コード例 #1
0
        /// <summary>
        /// Creates a virtual environment. If virtualenv or pip are not
        /// installed then they are downloaded and installed automatically.
        /// </summary>
        public static async Task CreateAndInstallDependencies(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string path,
            Redirector output = null
            )
        {
            factory.ThrowIfNotRunnable("factory");

            var modules = await factory.FindModulesAsync("pip", "virtualenv", "venv");

            bool hasPip        = modules.Contains("pip");
            bool hasVirtualEnv = modules.Contains("virtualenv") || modules.Contains("venv");

            if (!hasVirtualEnv)
            {
                if (!hasPip)
                {
                    bool elevate = provider.GetPythonToolsService().GeneralOptions.ElevatePip;
                    await Pip.InstallPip(provider, factory, elevate, output);
                }
                if (!await Install(provider, factory, output))
                {
                    throw new InvalidOperationException(Strings.VirtualEnvCreationFailed.FormatUI(path));
                }
            }

            await ContinueCreate(provider, factory, path, false, output);
        }
コード例 #2
0
ファイル: Pip.cs プロジェクト: zuokaihuang/PTVS
        public static async Task <bool> QueryInstall(
            IPythonInterpreterFactory factory,
            string package,
            IServiceProvider site,
            string message,
            bool elevate,
            Redirector output = null
            )
        {
            factory.ThrowIfNotRunnable("factory");

            if (Microsoft.VisualStudio.Shell.VsShellUtilities.ShowMessageBox(
                    site,
                    message,
                    null,
                    OLEMSGICON.OLEMSGICON_QUERY,
                    OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST
                    ) == 2)
            {
                throw new OperationCanceledException();
            }

            return(await Install(site, factory, package, elevate, output));
        }
コード例 #3
0
ファイル: Pip.cs プロジェクト: omnimark/PTVS
        private static ProcessOutput Run(
            IPythonInterpreterFactory factory,
            Redirector output,
            bool elevate,
            params string[] cmd
        ) {
            factory.ThrowIfNotRunnable("factory");

            IEnumerable<string> args;
            if (factory.Configuration.Version >= SupportsDashMPip) {
                args = new[] { "-m", "pip" }.Concat(cmd);
            } else {
                // Manually quote the code, since we are passing false to
                // quoteArgs below.
                args = new[] { "-c", "\"import pip; pip.main()\"" }.Concat(cmd);
            }

            return ProcessOutput.Run(
                factory.Configuration.InterpreterPath,
                args,
                factory.Configuration.PrefixPath,
                UnbufferedEnv,
                false,
                output,
                quoteArgs: false,
                elevate: elevate
            );
        }
コード例 #4
0
ファイル: Pip.cs プロジェクト: zuokaihuang/PTVS
        private static ProcessOutput Run(
            IPythonInterpreterFactory factory,
            Redirector output,
            bool elevate,
            params string[] cmd
            )
        {
            factory.ThrowIfNotRunnable("factory");

            IEnumerable <string> args;

            if (factory.Configuration.Version >= SupportsDashMPip)
            {
                args = new[] { "-m", "pip" }.Concat(cmd);
            }
            else
            {
                // Manually quote the code, since we are passing false to
                // quoteArgs below.
                args = new[] { "-c", "\"import pip; pip.main()\"" }.Concat(cmd);
            }

            return(ProcessOutput.Run(
                       factory.Configuration.InterpreterPath,
                       args,
                       factory.Configuration.PrefixPath,
                       UnbufferedEnv,
                       false,
                       output,
                       quoteArgs: false,
                       elevate: elevate
                       ));
        }
