Exemplo n.º 1
0
 private InterpretersNode(PythonProjectNode project, string id) : base(project, MakeElement(project))
 {
     _absentId      = id;
     _canRemove     = true;
     _captionSuffix = Strings.MissingSuffix;
 }
Exemplo n.º 2
0
 public static InterpretersNode CreateAbsentInterpreterNode(PythonProjectNode project, string id)
 {
     return(new InterpretersNode(project, id));
 }
Exemplo n.º 3
0
        private async Task ExecuteWorker(PythonProjectNode project)
        {
            _errorListProvider.Tasks.Clear();

            var interpFactory = project.GetInterpreterFactoryOrThrow();
            var startInfo     = GetStartInfo(project);

            var packagesToInstall = new List <string>();

            foreach (var pkg in startInfo.RequiredPackages)
            {
                if (!await Pip.IsInstalled(interpFactory, pkg))
                {
                    packagesToInstall.Add(pkg);
                }
            }

            if (packagesToInstall.Any())
            {
                var installMissingButton = new TaskDialogButton(
                    SR.GetString(SR.CustomCommandPrerequisitesInstallMissing),
                    SR.GetString(SR.CustomCommandPrerequisitesInstallMissingSubtext) + "\r\n\r\n" + string.Join("\r\n", packagesToInstall));
                var runAnywayButton = new TaskDialogButton(SR.GetString(SR.CustomCommandPrerequisitesRunAnyway));
                var doNotRunButton  = new TaskDialogButton(SR.GetString(SR.CustomCommandPrerequisitesDoNotRun));

                var taskDialog = new TaskDialog(project.Site)
                {
                    Title             = SR.ProductName,
                    MainInstruction   = SR.GetString(SR.CustomCommandPrerequisitesInstruction),
                    Content           = SR.GetString(SR.CustomCommandPrerequisitesContent, DisplayLabelWithoutAccessKeys),
                    AllowCancellation = true,
                    Buttons           = { installMissingButton, runAnywayButton, doNotRunButton, TaskDialogButton.Cancel }
                };

                var selectedButton = taskDialog.ShowModal();
                if (selectedButton == installMissingButton)
                {
                    await Pip.Install(
                        project.Site,
                        interpFactory,
                        string.Join(" ", packagesToInstall),
                        false,
                        OutputWindowRedirector.GetGeneral(project.Site));
                }
                else if (selectedButton == runAnywayButton)
                {
                }
                else
                {
                    throw new TaskCanceledException();
                }
            }

            if (startInfo.TargetType == CreatePythonCommandItem.TargetTypePip)
            {
                if (startInfo.ExecuteInOutput)
                {
                    await Pip.Install(
                        _project.Site,
                        interpFactory,
                        string.IsNullOrEmpty(startInfo.Arguments)?
                        startInfo.Filename :
                        string.Format("{0} {1}", startInfo.Filename, startInfo.Arguments),
                        project.Site,
                        false,
                        OutputWindowRedirector.GetGeneral(project.Site)
                        );

                    return;
                }

                // Rewrite start info to execute
                startInfo.TargetType = CreatePythonCommandItem.TargetTypeModule;
                startInfo.AddArgumentAtStart(startInfo.Filename);
                startInfo.Filename = "pip";
            }

            if (startInfo.ExecuteInRepl)
            {
                if (await RunInRepl(project, startInfo))
                {
                    return;
                }
            }

            startInfo.AdjustArgumentsForProcessStartInfo(GetInterpreterPath(project, false));

            if (startInfo.ExecuteInOutput)
            {
                RunInOutput(project, startInfo);
            }
            else
            {
                RunInConsole(project, startInfo);
            }
        }
Exemplo n.º 4
0
 private static ProjectElement MakeElement(PythonProjectNode project)
 {
     return(new VirtualProjectElement(project));
 }
Exemplo n.º 5
0
 public PythonAssemblyReferenceNode(PythonProjectNode root, ProjectElement element)
     : base(root, element)
 {
 }
Exemplo n.º 6
0
 public PythonAssemblyReferenceNode(PythonProjectNode root, string assemblyPath)
     : base(root, assemblyPath)
 {
 }
Exemplo n.º 7
0
 public TestFrameworkProjectInfoBar(IServiceProvider site, PythonProjectNode projectNode) : base(site)
 {
     Project = projectNode ?? throw new ArgumentNullException(nameof(projectNode));
 }
