/// <summary> /// Installs virtualenv. If pip is not installed, the returned task will /// succeed but error text will be passed to the redirector. /// </summary> public static Task<bool> Install(IServiceProvider provider, IPythonInterpreterFactory factory) { var ui = new VsPackageManagerUI(provider); if (factory.Configuration.Version < new Version(2, 5)) { ui.OnErrorTextReceived(null, "Python versions earlier than 2.5 are not supported by PTVS.\n"); throw new OperationCanceledException(); } else if (factory.PackageManager == null) { ui.OnErrorTextReceived(null, Strings.PackageManagementNotSupported_Package.FormatUI("virtualenv")); throw new OperationCanceledException(); } else if (factory.Configuration.Version == new Version(2, 5)) { return factory.PackageManager.InstallAsync(PackageSpec.FromArguments("https://go.microsoft.com/fwlink/?LinkID=317970"), ui, CancellationToken.None); } else { return factory.PackageManager.InstallAsync(PackageSpec.FromArguments("https://go.microsoft.com/fwlink/?LinkID=317969"), ui, CancellationToken.None); } }
/// <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)); }