コード例 #5
0
ファイル: VirtualEnv.cs プロジェクト: petrutlucian94/PTVS
        /// <summary>
        /// Creates a virtual environment using virtualenv. If virtualenv or pip
        /// are not installed then they are downloaded and installed automatically.
        /// </summary>
        public static async Task CreateWithVirtualEnv(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string path
            )
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            factory.ThrowIfNotRunnable(nameof(factory));

            var cancel          = CancellationToken.None;
            var ui              = new VsPackageManagerUI(provider);
            var interpreterOpts = provider.GetComponentModel().GetService <IInterpreterOptionsService>();
            var pm              = interpreterOpts?.GetPackageManagers(factory).FirstOrDefault(p => p.UniqueKey == "pip");

            if (pm == null)
            {
                throw new InvalidOperationException(Strings.PackageManagementNotSupported);
            }
            if (!pm.IsReady)
            {
                await pm.PrepareAsync(ui, cancel);

                if (!pm.IsReady)
                {
                    throw new InvalidOperationException(Strings.VirtualEnvCreationFailed.FormatUI(path));
                }
            }

            bool hasVirtualEnv = (await factory.HasModuleAsync("venv", interpreterOpts)) ||
                                 (await factory.HasModuleAsync("virtualenv", interpreterOpts));

            if (!hasVirtualEnv)
            {
                if (!await Install(provider, factory))
                {
                    throw new InvalidOperationException(Strings.VirtualEnvCreationFailed.FormatUI(path));
                }
            }

            await ContinueCreate(provider, factory, path, false, PackageManagerUIRedirector.Get(pm, ui));
        }
コード例 #6
0
ファイル: EasyInstall.cs プロジェクト: zuokaihuang/PTVS
        public static async Task <bool> Install(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string package,
            IServiceProvider site,
            bool elevate,
            Redirector output = null
            )
        {
            factory.ThrowIfNotRunnable("factory");

            bool isScript;

            if (site != null && GetEasyInstallPath(factory, out isScript) == null)
            {
                await Pip.QueryInstallPip(factory, site, Strings.InstallEasyInstall, elevate, output);
            }

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

            var exitCode = await ContinueRun(factory, output, elevate, package);

            if (output != null)
            {
                if (exitCode == 0)
                {
                    output.WriteLine(Strings.PackageInstallSucceeded.FormatUI(package));
                }
                else
                {
                    output.WriteLine(Strings.PackageInstallFailedExitCode.FormatUI(package, exitCode));
                }
                if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation)
                {
                    output.ShowAndActivate();
                }
                else
                {
                    output.Show();
                }
            }
            return(exitCode == 0);
        }
コード例 #7
0
ファイル: EasyInstall.cs プロジェクト: zuokaihuang/PTVS
        public static async Task Install(
            IPythonInterpreterFactory factory,
            string package,
            bool elevate,
            Redirector output = null
            )
        {
            factory.ThrowIfNotRunnable("factory");

            await ContinueRun(factory, output, elevate, package);
        }
コード例 #8
0
ファイル: EasyInstall.cs プロジェクト: smallwave/PTVS
        private static string GetEasyInstallPath(IPythonInterpreterFactory factory, out bool isScript) {
            factory.ThrowIfNotRunnable("factory");

            foreach (var path in EasyInstallLocations) {
                string easyInstallPath = Path.Combine(factory.Configuration.PrefixPath, path.Key);
                isScript = path.Value;
                if (File.Exists(easyInstallPath)) {
                    return easyInstallPath;
                }
            }
            isScript = false;
            return null;
        }
コード例 #9
0
ファイル: Pip.cs プロジェクト: zuokaihuang/PTVS
        public static async Task InstallPip(IServiceProvider provider, IPythonInterpreterFactory factory, bool elevate, Redirector output = null)
        {
            factory.ThrowIfNotRunnable("factory");

            var pipDownloaderPath = PythonToolsInstallPath.GetFile("pip_downloader.py");

            if (output != null)
            {
                output.WriteLine(Strings.PipInstalling);
                if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation)
                {
                    output.ShowAndActivate();
                }
                else
                {
                    output.Show();
                }
            }
            using (var proc = ProcessOutput.Run(
                       factory.Configuration.InterpreterPath,
                       new[] { pipDownloaderPath },
                       factory.Configuration.PrefixPath,
                       null,
                       false,
                       output,
                       elevate: elevate
                       )) {
                var exitCode = await proc;
                if (output != null)
                {
                    if (exitCode == 0)
                    {
                        output.WriteLine(Strings.PipInstallSucceeded);
                    }
                    else
                    {
                        output.WriteLine(Strings.PipInstallFailedExitCode.FormatUI(exitCode));
                    }
                    if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation)
                    {
                        output.ShowAndActivate();
                    }
                    else
                    {
                        output.Show();
                    }
                }
            }
        }