Exemplo n.º 8
0
 public InterpretersContainerNode(PythonProjectNode project)
     : base(project.ProjectMgr)
 {
     _projectNode       = project;
     ExcludeNodeFromScc = true;
 }
Exemplo n.º 9
0
        public override async Task CheckAsync()
        {
            if (IsCreated)
            {
                return;
            }

            if (!Project.Site.GetPythonToolsService().GeneralOptions.PromptForPackageInstallation)
            {
                return;
            }

            var suppressProp = Project.GetProjectProperty(PythonConstants.SuppressPackageInstallationPrompt);

            if (suppressProp.IsTrue())
            {
                return;
            }

            if (Project.IsActiveInterpreterGlobalDefault)
            {
                return;
            }

            var txtPath = Project.GetRequirementsTxtPath();

            if (!File.Exists(txtPath))
            {
                return;
            }

            var active = Project.ActiveInterpreter;

            if (!active.IsRunnable())
            {
                return;
            }

            var pm = Project.InterpreterOptions.GetPackageManagers(active).FirstOrDefault(p => p.UniqueKey == "pip");

            if (pm == null)
            {
                return;
            }

            var missing = await PackagesMissingAsync(pm, txtPath);

            if (!missing)
            {
                return;
            }

            Action installPackages = () => {
                Logger?.LogEvent(
                    PythonLogEvent.PackageInstallInfoBar,
                    new PackageInstallInfoBarInfo()
                {
                    Action = PackageInstallInfoBarActions.Install,
                }
                    );
                PythonProjectNode.InstallRequirementsAsync(Project.Site, pm, txtPath)
                .HandleAllExceptions(Project.Site, typeof(PackageInstallInfoBar))
                .DoNotWait();
                Close();
            };

            Action projectIgnore = () => {
                Logger?.LogEvent(
                    PythonLogEvent.PackageInstallInfoBar,
                    new PackageInstallInfoBarInfo()
                {
                    Action = PackageInstallInfoBarActions.Ignore,
                }
                    );
                Project.SetProjectProperty(PythonConstants.SuppressEnvironmentCreationPrompt, true.ToString());
                Close();
            };

            var messages = new List <IVsInfoBarTextSpan>();
            var actions  = new List <InfoBarActionItem>();

            messages.Add(new InfoBarTextSpan(
                             Strings.RequirementsTxtInstallPackagesInfoBarMessage.FormatUI(
                                 PathUtils.GetFileOrDirectoryName(txtPath),
                                 Project.Caption,
                                 pm.Factory.Configuration.Description
                                 )));
            actions.Add(new InfoBarButton(Strings.RequirementsTxtInfoBarInstallPackagesAction, installPackages));
            actions.Add(new InfoBarButton(Strings.RequirementsTxtInfoBarProjectIgnoreAction, projectIgnore));

            Logger?.LogEvent(
                PythonLogEvent.PackageInstallInfoBar,
                new PackageInstallInfoBarInfo()
            {
                Action = PackageInstallInfoBarActions.Prompt,
            }
                );

            Create(new InfoBarModel(messages, actions, KnownMonikers.StatusInformation, isCloseButtonVisible: true));
        }
Exemplo n.º 10
0
 public PythonReferenceContainerNode(PythonProjectNode root)
     : base(root)
 {
 }
Exemplo n.º 11
0
 public PackageInstallInfoBar(PythonProjectNode projectNode)
     : base(projectNode)
 {
 }
Exemplo n.º 12
0
 internal PythonProjectNodeProperties(PythonProjectNode node)
     : base(node)
 {
 }
Exemplo n.º 13
0
 public CommonSearchPathContainerNode(PythonProjectNode project)
     : base(project.ProjectMgr)
 {
     _projectNode            = project;
     this.ExcludeNodeFromScc = true;
 }
 public CommonSearchPathNode(PythonProjectNode project, string path, int index)
     : base(project, path, new VirtualProjectElement(project))
 {
     _index = index;
 }
Exemplo n.º 15
0
 public CurrentWorkingDirectoryNode(PythonProjectNode project, string path)
     : base(project, path, new VirtualProjectElement(project))
 {
 }
Exemplo n.º 16
0
 public PythonProjectConfig(PythonProjectNode project, string configuration)
     : base(project, configuration)
 {
     _project = project;
 }
Exemplo n.º 17
0
 public PackageInstallProjectInfoBar(IServiceProvider site, PythonProjectNode projectNode)
     : base(site)
 {
     Project = projectNode ?? throw new ArgumentNullException(nameof(projectNode));
 }