private CustomCommand( PythonProjectNode project, string target, string label ) { _project = project; _target = target; _label = string.IsNullOrWhiteSpace(label) ? target : label; var match = _customCommandLabelRegex.Match(label); if (match.Success) { DisplayLabel = LoadResourceFromAssembly( match.Groups["assembly"].Value, match.Groups["namespace"].Value, match.Groups["key"].Value ); } else { DisplayLabel = _label; } DisplayLabel = PerformSubstitutions(project, DisplayLabel); _canExecute = !string.IsNullOrEmpty(target); Verb = "Project." + Regex.Replace( DisplayLabelWithoutAccessKeys, "[^a-z0-9]+", "", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase ); AlternateCmdId = AddNamedCommand(project.Site, Verb); _errorListProvider = new ErrorListProvider(_project.Site); }
internal static IVsInteractiveWindow/*!*/ EnsureReplWindow(IServiceProvider serviceProvider, IPythonInterpreterFactory factory, PythonProjectNode project) { var compModel = serviceProvider.GetComponentModel(); var provider = compModel.GetService<InteractiveWindowProvider>(); string replId = PythonReplEvaluatorProvider.GetReplId(factory, project); var window = provider.FindReplWindow(replId); if (window == null) { window = provider.CreateInteractiveWindow( serviceProvider.GetPythonContentType(), factory.Description + " Interactive", typeof(PythonLanguageInfo).GUID, replId ); var toolWindow = window as ToolWindowPane; if (toolWindow != null) { toolWindow.BitmapImageMoniker = KnownMonikers.PYInteractiveWindow; } var pyService = serviceProvider.GetPythonToolsService(); window.InteractiveWindow.SetSmartUpDown(pyService.GetInteractiveOptions(factory).ReplSmartHistory); } if (project != null && project.Interpreters.IsProjectSpecific(factory)) { project.AddActionOnClose(window, BasePythonReplEvaluator.CloseReplWindow); } return window; }
public AddInterpreterView( PythonProjectNode project, IServiceProvider serviceProvider, IEnumerable<IPythonInterpreterFactory> selected ) { _project = project; Interpreters = new ObservableCollection<InterpreterView>(InterpreterView.GetInterpreters(serviceProvider, project)); var map = new Dictionary<IPythonInterpreterFactory, InterpreterView>(); foreach (var view in Interpreters) { map[view.Interpreter] = view; view.IsSelected = false; } foreach (var interp in selected) { InterpreterView view; if (map.TryGetValue(interp, out view)) { view.IsSelected = true; } else { view = new InterpreterView(interp, interp.Configuration.FullDescription, false); view.IsSelected = true; Interpreters.Add(view); } } _project.InterpreterFactoriesChanged += OnInterpretersChanged; }
private AddInterpreter(PythonProjectNode project, IInterpreterOptionsService service) { _view = new AddInterpreterView(project, project.Site, project.InterpreterFactories); _view.PropertyChanged += View_PropertyChanged; DataContext = _view; InitializeComponent(); }
public AddVirtualEnvironmentView( PythonProjectNode project, IInterpreterRegistryService interpreterService, IPythonInterpreterFactory selectInterpreter ) { _interpreterService = interpreterService; _project = project; VirtualEnvBasePath = _projectHome = project.ProjectHome; Interpreters = new ObservableCollection<InterpreterView>(InterpreterView.GetInterpreters(project.Site, project)); var selection = Interpreters.FirstOrDefault(v => v.Interpreter == selectInterpreter); if (selection == null) { selection = Interpreters.FirstOrDefault(v => v.Interpreter == project.GetInterpreterFactory()) ?? Interpreters.LastOrDefault(); } BaseInterpreter = selection; _project.InterpreterFactoriesChanged += OnInterpretersChanged; var venvName = "env"; for (int i = 1; Directory.Exists(Path.Combine(_projectHome, venvName)); ++i) { venvName = "env" + i.ToString(); } VirtualEnvName = venvName; CanInstallRequirementsTxt = File.Exists(PathUtils.GetAbsoluteFilePath(_projectHome, "requirements.txt")); WillInstallRequirementsTxt = CanInstallRequirementsTxt; }
internal PythonExtensionReferenceNode(PythonProjectNode root, ProjectElement element, string filename) : base(root, element) { Utilities.ArgumentNotNullOrEmpty("filename", filename); _filename = CommonUtils.GetAbsoluteFilePath(root.ProjectHome, filename); AnalyzeReference(root.GetInterpreter() as IPythonInterpreterWithProjectReferences); InitializeFileChangeEvents(); }
public static IEnumerable<IPythonInterpreterFactory> ShowDialog( PythonProjectNode project, IInterpreterOptionsService service) { using (var wnd = new AddInterpreter(project, service)) { if (wnd.ShowModal() ?? false) { return wnd._view.Interpreters.Where(iv => iv.IsSelected).Select(iv => iv.Interpreter); } } return null; }
internal void OpenProject(VisualStudioApp app, string slnName, out PythonProjectNode projectNode, out EnvDTE.Project dteProject) { PythonVersion.AssertInstalled(); dteProject = app.OpenProject("TestData\\Targets\\" + slnName); projectNode = dteProject.GetPythonProject(); var fact = projectNode.InterpreterFactories.Where(x => x.Configuration.Id == PythonVersion.Id).FirstOrDefault(); Assert.IsNotNull(fact, "Project does not contain expected interpreter"); projectNode.ActiveInterpreter = fact; dteProject.Save(); }
public void UpdateProject(PythonProjectNode node, MSBuild.Project project) { lock (_projects) { if (project == null) { _projects.Remove(node); } else if (!_projects.ContainsKey(node) || _projects[node] != project) { _projects[node] = project; } } // Always raise the event, this also occurs when we're adding projects // to the MSBuild.Project. ProjectsChanaged?.Invoke(this, EventArgs.Empty); }
public InterpretersPackageNode(PythonProjectNode project, PackageSpec spec) : base(project, new VirtualProjectElement(project)) { ExcludeNodeFromScc = true; _package = spec.Clone(); _packageName = spec.FullSpec; if (spec.ExactVersion.IsEmpty) { _caption = spec.Name; _canUninstall = false; } else { _caption = string.Format("{0} ({1})", spec.Name, spec.ExactVersion); _canUninstall = !CannotUninstall.Contains(spec.Name); } }
internal static IVsInteractiveWindow/*!*/ EnsureReplWindow(IServiceProvider serviceProvider, InterpreterConfiguration config, PythonProjectNode project) { var compModel = serviceProvider.GetComponentModel(); var provider = compModel.GetService<InteractiveWindowProvider>(); var vsProjectContext = compModel.GetService<VsProjectContextProvider>(); string replId = config != null ? PythonReplEvaluatorProvider.GetEvaluatorId(config) : PythonReplEvaluatorProvider.GetEvaluatorId(project); var window = provider.OpenOrCreate(replId); project?.AddActionOnClose(window, InteractiveWindowProvider.Close); return window; }
public InterpretersPackageNode(PythonProjectNode project, string name) : base(project, new VirtualProjectElement(project)) { ExcludeNodeFromScc = true; _packageName = name; var match = PipFreezeRegex.Match(name); if (match.Success) { var namePart = match.Groups["name"].Value; _caption = string.Format("{0} ({1})", namePart, match.Groups["version"]); _canUninstall = !CannotUninstall.Contains(namePart); } else { _caption = name; _canUninstall = false; } }
internal static IVsInteractiveWindow/*!*/ EnsureReplWindow(IServiceProvider serviceProvider, InterpreterConfiguration config, PythonProjectNode project) { var compModel = serviceProvider.GetComponentModel(); var provider = compModel.GetService<InteractiveWindowProvider>(); var vsProjectContext = compModel.GetService<VsProjectContextProvider>(); var projectId = project != null ? PythonReplEvaluatorProvider.GetEvaluatorId(project) : null; var configId = config != null ? PythonReplEvaluatorProvider.GetEvaluatorId(config) : null; IVsInteractiveWindow window; // If we find an open window for the project, prefer that to a per-config one if (!string.IsNullOrEmpty(projectId)) { window = provider.Open(projectId); if (window != null) { if (window.InteractiveWindow.GetPythonEvaluator()?.AssociatedProjectHasChanged == true) { // We have an existing window, but it needs to be reset. // Let's create a new one window = provider.Create(projectId); project.AddActionOnClose(window, InteractiveWindowProvider.Close); } return window; } } // If we find an open window for the configuration, return that if (!string.IsNullOrEmpty(configId)) { window = provider.Open(configId); if (window != null) { return window; } } // No window found, so let's create one if (!string.IsNullOrEmpty(projectId)) { window = provider.Create(projectId); project.AddActionOnClose(window, InteractiveWindowProvider.Close); } else if (!string.IsNullOrEmpty(configId)) { window = provider.Create(configId); } else { var interpService = compModel.GetService<IInterpreterOptionsService>(); window = provider.Create(PythonReplEvaluatorProvider.GetEvaluatorId(interpService.DefaultInterpreter.Configuration)); } return window; }
public AddVirtualEnvironmentOperation( PythonProjectNode project, string virtualEnvPath, IPythonInterpreterFactory baseInterpreter, bool create, bool useVEnv, bool installRequirements, Redirector output = null ) { _project = project; _virtualEnvPath = virtualEnvPath; _baseInterpreter = baseInterpreter; _create = create; _useVEnv = useVEnv; _installRequirements = installRequirements; _output = output; }
public InterpretersNode( PythonProjectNode project, ProjectItem item, IPythonInterpreterFactory factory, bool isInterpreterReference, bool canDelete, bool isGlobalDefault = false ) : base(project, ChooseElement(project, item)) { ExcludeNodeFromScc = true; _interpreters = project.Interpreters; _interpreterService = project.Site.GetComponentModel().GetService<IInterpreterOptionsService>(); _factory = factory; _isReference = isInterpreterReference; _canDelete = canDelete; _isGlobalDefault = isGlobalDefault; _canRemove = !isGlobalDefault; _captionSuffix = isGlobalDefault ? SR.GetString(SR.GlobalDefaultSuffix) : ""; if (Directory.Exists(_factory.Configuration.LibraryPath)) { // TODO: Need to handle watching for creation try { _fileWatcher = new FileSystemWatcher(_factory.Configuration.LibraryPath); } catch (ArgumentException) { // Path was not actually valid, despite Directory.Exists // returning true. } if (_fileWatcher != null) { try { _fileWatcher.IncludeSubdirectories = true; _fileWatcher.Deleted += PackagesChanged; _fileWatcher.Created += PackagesChanged; _fileWatcher.EnableRaisingEvents = true; // Only create the timer if the file watcher is running. _timer = new Timer(CheckPackages); } catch (IOException) { // Raced with directory deletion _fileWatcher.Dispose(); _fileWatcher = null; } } } }
public InterpretersNode( PythonProjectNode project, IPythonInterpreterFactory factory, bool isInterpreterReference, bool canDelete, bool isGlobalDefault = false, bool? canRemove = null ) : base(project, MakeElement(project)) { ExcludeNodeFromScc = true; _interpreterService = project.Site.GetComponentModel().GetService<IInterpreterRegistryService>(); _factory = factory; _isReference = isInterpreterReference; _canDelete = canDelete; _isGlobalDefault = isGlobalDefault; _canRemove = canRemove.HasValue ? canRemove.Value : !isGlobalDefault; _captionSuffix = isGlobalDefault ? Strings.GlobalDefaultSuffix : ""; if (_factory.PackageManager != null) { _factory.PackageManager.InstalledPackagesChanged += InstalledPackagesChanged; } }
public AddInterpreterView( PythonProjectNode project, IServiceProvider serviceProvider, IEnumerable<string> selectedIds ) { _project = project; Interpreters = new ObservableCollection<InterpreterView>(InterpreterView.GetInterpreters(serviceProvider, project)); var map = new Dictionary<string, InterpreterView>(); foreach (var view in Interpreters) { map[view.Id] = view; view.IsSelected = false; } foreach (var id in selectedIds) { InterpreterView view; if (map.TryGetValue(id, out view)) { view.IsSelected = true; } } _project.InterpreterFactoriesChanged += OnInterpretersChanged; }
public static async Task ShowDialog( PythonProjectNode project, IInterpreterOptionsService service, bool browseForExisting = false ) { using (var view = new AddVirtualEnvironmentView(project, service, project.Interpreters.ActiveInterpreter)) { var wnd = new AddVirtualEnvironment(view); if (browseForExisting) { var path = project.Site.BrowseForDirectory(IntPtr.Zero, project.ProjectHome); if (string.IsNullOrEmpty(path)) { throw new OperationCanceledException(); } view.VirtualEnvName = path; view.WillInstallRequirementsTxt = false; await view.WaitForReady(); if (view.WillAddVirtualEnv) { await view.Create().HandleAllExceptions(SR.ProductName, typeof(AddVirtualEnvironment)); return; } view.ShowBrowsePathError = true; view.BrowseOrigPrefix = DerivedInterpreterFactory.GetOrigPrefixPath(path); } wnd.VirtualEnvPathTextBox.ScrollToEnd(); wnd.VirtualEnvPathTextBox.SelectAll(); wnd.VirtualEnvPathTextBox.Focus(); wnd.ShowModal(); var op = wnd._currentOperation; if (op != null) { await op; } } }
public void MergeRequirements() { // Comments should be preserved, only package specs should change. AssertUtil.AreEqual( PythonProjectNode.MergeRequirements(new[] { "a # with a comment", "B==0.2", "# just a comment B==01234", "", "x < 1", "d==1.0 e==2.0 f==3.0" }, new[] { "b==0.1", "a==0.2", "c==0.3", "e==4.0", "x==0.8" }.Select(p => PackageSpec.FromRequirement(p)), false), "a==0.2 # with a comment", "b==0.1", "# just a comment B==01234", "", "x==0.8", "d==1.0 e==4.0 f==3.0" ); // addNew is true, so the c==0.3 should be added. AssertUtil.AreEqual( PythonProjectNode.MergeRequirements(new[] { "a # with a comment", "b==0.2", "# just a comment B==01234" }, new[] { "B==0.1", // case is updated "a==0.2", "c==0.3" }.Select(p => PackageSpec.FromRequirement(p)), true), "a==0.2 # with a comment", "B==0.1", "# just a comment B==01234", "c==0.3" ); // No existing entries, so the new ones are sorted and returned. AssertUtil.AreEqual( PythonProjectNode.MergeRequirements(null, new[] { "b==0.2", "a==0.1", "c==0.3" }.Select(p => PackageSpec.FromRequirement(p)), false), "a==0.1", "b==0.2", "c==0.3" ); // Check all the inequalities const string inequalities = "<=|>=|<|>|!=|=="; AssertUtil.AreEqual( PythonProjectNode.MergeRequirements( inequalities.Split('|').Select(s => "a " + s + " 1.2.3"), new[] { "a==0" }.Select(p => PackageSpec.FromRequirement(p)), false ), inequalities.Split('|').Select(_ => "a==0").ToArray() ); }
private static async Task ShowDialogAsync( PageKind activePage, IServiceProvider site, PythonProjectNode project, string existingCondaEnvName = null, string environmentYmlPath = null, string requirementsTxtPath = null, CancellationToken ct = default(CancellationToken) ) { if (site == null) { throw new ArgumentNullException(nameof(site)); } ProjectView[] projectViews; ProjectView selectedProjectView; try { var sln = (IVsSolution)site.GetService(typeof(SVsSolution)); var projects = sln?.EnumerateLoadedPythonProjects().ToArray() ?? new PythonProjectNode[0]; projectViews = projects .Select((projectNode) => new ProjectView(projectNode)) .ToArray(); selectedProjectView = projectViews.SingleOrDefault(pv => pv.Node == project); } catch (InvalidOperationException ex) { Debug.Fail(ex.ToUnhandledExceptionMessage(typeof(AddEnvironmentDialog))); projectViews = new ProjectView[0]; selectedProjectView = null; } if (selectedProjectView != null) { if (existingCondaEnvName != null) { selectedProjectView.MissingCondaEnvName = existingCondaEnvName; } if (environmentYmlPath != null) { selectedProjectView.EnvironmentYmlPath = environmentYmlPath; } if (requirementsTxtPath != null) { selectedProjectView.RequirementsTxtPath = requirementsTxtPath; } } var addVirtualView = new AddVirtualEnvironmentView( site, projectViews, selectedProjectView ); var addCondaView = new AddCondaEnvironmentView( site, projectViews, selectedProjectView ); var addExistingView = new AddExistingEnvironmentView( site, projectViews, selectedProjectView ); var addInstalledView = new AddInstalledEnvironmentView( site, projectViews, selectedProjectView ); EnvironmentViewBase activeView; switch (activePage) { case PageKind.VirtualEnvironment: activeView = addVirtualView; break; case PageKind.CondaEnvironment: activeView = addCondaView; break; case PageKind.ExistingEnvironment: activeView = addExistingView; break; case PageKind.InstalledEnvironment: activeView = addInstalledView; break; default: Debug.Assert(false, string.Format("Unknown page kind '{0}'", activePage)); activeView = null; break; } using (var dlg = new AddEnvironmentDialog( new EnvironmentViewBase[] { addVirtualView, addCondaView, addExistingView, addInstalledView, }, activeView )) { try { WindowHelper.ShowModal(dlg); } catch (Exception) { dlg.Close(); throw; } if (dlg.DialogResult ?? false) { var view = dlg.View.PagesView.CurrentItem as EnvironmentViewBase; Debug.Assert(view != null); if (view != null) { try { await view.ApplyAsync(); } catch (Exception ex) when(!ex.IsCriticalException()) { Debug.Fail(ex.ToUnhandledExceptionMessage(typeof(AddEnvironmentDialog)), Strings.ProductTitle); } } } } }
internal Task ExecuteAsync(PythonProjectNode projectNode, string commandName) { Console.WriteLine("Executing command {0} asynchronously", commandName); return projectNode.Site.GetUIThread().InvokeTask(() => projectNode._customCommands.First(cc => cc.DisplayLabel == commandName).ExecuteAsync(projectNode)); }
internal static IVsInteractiveWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, VsProjectAnalyzer analyzer, PythonProjectNode project) { return(EnsureReplWindow(serviceProvider, analyzer.InterpreterFactory.Configuration, project)); }
public InterpretersContainerNode(PythonProjectNode project) : base(project.ProjectMgr) { _projectNode = project; ExcludeNodeFromScc = true; }
public PythonAssemblyReferenceNode(PythonProjectNode root, string assemblyPath) : base(root, assemblyPath) { AnalyzeReference(root.GetInterpreter() as IPythonInterpreterWithProjectReferences); }
internal static IVsInteractiveWindow/*!*/ EnsureReplWindow(IServiceProvider serviceProvider, VsProjectAnalyzer analyzer, PythonProjectNode project) { return EnsureReplWindow(serviceProvider, analyzer.InterpreterFactory, project); }
internal static string GetReplId(IPythonInterpreterFactory interpreter, PythonProjectNode project = null) { return(GetReplId(interpreter, project, false)); }
public static async Task <IPythonInterpreterFactory> CreateAndAddFactory( IServiceProvider site, IInterpreterRegistryService registry, IInterpreterOptionsService options, PythonProjectNode project, IPythonWorkspaceContext workspace, string path, IPythonInterpreterFactory baseInterp, bool registerAsCustomEnv, string customEnvName, bool preferVEnv = false ) { if (site == null) { throw new ArgumentNullException(nameof(site)); } if (registry == null) { throw new ArgumentNullException(nameof(registry)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (baseInterp == null) { throw new ArgumentNullException(nameof(baseInterp)); } if (preferVEnv) { await CreateWithVEnv(site, baseInterp, path); } else { await CreateWithVirtualEnv(site, baseInterp, path); } if (registerAsCustomEnv) { GetVirtualEnvConfig(path, baseInterp, out string interpExe, out string winterpExe, out string pathVar); var factory = await CustomEnv.CreateCustomEnv( registry, options, path, interpExe, winterpExe, pathVar, baseInterp.Configuration.Architecture, baseInterp.Configuration.Version, customEnvName ); if (factory != null) { if (project != null) { project.AddInterpreter(factory.Configuration.Id); } else if (workspace != null) { await workspace.SetInterpreterFactoryAsync(factory); } } return(factory); } else { if (project != null) { return(project.AddVirtualEnvironment(registry, path, baseInterp)); } else if (workspace != null) { // In workspaces, always store the path to the virtual env's python.exe GetVirtualEnvConfig(path, baseInterp, out string interpExe, out string winterpExe, out string pathVar); var workspaceFactoryProvider = site.GetComponentModel().GetService <WorkspaceInterpreterFactoryProvider>(); using (workspaceFactoryProvider?.SuppressDiscoverFactories(forceDiscoveryOnDispose: true)) { var relativeInterpExe = PathUtils.GetRelativeFilePath(workspace.Location, interpExe); await workspace.SetInterpreterAsync(relativeInterpExe); } var factory = workspaceFactoryProvider? .GetInterpreterFactories() .FirstOrDefault(f => PathUtils.IsSamePath(f.Configuration.InterpreterPath, interpExe)); return(factory); } else { return(null); } } }
private static void CloudProjectTest(string roleType, bool openServiceDefinition) { Assert.IsTrue(roleType == "Web" || roleType == "Worker", "Invalid roleType: " + roleType); var asm = Assembly.Load("Microsoft.VisualStudio.CloudService.Wizard,Version=1.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"); if (asm != null && asm.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false) .OfType <AssemblyFileVersionAttribute>() .Any(a => { Version ver; return(Version.TryParse(a.Version, out ver) && ver < new Version(2, 5)); }) ) { Assert.Inconclusive("Test requires Microsoft Azure Tools 2.5 or later"); } using (var app = new PythonVisualStudioApp()) using (FileUtils.Backup(TestData.GetPath(@"TestData\CloudProject\ServiceDefinition.csdef"))) { app.OpenProject("TestData\\CloudProject.sln", expectedProjects: 3); var ccproj = app.Dte.Solution.Projects.Cast <Project>().FirstOrDefault(p => p.Name == "CloudProject"); Assert.IsNotNull(ccproj); if (openServiceDefinition) { var wnd = ccproj.ProjectItems.Item("ServiceDefinition.csdef").Open(); wnd.Activate(); app.OnDispose(() => wnd.Close()); } IVsHierarchy hier; var sln = app.GetService <IVsSolution>(typeof(SVsSolution)); ErrorHandler.ThrowOnFailure(sln.GetProjectOfUniqueName(ccproj.FullName, out hier)); app.ServiceProvider.GetUIThread().InvokeAsync(() => PythonProjectNode.UpdateServiceDefinition(hier, roleType, roleType + "Role1", app.ServiceProvider) ).GetAwaiter().GetResult(); var doc = new XmlDocument(); for (int retries = 5; retries > 0; --retries) { try { doc.Load(TestData.GetPath(@"TestData\CloudProject\ServiceDefinition.csdef")); break; } catch (IOException ex) { Console.WriteLine("Exception while reading ServiceDefinition.csdef.{0}{1}", Environment.NewLine, ex); } catch (XmlException) { var copyTo = TestData.GetPath(@"TestData\CloudProject\" + Path.GetRandomFileName()); File.Copy(TestData.GetPath(@"TestData\CloudProject\ServiceDefinition.csdef"), copyTo); Console.WriteLine("Copied file to " + copyTo); throw; } Thread.Sleep(100); } var ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("sd", "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"); doc.Save(Console.Out); var nav = doc.CreateNavigator(); if (roleType == "Web") { Assert.IsNotNull(nav.SelectSingleNode( "/sd:ServiceDefinition/sd:WebRole[@name='WebRole1']/sd:Startup/sd:Task[@commandLine='ps.cmd ConfigureCloudService.ps1']", ns )); } else if (roleType == "Worker") { Assert.IsNotNull(nav.SelectSingleNode( "/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Startup/sd:Task[@commandLine='bin\\ps.cmd ConfigureCloudService.ps1']", ns )); Assert.IsNotNull(nav.SelectSingleNode( "/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Runtime/sd:EntryPoint/sd:ProgramEntryPoint[@commandLine='bin\\ps.cmd LaunchWorker.ps1']", ns )); } } }
internal static IPythonInterpreterFactory CreateVirtualEnvironment(string pythonVersion, VisualStudioApp app, PythonProjectNode pyProj) { var uiThread = app.ServiceProvider.GetUIThread(); var task = uiThread.InvokeTask(() => { var model = app.GetService <IComponentModel>(typeof(SComponentModel)); var service = model.GetService <IInterpreterRegistryService>(); return(pyProj.CreateOrAddVirtualEnvironment( service, true, Path.Combine(pyProj.ProjectHome, "env"), service.FindInterpreter("Global|PythonCore|" + pythonVersion + "-32"), Version.Parse(pythonVersion) >= new Version(3, 3) )); }); try { Assert.IsTrue(task.Wait(TimeSpan.FromMinutes(2.0)), "Timed out waiting for venv"); } catch (AggregateException ex) { throw ex.InnerException; } var factory = task.Result; Assert.IsTrue(uiThread.Invoke(() => factory.Configuration.Id == pyProj.GetInterpreterFactory().Configuration.Id)); return(factory); }
internal Task ExecuteAsync(PythonProjectNode projectNode, string commandName) { Console.WriteLine("Executing command {0} asynchronously", commandName); return(projectNode.Site.GetUIThread().InvokeTask(() => projectNode._customCommands.First(cc => cc.DisplayLabel == commandName).ExecuteAsync(projectNode))); }
internal static string GetReplId(IPythonInterpreterFactory interpreter, PythonProjectNode project = null) { return GetReplId(interpreter, project, false); }
public PythonAssemblyReferenceNode(PythonProjectNode root, ProjectElement element) : base(root, element) { AnalyzeReference(root.GetInterpreter() as IPythonInterpreterWithProjectReferences); }
internal static string GetReplId(IPythonInterpreterFactory interpreter, PythonProjectNode project, bool alwaysPerProject) { if (alwaysPerProject || project != null && project.Interpreters.IsProjectSpecific(interpreter)) { return GetConfigurableReplId(interpreter, (IVsHierarchy)project, ""); } else { return String.Format("{0} {1} {2}", _replGuid, interpreter.Id, interpreter.Configuration.Version ); } }
internal static IVsInteractiveWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, InterpreterConfiguration config, PythonProjectNode project) { var compModel = serviceProvider.GetComponentModel(); var provider = compModel.GetService <InteractiveWindowProvider>(); var vsProjectContext = compModel.GetService <VsProjectContextProvider>(); var projectId = project != null?PythonReplEvaluatorProvider.GetEvaluatorId(project) : null; var configId = config != null?PythonReplEvaluatorProvider.GetEvaluatorId(config) : null; if (config?.IsRunnable() == false) { throw new MissingInterpreterException( Strings.MissingEnvironment.FormatUI(config.Description, config.Version) ); } IVsInteractiveWindow window; // If we find an open window for the project, prefer that to a per-config one if (!string.IsNullOrEmpty(projectId)) { window = provider.Open( projectId, e => ((e as SelectableReplEvaluator)?.Evaluator as PythonCommonInteractiveEvaluator)?.AssociatedProjectHasChanged != true ); if (window != null) { return(window); } } // If we find an open window for the configuration, return that if (!string.IsNullOrEmpty(configId)) { window = provider.Open(configId); if (window != null) { return(window); } } // No window found, so let's create one if (!string.IsNullOrEmpty(projectId)) { window = provider.Create(projectId); project.AddActionOnClose(window, w => InteractiveWindowProvider.CloseIfEvaluatorMatches(w, projectId)); } else if (!string.IsNullOrEmpty(configId)) { window = provider.Create(configId); } else { var interpService = compModel.GetService <IInterpreterOptionsService>(); window = provider.Create(PythonReplEvaluatorProvider.GetEvaluatorId(interpService.DefaultInterpreter.Configuration)); } return(window); }
public LauncherInfo(PythonProjectNode project, IPythonLauncherProvider launcher) { Launcher = launcher; LauncherOptions = launcher.GetLauncherOptions(project); OptionsControl = LauncherOptions.Control; LauncherOptions.LoadSettings(); }
public static async Task <IPythonInterpreterFactory> CreateAndAddFactory( IServiceProvider site, IInterpreterRegistryService registry, IInterpreterOptionsService options, PythonProjectNode project, string path, IPythonInterpreterFactory baseInterp, bool registerAsCustomEnv, string customEnvName, bool preferVEnv = false ) { if (site == null) { throw new ArgumentNullException(nameof(site)); } if (registry == null) { throw new ArgumentNullException(nameof(registry)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (baseInterp == null) { throw new ArgumentNullException(nameof(baseInterp)); } if (preferVEnv) { await CreateWithVEnv(site, baseInterp, path); } else { await CreateWithVirtualEnv(site, baseInterp, path); } if (registerAsCustomEnv) { GetVirtualEnvConfig(path, baseInterp, out string interpExe, out string winterpExe, out string pathVar); var factory = await CustomEnv.CreateCustomEnv( registry, options, path, interpExe, winterpExe, pathVar, baseInterp.Configuration.Architecture, baseInterp.Configuration.Version, customEnvName ); if (project != null && factory != null) { project.AddInterpreter(factory.Configuration.Id); } return(factory); } else { if (project != null) { return(project.AddVirtualEnvironment(registry, path, baseInterp)); } else { return(null); } } }
public PythonReferenceContainerNode(PythonProjectNode root) : base(root) { }
internal void Execute(PythonProjectNode projectNode, string commandName) { Console.WriteLine("Executing command {0}", commandName); var t = projectNode.Site.GetUIThread().InvokeTask(() => projectNode._customCommands.First(cc => cc.DisplayLabel == commandName).ExecuteAsync(projectNode)); t.GetAwaiter().GetResult(); }
public CurrentWorkingDirectoryNode(PythonProjectNode project, string path) : base(project, path, new VirtualProjectElement(project)) { }
internal void OpenProject(VisualStudioApp app, string slnName, PythonVersion python, out PythonProjectNode projectNode, out EnvDTE.Project dteProject) { dteProject = app.OpenProject(app.CopyProjectForTest("TestData\\Targets\\" + slnName)); var pn = projectNode = dteProject.GetPythonProject(); var fact = projectNode.InterpreterFactories.Where(x => x.Configuration.Id == python.Id).FirstOrDefault(); Assert.IsNotNull(fact, "Project does not contain expected interpreter"); app.ServiceProvider.GetUIThread().Invoke(() => pn.ActiveInterpreter = fact); dteProject.Save(); }
public ErrorUnRegister(TaskProvider provider, IVsErrorList errorList, uint cookie, PythonProjectNode project, string filename) { _errorList = errorList; _cookie = cookie; _project = project; _filename = filename; _provider = provider; }
internal static IVsInteractiveWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, IPythonInterpreterFactory factory, PythonProjectNode project) { var compModel = serviceProvider.GetComponentModel(); var provider = compModel.GetService <InteractiveWindowProvider>(); string replId = PythonReplEvaluatorProvider.GetReplId(factory, project); var window = provider.FindReplWindow(replId); if (window == null) { window = provider.CreateInteractiveWindow( serviceProvider.GetPythonContentType(), factory.Description + " Interactive", typeof(PythonLanguageInfo).GUID, replId ); #if DEV14 var toolWindow = window as ToolWindowPane; if (toolWindow != null) { toolWindow.BitmapImageMoniker = KnownMonikers.PYInteractiveWindow; } #endif var pyService = serviceProvider.GetPythonToolsService(); window.InteractiveWindow.SetSmartUpDown(pyService.GetInteractiveOptions(factory).ReplSmartHistory); } if (project != null && project.Interpreters.IsProjectSpecific(factory)) { project.AddActionOnClose(window, BasePythonReplEvaluator.CloseReplWindow); } return(window); }
public CommonSearchPathContainerNode(PythonProjectNode project) : base(project.ProjectMgr) { _projectNode = project; this.ExcludeNodeFromScc = true; }