コード例 #10
0
ファイル: Pip.cs プロジェクト: zuokaihuang/PTVS
        public static async Task <bool> Uninstall(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string package,
            bool elevate,
            Redirector output = null
            )
        {
            factory.ThrowIfNotRunnable("factory");

            if (output != null)
            {
                output.WriteLine(Strings.PackageUninstalling.FormatUI(package));
                if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation)
                {
                    output.ShowAndActivate();
                }
                else
                {
                    output.Show();
                }
            }

            using (var proc = Run(factory, output, elevate, "uninstall", "-y", package)) {
                var exitCode = await proc;

                if (output != null)
                {
                    if (exitCode == 0)
                    {
                        output.WriteLine(Strings.PackageUninstallSucceeded.FormatUI(package));
                    }
                    else
                    {
                        output.WriteLine(Strings.PackageUninstallFailedExitCode.FormatUI(package, exitCode));
                    }
                    if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation)
                    {
                        output.ShowAndActivate();
                    }
                    else
                    {
                        output.Show();
                    }
                }
                return(exitCode == 0);
            }
        }
コード例 #11
0
ファイル: EasyInstall.cs プロジェクト: zuokaihuang/PTVS
        private static string GetEasyInstallPath(IPythonInterpreterFactory factory, out bool isScript)
        {
            factory.ThrowIfNotRunnable("factory");

            foreach (var path in EasyInstallLocations)
            {
                string easyInstallPath = Path.Combine(factory.Configuration.PrefixPath, path.Key);
                isScript = path.Value;
                if (File.Exists(easyInstallPath))
                {
                    return(easyInstallPath);
                }
            }
            isScript = false;
            return(null);
        }
コード例 #12
0
ファイル: Pip.cs プロジェクト: zuokaihuang/PTVS
        public static async Task <bool> Install(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string package,
            bool elevate,
            Redirector output = null
            )
        {
            factory.ThrowIfNotRunnable("factory");

            if (!(await factory.FindModulesAsync("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);
            }
        }
コード例 #13
0
ファイル: VirtualEnv.cs プロジェクト: petrutlucian94/PTVS
        /// <summary>
        /// Creates a virtual environment. If virtualenv is not installed, the
        /// task will succeed but error text will be passed to the redirector.
        /// </summary>
        public static Task Create(IServiceProvider provider, IPythonInterpreterFactory factory, string path, Redirector output = null)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            factory.ThrowIfNotRunnable(nameof(factory));
            return(ContinueCreate(provider, factory, path, false, output));
        }
コード例 #14
0
        /// <summary>
        /// Creates a virtual environment. If virtualenv or pip are not
        /// installed then they are downloaded and installed automatically.
        /// </summary>
        public static async Task CreateAndInstallDependencies(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string path
            )
        {
            factory.ThrowIfNotRunnable("factory");

            var cancel = CancellationToken.None;
            var ui     = new VsPackageManagerUI(provider);
            var pm     = factory.PackageManager;

            if (pm == null)
            {
                throw new InvalidOperationException(Strings.PackageManagementNotSupported);
            }
            if (!pm.IsReady)
            {
                await pm.PrepareAsync(ui, cancel);

                if (!pm.IsReady)
                {
                    throw new InvalidOperationException(Strings.VirtualEnvCreationFailed.FormatUI(path));
                }
            }

            var modules = await factory.FindModulesAsync("virtualenv", "venv");

            bool hasVirtualEnv = modules.Contains("virtualenv") || modules.Contains("venv");

            if (!hasVirtualEnv)
            {
                if (!await Install(provider, factory))
                {
                    throw new InvalidOperationException(Strings.VirtualEnvCreationFailed.FormatUI(path));
                }
            }

            await ContinueCreate(provider, factory, path, false, PackageManagerUIRedirector.Get(pm, ui));
        }
コード例 #15
0
ファイル: VirtualEnv.cs プロジェクト: petrutlucian94/PTVS
        /// <summary>
        /// Creates a virtual environment using venv. If venv is not available,
        /// the task will succeed but error text will be passed to the
        /// redirector.
        /// </summary>
        public static Task CreateWithVEnv(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string path
            )
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            factory.ThrowIfNotRunnable();
            return(ContinueCreate(provider, factory, path, true, OutputWindowRedirector.GetGeneral(provider)));
        }
