Exemplo n.º 1
0
        internal static void InstallWebFramework(VisualStudioApp app, string moduleName, string packageName, IPythonInterpreterFactory factory)
        {
            var task = app.ServiceProvider.GetUIThread().InvokeTask(() => factory.PipInstallAsync(packageName));

            try {
                Assert.IsTrue(task.Wait(TimeSpan.FromMinutes(3.0)), "Timed out waiting for install " + packageName);
            } catch (AggregateException ex) {
                ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
            }
            Assert.AreEqual(1, factory.FindModules(moduleName).Count);
        }
Exemplo n.º 2
0
        internal static void InstallWebFramework(VisualStudioApp app, string moduleName, string packageName, IPythonInterpreterFactory factory)
        {
            var redirector = new TraceRedirector("pip install " + packageName);
            var task       = app.ServiceProvider.GetUIThread().InvokeTask(() =>
                                                                          Pip.Install(app.ServiceProvider, factory, packageName, false, redirector)
                                                                          );

            try {
                Assert.IsTrue(task.Wait(TimeSpan.FromMinutes(3.0)), "Timed out waiting for install " + packageName);
            } catch (AggregateException ex) {
                throw ex.InnerException;
            }
            Assert.AreEqual(1, factory.FindModules(moduleName).Count);
        }
Exemplo n.º 3
0
        public static async Task <bool> Install(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string package,
            bool elevate,
            Redirector output = null
            )
        {
            factory.ThrowIfNotRunnable("factory");

            if (!factory.FindModules("pip").Any())
            {
                await InstallPip(provider, factory, elevate, output);
            }
            using (var proc = Run(factory, output, elevate, "install", GetInsecureArg(factory, output), package)) {
                await proc;
                return(proc.ExitCode == 0);
            }
        }
Exemplo n.º 4
0
 internal static void InstallWebFramework(VisualStudioApp app, string moduleName, string packageName, IPythonInterpreterFactory factory) {
     var task = app.ServiceProvider.GetUIThread().InvokeTask(() => factory.PipInstallAsync(packageName));
     try {
         Assert.IsTrue(task.Wait(TimeSpan.FromMinutes(3.0)), "Timed out waiting for install " + packageName);
     } catch (AggregateException ex) {
         throw ex.InnerException;
     }
     Assert.AreEqual(1, factory.FindModules(moduleName).Count);
 }
Exemplo n.º 5
0
 internal static Task <HashSet <string> > FindPipAndVirtualEnv(IPythonInterpreterFactory factory)
 {
     return(Task.Run(() => factory.FindModules("pip", "virtualenv", "venv")));
 }
Exemplo n.º 6
0
        public static async Task <bool> Install(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string package,
            IServiceProvider site,
            bool elevate,
            Redirector output = null
            )
        {
            factory.ThrowIfNotRunnable("factory");

            if (!factory.FindModules("pip").Any())
            {
                if (site != null)
                {
                    try {
                        await QueryInstallPip(factory, site, SR.GetString(SR.InstallPip), elevate, output);
                    } catch (OperationCanceledException) {
                        return(false);
                    }
                }
                else
                {
                    await InstallPip(provider, factory, elevate, output);
                }
            }

            if (output != null)
            {
                output.WriteLine(SR.GetString(SR.PackageInstalling, package));
                if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation)
                {
                    output.ShowAndActivate();
                }
                else
                {
                    output.Show();
                }
            }

            using (var proc = Run(factory, output, elevate, "install", GetInsecureArg(factory, output), package)) {
                var exitCode = await proc;

                if (output != null)
                {
                    if (exitCode == 0)
                    {
                        output.WriteLine(SR.GetString(SR.PackageInstallSucceeded, package));
                    }
                    else
                    {
                        output.WriteLine(SR.GetString(SR.PackageInstallFailedExitCode, package, exitCode));
                    }
                    if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation)
                    {
                        output.ShowAndActivate();
                    }
                    else
                    {
                        output.Show();
                    }
                }
                return(exitCode == 0);
            }
        }
Exemplo n.º 7
0
        private static bool TryGetCondaFactory(
            IPythonInterpreterFactory target,
            IInterpreterOptionsService service,
            out IPythonInterpreterFactory factory
            )
        {
            factory = null;

            var condaMetaPath = CommonUtils.GetAbsoluteDirectoryPath(
                target.Configuration.PrefixPath,
                "conda-meta"
                );

            if (!Directory.Exists(condaMetaPath))
            {
                return(false);
            }

            string metaFile;

            try {
                metaFile = Directory.EnumerateFiles(condaMetaPath, "*.json").FirstOrDefault();
            } catch (Exception ex) {
                if (ex.IsCriticalException())
                {
                    throw;
                }
                return(false);
            }

            if (!string.IsNullOrEmpty(metaFile))
            {
                string text = string.Empty;
                try {
                    text = File.ReadAllText(metaFile);
                } catch (Exception ex) {
                    if (ex.IsCriticalException())
                    {
                        throw;
                    }
                }

                var m = Regex.Match(text, @"\{[^{]+link.+?\{.+?""source""\s*:\s*""(.+?)""", RegexOptions.Singleline);
                if (m.Success)
                {
                    var pkg = m.Groups[1].Value;
                    if (!Directory.Exists(pkg))
                    {
                        return(false);
                    }

                    var prefix = Path.GetDirectoryName(Path.GetDirectoryName(pkg));
                    factory = service.Interpreters.FirstOrDefault(
                        f => CommonUtils.IsSameDirectory(f.Configuration.PrefixPath, prefix)
                        );

                    if (factory != null && !factory.FindModules("conda").Any())
                    {
                        factory = null;
                    }

                    return(factory != null);
                }
            }

            if (target.FindModules("conda").Any())
            {
                factory = target;
            }
            return(factory != null);
        }