Exemplo n.º 1
0
        public void MergeRequirementsMismatchedCase()
        {
            AssertUtil.AreEqual(
                PipRequirementsUtils.MergeRequirements(new[] {
                "aaaaaa==0.0",
                "BbBbBb==0.1",
                "CCCCCC==0.2"
            }, new[] {
                "aaaAAA==0.1",
                "bbbBBB==0.2",
                "cccCCC==0.3"
            }.Select(p => PackageSpec.FromRequirement(p)), false),
                "aaaAAA==0.1",
                "bbbBBB==0.2",
                "cccCCC==0.3"
                );

            // https://pytools.codeplex.com/workitem/2465
            AssertUtil.AreEqual(
                PipRequirementsUtils.MergeRequirements(new[] {
                "Flask==0.10.1",
                "itsdangerous==0.24",
                "Jinja2==2.7.3",
                "MarkupSafe==0.23",
                "Werkzeug==0.9.6"
            }, new[] {
                "flask==0.10.1",
                "itsdangerous==0.24",
                "jinja2==2.7.3",
                "markupsafe==0.23",
                "werkzeug==0.9.6"
            }.Select(p => PackageSpec.FromRequirement(p)), false),
                "flask==0.10.1",
                "itsdangerous==0.24",
                "jinja2==2.7.3",
                "markupsafe==0.23",
                "werkzeug==0.9.6"
                );
        }
Exemplo n.º 2
0
        public void MergeRequirements()
        {
            // Comments should be preserved, only package specs should change.
            AssertUtil.AreEqual(
                PipRequirementsUtils.MergeRequirements(new[] {
                "a # with a comment",
                "B==0.2",
                "# just a comment B==01234",
                "",
                "x < 1",
                "d==1.0",
                "e==2.0",
                "f==3.0",
                "-r user/requirements.txt",
                "git+https://myvcs.com/some_dependency",
            }, new[] {
                "b==0.1",
                "a==0.2",
                "c==0.3",
                "e==4.0",
                "x==0.8"
            }.Select(p => PackageSpec.FromRequirement(p)), false),
                "a==0.2 # with a comment",
                "b==0.1",
                "# just a comment B==01234",
                "",
                "x==0.8",
                "d==1.0",
                "e==4.0",
                "f==3.0",
                "-r user/requirements.txt",
                "git+https://myvcs.com/some_dependency"
                );

            // addNew is true, so the c==0.3 should be added.
            AssertUtil.AreEqual(
                PipRequirementsUtils.MergeRequirements(new[] {
                "a # with a comment",
                "b==0.2",
                "# just a comment B==01234"
            }, new[] {
                "B==0.1",       // case is updated
                "a==0.2",
                "c==0.3"
            }.Select(p => PackageSpec.FromRequirement(p)), true),
                "a==0.2 # with a comment",
                "B==0.1",
                "# just a comment B==01234",
                "c==0.3"
                );

            // No existing entries, so the new ones are sorted and returned.
            AssertUtil.AreEqual(
                PipRequirementsUtils.MergeRequirements(null, new[] {
                "b==0.2",
                "a==0.1",
                "c==0.3"
            }.Select(p => PackageSpec.FromRequirement(p)), false),
                "a==0.1",
                "b==0.2",
                "c==0.3"
                );

            // Check all the inequalities
            const string inequalities = "<=|>=|<|>|!=|==";

            AssertUtil.AreEqual(
                PipRequirementsUtils.MergeRequirements(
                    inequalities.Split('|').Select(s => "a " + s + " 1.2.3"),
                    new[] { "a==0" }.Select(p => PackageSpec.FromRequirement(p)),
                    false
                    ),
                inequalities.Split('|').Select(_ => "a==0").ToArray()
                );
        }
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>();
            var interpreterOpts   = _project.Site.GetComponentModel().GetService <IInterpreterOptionsService>();
            var pm = interpreterOpts?.GetPackageManagers(interpFactory).FirstOrDefault();

            if (pm != null)
            {
                foreach (var pkg in startInfo.RequiredPackages)
                {
                    if (!(await pm.GetInstalledPackageAsync(PackageSpec.FromRequirement(pkg), CancellationToken.None)).IsValid)
                    {
                        packagesToInstall.Add(pkg);
                    }
                }
            }

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

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

                var selectedButton = taskDialog.ShowModal();
                if (selectedButton == installMissingButton)
                {
                    var ui = new VsPackageManagerUI(project.Site);
                    if (!pm.IsReady)
                    {
                        await pm.PrepareAsync(ui, CancellationToken.None);
                    }
                    await pm.InstallAsync(PackageSpec.FromArguments(string.Join(" ", packagesToInstall)), ui, CancellationToken.None);
                }
                else if (selectedButton == runAnywayButton)
                {
                }
                else
                {
                    throw new TaskCanceledException();
                }
            }

            if (startInfo.TargetType == PythonCommandTask.TargetTypePip)
            {
                if (startInfo.ExecuteInOutput && pm != null)
                {
                    var ui = new VsPackageManagerUI(project.Site);
                    if (!pm.IsReady)
                    {
                        await pm.PrepareAsync(ui, CancellationToken.None);
                    }
                    await pm.InstallAsync(
                        PackageSpec.FromArguments(string.IsNullOrEmpty(startInfo.Arguments) ? startInfo.Filename : "{0} {1}".FormatUI(startInfo.Filename, startInfo.Arguments)),
                        ui,
                        CancellationToken.None
                        );

                    return;
                }

                // Rewrite start info to execute
                startInfo.TargetType = PythonCommandTask.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);
            }
        }