コード例 #16
0
ファイル: EasyInstall.cs プロジェクト: smallwave/PTVS
        public static async Task<bool> Install(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string package,
            IServiceProvider site,
            bool elevate,
            Redirector output = null
        ) {
            factory.ThrowIfNotRunnable("factory");

            bool isScript;
            if (site != null && GetEasyInstallPath(factory, out isScript) == null) {
                await Pip.QueryInstallPip(factory, site, Strings.InstallEasyInstall, elevate, output);
            }

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

            var exitCode = await ContinueRun(factory, output, elevate, package);

            if (output != null) {
                if (exitCode == 0) {
                    output.WriteLine(Strings.PackageInstallSucceeded.FormatUI(package));
                } else {
                    output.WriteLine(Strings.PackageInstallFailedExitCode.FormatUI(package, exitCode));
                }
                if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation) {
                    output.ShowAndActivate();
                } else {
                    output.Show();
                }
            }
            return exitCode == 0;
        }
コード例 #17
0
ファイル: VirtualEnv.cs プロジェクト: zyxws012/PTVS
 /// <summary>
 /// Creates a virtual environment using venv. If venv is not available,
 /// the task will succeed but error text will be passed to the
 /// redirector.
 /// </summary>
 public static Task CreateWithVEnv(IServiceProvider provider, IPythonInterpreterFactory factory, string path)
 {
     factory.ThrowIfNotRunnable();
     return(ContinueCreate(provider, factory, path, true, OutputWindowRedirector.GetGeneral(provider)));
 }
コード例 #18
0
ファイル: Pip.cs プロジェクト: omnimark/PTVS
        public static async Task QueryInstallPip(
            IPythonInterpreterFactory factory,
            IServiceProvider site,
            string message,
            bool elevate,
            Redirector output = null
        ) {
            factory.ThrowIfNotRunnable("factory");

            if (Microsoft.VisualStudio.Shell.VsShellUtilities.ShowMessageBox(
                site,
                message,
                null,
                OLEMSGICON.OLEMSGICON_QUERY,
                OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST
            ) == 2) {
                throw new OperationCanceledException();
            }

            await InstallPip(site, factory, elevate, output);
        }
