private static async Task ContinueCreate(IServiceProvider provider, IPythonInterpreterFactory factory, string path, bool useVEnv, Redirector output) { path = PathUtils.TrimEndSeparator(path); var name = Path.GetFileName(path); var dir = Path.GetDirectoryName(path); if (output != null) { output.WriteLine(Strings.VirtualEnvCreating.FormatUI(path)); if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForVirtualEnvCreate) { output.ShowAndActivate(); } else { output.Show(); } } // Ensure the target directory exists. Directory.CreateDirectory(dir); using (var proc = ProcessOutput.Run( factory.Configuration.InterpreterPath, new[] { "-m", useVEnv ? "venv" : "virtualenv", name }, dir, UnbufferedEnv, false, output )) { var exitCode = await proc; if (output != null) { if (exitCode == 0) { output.WriteLine(Strings.VirtualEnvCreationSucceeded.FormatUI(path)); } else { output.WriteLine(Strings.VirtualEnvCreationFailedExitCode.FormatUI(path, exitCode)); } if (provider.GetPythonToolsService().GeneralOptions.ShowOutputWindowForVirtualEnvCreate) { output.ShowAndActivate(); } else { output.Show(); } } if (exitCode != 0 || !Directory.Exists(path)) { throw new InvalidOperationException(Strings.VirtualEnvCreationFailed.FormatUI(path)); } } }
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); }
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(); } } } }
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); } }
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); } }
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); } }