public async Task Run() { var service = _project.Site.GetComponentModel().GetService <IInterpreterRegistryService>(); IPythonInterpreterFactory factory; try { factory = await _project.CreateOrAddVirtualEnvironment( service, _create, _virtualEnvPath, _baseInterpreter, _useVEnv ); } catch (Exception ex) when(!ex.IsCriticalException()) { WriteError(ex.Message); factory = null; } if (factory == null) { return; } var txt = PathUtils.GetAbsoluteFilePath(_project.ProjectHome, "requirements.txt"); if (!_installRequirements || !File.Exists(txt)) { return; } WriteOutput(Strings.RequirementsTxtInstalling.FormatUI(txt)); if (await Pip.Install( _project.Site, factory, "-r " + ProcessOutput.QuoteSingleArgument(txt), false, // never elevate for a virtual environment _output )) { WriteOutput(Strings.PackageInstallSucceeded.FormatUI(Path.GetFileName(txt))); } else { WriteOutput(Strings.PackageInstallFailed.FormatUI(Path.GetFileName(txt))); } }
/// <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, Redirector output = null) { bool elevate = provider.GetPythonToolsService().GeneralOptions.ElevatePip; if (factory.Configuration.Version < new Version(2, 5)) { if (output != null) { output.WriteErrorLine("Python versions earlier than 2.5 are not supported by PTVS."); } throw new OperationCanceledException(); } else if (factory.Configuration.Version == new Version(2, 5)) { return(Pip.Install(provider, factory, "https://go.microsoft.com/fwlink/?LinkID=317970", elevate, output)); } else { return(Pip.Install(provider, factory, "https://go.microsoft.com/fwlink/?LinkID=317969", elevate, output)); } }
public async Task Run() { var service = _project.Site.GetComponentModel().GetService <IInterpreterOptionsService>(); var factory = await _project.CreateOrAddVirtualEnvironment( service, _create, _virtualEnvPath, _baseInterpreter, _useVEnv ); if (factory == null) { return; } var txt = CommonUtils.GetAbsoluteFilePath(_project.ProjectHome, "requirements.txt"); if (!_installRequirements || !File.Exists(txt)) { return; } WriteOutput(SR.RequirementsTxtInstalling, txt); if (await Pip.Install( _project.Site, factory, "-r " + ProcessOutput.QuoteSingleArgument(txt), false, // never elevate for a virtual environment _output )) { WriteOutput(SR.PackageInstallSucceeded, Path.GetFileName(txt)); } else { WriteOutput(SR.PackageInstallFailed, Path.GetFileName(txt)); } }
private async Task ExecuteWorker(PythonProjectNode project) { _errorListProvider.Tasks.Clear(); var interpFactory = project.GetInterpreterFactoryOrThrow(); var startInfo = GetStartInfo(project); var packagesToInstall = new List <string>(); foreach (var pkg in startInfo.RequiredPackages) { if (!await Pip.IsInstalled(interpFactory, pkg)) { 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) { await Pip.Install( project.Site, interpFactory, string.Join(" ", packagesToInstall), false, OutputWindowRedirector.GetGeneral(project.Site)); } else if (selectedButton == runAnywayButton) { } else { throw new TaskCanceledException(); } } if (startInfo.TargetType == CreatePythonCommandItem.TargetTypePip) { if (startInfo.ExecuteInOutput) { await Pip.Install( _project.Site, interpFactory, string.IsNullOrEmpty(startInfo.Arguments)? startInfo.Filename : string.Format("{0} {1}", startInfo.Filename, startInfo.Arguments), project.Site, false, OutputWindowRedirector.GetGeneral(project.Site) ); return; } // Rewrite start info to execute startInfo.TargetType = CreatePythonCommandItem.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); } }
private async Task ExecuteWorker(PythonProjectNode project) { _errorListProvider.Tasks.Clear(); var interpFactory = project.GetInterpreterFactory(); var startInfo = GetStartInfo(project); var packagesToInstall = new List <string>(); foreach (var pkg in startInfo.RequiredPackages) { if (!await Pip.IsInstalled(interpFactory, pkg)) { packagesToInstall.Add(pkg); } } if (packagesToInstall.Any()) { await Pip.QueryInstall( interpFactory, string.Join(" ", packagesToInstall), project.Site, SR.GetString(SR.CustomCommandPrerequisitesInstallPrompt, string.Join("\r\n", packagesToInstall)), false, OutputWindowRedirector.GetGeneral(project.Site) ); } if (startInfo.TargetType == CreatePythonCommandItem.TargetTypePip) { if (startInfo.ExecuteInOutput) { await Pip.Install( _project.Site, interpFactory, string.Format("{0} {1}", startInfo.Filename, startInfo.Arguments), project.Site, false, OutputWindowRedirector.GetGeneral(project.Site) ); return; } // Rewrite start info to execute startInfo.TargetType = CreatePythonCommandItem.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); } }