コード例 #19
0
ファイル: Pip.cs プロジェクト: omnimark/PTVS
        public static async Task<bool> Install(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string package,
            bool elevate,
            Redirector output = null
        ) {
            factory.ThrowIfNotRunnable("factory");

            if (!(await factory.FindModulesAsync("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;
            }
        }
コード例 #20
0
ファイル: VirtualEnv.cs プロジェクト: zyxws012/PTVS
 /// <summary>
 /// Creates a virtual environment. If virtualenv is not installed, the
 /// task will succeed but error text will be passed to the redirector.
 /// </summary>
 public static Task Create(IServiceProvider provider, IPythonInterpreterFactory factory, string path, Redirector output = null)
 {
     factory.ThrowIfNotRunnable();
     return(ContinueCreate(provider, factory, path, false, output));
 }
コード例 #21
0
ファイル: Pip.cs プロジェクト: omnimark/PTVS
        public static async Task<bool> Install(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string package,
            IServiceProvider site,
            bool elevate,
            Redirector output = null
        ) {
            factory.ThrowIfNotRunnable("factory");

            if (!(await factory.FindModulesAsync("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;
            }
        }
コード例 #22
0
ファイル: Pip.cs プロジェクト: omnimark/PTVS
        public static async Task InstallPip(IServiceProvider provider, IPythonInterpreterFactory factory, bool elevate, Redirector output = null) {
            factory.ThrowIfNotRunnable("factory");

            var pipDownloaderPath = PythonToolsInstallPath.GetFile("pip_downloader.py");

            if (output != null) {
                output.WriteLine(SR.GetString(SR.PipInstalling));
                if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation) {
                    output.ShowAndActivate();
                } else {
                    output.Show();
                }
            }
            using (var proc = ProcessOutput.Run(
                factory.Configuration.InterpreterPath,
                new[] { pipDownloaderPath },
                factory.Configuration.PrefixPath,
                null,
                false,
                output,
                elevate: elevate
            )) {
                var exitCode = await proc;
                if (output != null) {
                    if (exitCode == 0) {
                        output.WriteLine(SR.GetString(SR.PipInstallSucceeded));
                    } else {
                        output.WriteLine(SR.GetString(SR.PipInstallFailedExitCode, exitCode));
                    }
                    if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation) {
                        output.ShowAndActivate();
                    } else {
                        output.Show();
                    }
                }
            }
        }
コード例 #23
0
ファイル: Pip.cs プロジェクト: omnimark/PTVS
        public static async Task<bool> Uninstall(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string package,
            bool elevate,
            Redirector output = null
        ) {
            factory.ThrowIfNotRunnable("factory");

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

            using (var proc = Run(factory, output, elevate, "uninstall", "-y", package)) {
                var exitCode = await proc;

                if (output != null) {
                    if (exitCode == 0) {
                        output.WriteLine(SR.GetString(SR.PackageUninstallSucceeded, package));
                    } else {
                        output.WriteLine(SR.GetString(SR.PackageUninstallFailedExitCode, package, exitCode));
                    }
                    if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation) {
                        output.ShowAndActivate();
                    } else {
                        output.Show();
                    }
                }
                return exitCode == 0;
            }
        }
コード例 #24
0
ファイル: VirtualEnv.cs プロジェクト: wenh123/PTVS
 /// <summary>
 /// Creates a virtual environment. If virtualenv is not installed, the
 /// task will succeed but error text will be passed to the redirector.
 /// </summary>
 public static Task Create(IServiceProvider provider, IPythonInterpreterFactory factory, string path, Redirector output = null) {
     factory.ThrowIfNotRunnable();
     return ContinueCreate(provider, factory, path, false, output);
 }
コード例 #25
0
ファイル: Pip.cs プロジェクト: zuokaihuang/PTVS
        public static async Task <bool> Install(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string package,
            IServiceProvider site,
            bool elevate,
            Redirector output = null
            )
        {
            factory.ThrowIfNotRunnable("factory");

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

            if (output != null)
            {
                output.WriteLine(Strings.PackageInstalling.FormatUI(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(Strings.PackageInstallSucceeded.FormatUI(package));
                    }
                    else
                    {
                        output.WriteLine(Strings.PackageInstallFailedExitCode.FormatUI(package, exitCode));
                    }
                    if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForPackageInstallation)
                    {
                        output.ShowAndActivate();
                    }
                    else
                    {
                        output.Show();
                    }
                }
                return(exitCode == 0);
            }
        }
コード例 #26
0
ファイル: EasyInstall.cs プロジェクト: smallwave/PTVS
        public static async Task Install(
            IPythonInterpreterFactory factory,
            string package,
            bool elevate,
            Redirector output = null
        ) {
            factory.ThrowIfNotRunnable("factory");

            await ContinueRun(factory, output, elevate, package);
        }
