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); } }