コード例 #27
0
ファイル: VirtualEnv.cs プロジェクト: jsschultz/PTVS
        /// <summary>
        /// Creates a virtual environment. If virtualenv or pip are not
        /// installed then they are downloaded and installed automatically.
        /// </summary>
        public static async Task CreateAndInstallDependencies(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string path
        ) {
            factory.ThrowIfNotRunnable("factory");

            var cancel = CancellationToken.None;
            var ui = new VsPackageManagerUI(provider);
            var pm = factory.PackageManager;
            if (pm == null) {
                throw new InvalidOperationException(Strings.PackageManagementNotSupported);
            }
            if (!pm.IsReady) {
                await pm.PrepareAsync(ui, cancel);
                if (!pm.IsReady) {
                    throw new InvalidOperationException(Strings.VirtualEnvCreationFailed.FormatUI(path));
                }
            }

            var modules = await factory.FindModulesAsync("virtualenv", "venv");
            bool hasVirtualEnv = modules.Contains("virtualenv") || modules.Contains("venv");

            if (!hasVirtualEnv) {
                if (!await Install(provider, factory)) {
                    throw new InvalidOperationException(Strings.VirtualEnvCreationFailed.FormatUI(path));
                }
            }

            await ContinueCreate(provider, factory, path, false, PackageManagerUIRedirector.Get(pm, ui));
        }
コード例 #28
0
ファイル: VirtualEnv.cs プロジェクト: wenh123/PTVS
        /// <summary>
        /// Creates a virtual environment. If virtualenv or pip are not
        /// installed then they are downloaded and installed automatically.
        /// </summary>
        public static async Task CreateAndInstallDependencies(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            string path,
            Redirector output = null
        ) {
            factory.ThrowIfNotRunnable("factory");

            var modules = await factory.FindModulesAsync("pip", "virtualenv", "venv");
            bool hasPip = modules.Contains("pip");
            bool hasVirtualEnv = modules.Contains("virtualenv") || modules.Contains("venv");

            if (!hasVirtualEnv) {
                if (!hasPip) {
                    bool elevate = provider.GetPythonToolsService().GeneralOptions.ElevatePip;
                    await Pip.InstallPip(provider, factory, elevate, output);
                }
                if (!await Install(provider, factory, output)) {
                    throw new InvalidOperationException(SR.GetString(SR.VirtualEnvCreationFailed, path));
                }
            }

            await ContinueCreate(provider, factory, path, false, output);
        }
コード例 #29
0
        public static async Task <bool> Install(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            IInterpreterOptionsService service,
            string package,
            Redirector output = null
            )
        {
            factory.ThrowIfNotRunnable("factory");

            var condaFactory = await TryGetCondaFactoryAsync(factory, service);;

            if (condaFactory == null)
            {
                throw new InvalidOperationException("Cannot find conda");
            }
            condaFactory.ThrowIfNotRunnable();

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

            using (var proc = ProcessOutput.Run(
                       condaFactory.Configuration.InterpreterPath,
                       new[] { "-m", "conda", "install", "--yes", "-n", factory.Configuration.PrefixPath, package },
                       factory.Configuration.PrefixPath,
                       UnbufferedEnv,
                       false,
                       output
                       )) {
                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);
            }
        }
コード例 #30
0
ファイル: Conda.cs プロジェクト: wenh123/PTVS
        public static async Task<bool> Install(
            IServiceProvider provider,
            IPythonInterpreterFactory factory,
            IInterpreterOptionsService service,
            string package,
            Redirector output = null
        ) {
            factory.ThrowIfNotRunnable("factory");

            var condaFactory = await TryGetCondaFactoryAsync(factory, service); ;
            if (condaFactory == null) {
                throw new InvalidOperationException("Cannot find conda");
            }
            condaFactory.ThrowIfNotRunnable();

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

            using (var proc = ProcessOutput.Run(
                condaFactory.Configuration.InterpreterPath,
                new[] { "-m", "conda", "install", "--yes", "-n", factory.Configuration.PrefixPath, package },
                factory.Configuration.PrefixPath,
                UnbufferedEnv,
                false,
                output
            )) {
                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;
            }
        }
コード例 #31
0
ファイル: VirtualEnv.cs プロジェクト: jsschultz/PTVS
 /// <summary>
 /// Creates a virtual environment using venv. If venv is not available,
 /// the task will succeed but error text will be passed to the
 /// redirector.
 /// </summary>
 public static Task CreateWithVEnv(IServiceProvider provider, IPythonInterpreterFactory factory, string path) {
     factory.ThrowIfNotRunnable();
     return ContinueCreate(provider, factory, path, true, OutputWindowRedirector.GetGeneral(provider));
 }