protected override void ResetProjectDependentProperties() { // When there's no project, the only action that is viable is to register a custom environment. IEnumerable <InterpreterView> available = SelectedProject != null ? InterpreterView.GetInterpreters(Site, SelectedProject?.Node).Where(view => SelectedProject.InterpreterIds.IndexOf(view.Id) < 0) : Enumerable.Empty <InterpreterView>(); var interpreters = new ObservableCollection <InterpreterView>(available); interpreters.Insert(0, CustomInterpreter); Interpreters = interpreters; if (Interpreters.Count > 1) { SelectedInterpreter = (InterpreterView)Interpreters[1]; } else { SelectedInterpreter = CustomInterpreter; } }
internal async Task UpdateInterpreter(InterpreterView view) { if (!Dispatcher.CheckAccess()) { await Dispatcher.InvokeAsync(() => UpdateInterpreter(view)); return; } try { await _ready.WaitAsync(); } catch (ObjectDisposedException) { return; } try { WillInstallPip = false; WillInstallVirtualEnv = false; WillInstallElevated = false; MayNotSupportVirtualEnv = false; Debug.Assert(view != null); if (view == null) { return; } var interp = view.Interpreter; Debug.Assert(interp != null); if (interp == null) { return; } MayNotSupportVirtualEnv = !SupportsVirtualEnv.Contains(interp.Id); RefreshCanCreateVirtualEnv(VirtualEnvPath); var libPath = interp.Configuration.LibraryPath; if (Directory.Exists(libPath)) { var installed = await interp.FindModulesAsync("pip", "virtualenv", "venv"); if (installed.Contains("venv") || installed.Contains("virtualenv")) { WillInstallPip = false; WillInstallVirtualEnv = false; UseVEnv = !installed.Contains("virtualenv"); } else { WillInstallPip = !installed.Contains("pip"); WillInstallVirtualEnv = true; UseVEnv = false; } WillInstallElevated = (WillInstallPip || WillInstallVirtualEnv) && _project.Site.GetPythonToolsService().GeneralOptions.ElevatePip; } } finally { try { _ready.Release(); } catch (ObjectDisposedException) { } } }
private void RefreshCanCreateVirtualEnv(string path) { if (!Dispatcher.CheckAccess()) { Dispatcher.BeginInvoke((Action)(() => RefreshCanCreateVirtualEnv(path))); return; } if (Interpreters.Count == 0) { WillCreateVirtualEnv = false; WillAddVirtualEnv = false; CannotCreateVirtualEnv = false; NoInterpretersInstalled = true; return; } if (!IsValidVirtualEnvPath(path) || BaseInterpreter == null) { WillCreateVirtualEnv = false; WillAddVirtualEnv = false; CannotCreateVirtualEnv = true; NoInterpretersInstalled = false; return; } if (Directory.Exists(path) && Directory.EnumerateFileSystemEntries(path).Any()) { WillCreateVirtualEnv = false; var options = VirtualEnv.FindInterpreterOptions(path, _interpreterService); if (options != null && File.Exists(options.InterpreterPath)) { var baseInterp = _interpreterService.FindInterpreter(options.Id, options.LanguageVersion); InterpreterView baseInterpView; if (baseInterp != null && (baseInterpView = Interpreters.FirstOrDefault(iv => iv.Interpreter == baseInterp)) != null) { if (_lastUserSelectedBaseInterpreter == null) { _lastUserSelectedBaseInterpreter = BaseInterpreter; } BaseInterpreter = baseInterpView; WillAddVirtualEnv = true; } else { WillAddVirtualEnv = false; } } else { WillAddVirtualEnv = false; } CannotCreateVirtualEnv = !WillAddVirtualEnv; NoInterpretersInstalled = false; } else { WillCreateVirtualEnv = true; WillAddVirtualEnv = false; CannotCreateVirtualEnv = false; NoInterpretersInstalled = false; if (_lastUserSelectedBaseInterpreter != null) { BaseInterpreter = _lastUserSelectedBaseInterpreter; _lastUserSelectedBaseInterpreter = null; } } }
private void RefreshCanCreateVirtualEnv(string path) { if (!Dispatcher.CheckAccess()) { Dispatcher.BeginInvoke((Action)(() => RefreshCanCreateVirtualEnv(path))); return; } if (Interpreters.Count == 0) { WillCreateVirtualEnv = false; WillAddVirtualEnv = false; CannotCreateVirtualEnv = false; NoInterpretersInstalled = true; return; } if (!IsValidVirtualEnvPath(path) || BaseInterpreter == null) { WillCreateVirtualEnv = false; WillAddVirtualEnv = false; CannotCreateVirtualEnv = true; NoInterpretersInstalled = false; return; } if (Directory.Exists(path) && Directory.EnumerateFileSystemEntries(path).Any()) { WillCreateVirtualEnv = false; var config = VirtualEnv.FindInterpreterConfiguration(null, path, _interpreterService); if (config != null && File.Exists(config.InterpreterPath)) { var baseInterpView = Interpreters.FirstOrDefault(v => v.Id == config.Id); if (baseInterpView != null) { if (_lastUserSelectedBaseInterpreter == null) { _lastUserSelectedBaseInterpreter = BaseInterpreter; } BaseInterpreter = baseInterpView; WillAddVirtualEnv = true; } else { WillAddVirtualEnv = false; } } else { WillAddVirtualEnv = false; } CannotCreateVirtualEnv = !WillAddVirtualEnv; NoInterpretersInstalled = false; } else { WillCreateVirtualEnv = true; WillAddVirtualEnv = false; CannotCreateVirtualEnv = false; NoInterpretersInstalled = false; if (_lastUserSelectedBaseInterpreter != null) { BaseInterpreter = _lastUserSelectedBaseInterpreter; _lastUserSelectedBaseInterpreter = null; } } }
internal async Task UpdateInterpreterAsync(InterpreterView interpreterView) { if (!Dispatcher.CheckAccess()) { await Dispatcher.InvokeAsync(() => UpdateInterpreterAsync(interpreterView)); return; } try { await _ready.WaitAsync(); } catch (ObjectDisposedException) { return; } Progress.IsProgressDisplayed = true; IsAcceptEnabled = false; try { WillInstallPip = false; WillInstallVirtualEnv = false; WillRegisterGlobally = false; UseVEnv = false; UseVirtualEnv = false; IsAcceptShieldVisible = false; if (interpreterView == null) { return; } var interp = RegistryService.FindInterpreter(interpreterView.Id); Debug.Assert(interp != null); if (interp == null) { return; } RefreshCanCreateVirtualEnv(); if (await interp.HasModuleAsync("venv", OptionsService)) { WillInstallPip = false; WillInstallVirtualEnv = false; UseVEnv = true; UseVirtualEnv = false; } else if (await interp.HasModuleAsync("virtualenv", OptionsService)) { WillInstallPip = false; WillInstallVirtualEnv = false; UseVEnv = false; UseVirtualEnv = true; } else { WillInstallPip = await interp.HasModuleAsync("pip", OptionsService); WillInstallVirtualEnv = true; UseVEnv = false; UseVirtualEnv = true; } IsAcceptShieldVisible = (WillInstallPip || WillInstallVirtualEnv) && Site.GetPythonToolsService().GeneralOptions.ElevatePip; } finally { try { _ready.Release(); } catch (ObjectDisposedException) { } Progress.IsProgressDisplayed = false; RefreshCanCreateVirtualEnv(); } }
private void UpdateInterpreter(InterpreterView interpreterView) { UpdateInterpreterAsync(interpreterView).HandleAllExceptions(Site, GetType()).DoNotWait(); }
internal async Task UpdateInterpreter(InterpreterView view) { if (!Dispatcher.CheckAccess()) { await Dispatcher.InvokeAsync(() => UpdateInterpreter(view)); return; } try { await _ready.WaitAsync(); } catch (ObjectDisposedException) { return; } try { WillInstallPip = false; WillInstallVirtualEnv = false; WillInstallElevated = false; MayNotSupportVirtualEnv = false; Debug.Assert(view != null); if (view == null) { return; } var registry = _project.Site.GetComponentModel().GetService <IInterpreterRegistryService>(); var interp = registry.FindInterpreter(view.Id); Debug.Assert(interp != null); if (interp == null) { return; } //MayNotSupportVirtualEnv = !SupportsVirtualEnv.Contains(interp.Id); RefreshCanCreateVirtualEnv(VirtualEnvPath); var opts = _project.Site.GetComponentModel().GetService <IInterpreterOptionsService>(); if (await interp.HasModuleAsync("venv", opts)) { WillInstallPip = false; WillInstallVirtualEnv = false; UseVEnv = true; } else if (await interp.HasModuleAsync("virtualenv", opts)) { WillInstallPip = false; WillInstallVirtualEnv = false; UseVEnv = false; } else { WillInstallPip = await interp.HasModuleAsync("pip", opts); WillInstallVirtualEnv = true; UseVEnv = false; } WillInstallElevated = (WillInstallPip || WillInstallVirtualEnv) && _project.Site.GetPythonToolsService().GeneralOptions.ElevatePip; } finally { try { _ready.Release(); } catch (ObjectDisposedException) { } } }
internal async Task UpdateInterpreter(InterpreterView view) { if (!Dispatcher.CheckAccess()) { await Dispatcher.InvokeAsync(() => UpdateInterpreter(view)); return; } try { await _ready.WaitAsync(); } catch (ObjectDisposedException) { return; } try { WillInstallPip = false; WillInstallVirtualEnv = false; WillInstallElevated = false; MayNotSupportVirtualEnv = false; Debug.Assert(view != null); if (view == null) { return; } var registry = _project.Site.GetComponentModel().GetService<IInterpreterRegistryService>(); var interp = registry.FindInterpreter(view.Id); Debug.Assert(interp != null); if (interp == null) { return; } //MayNotSupportVirtualEnv = !SupportsVirtualEnv.Contains(interp.Id); RefreshCanCreateVirtualEnv(VirtualEnvPath); var installed = await interp.FindModulesAsync("pip", "virtualenv", "venv"); if (installed.Contains("venv") || installed.Contains("virtualenv")) { WillInstallPip = false; WillInstallVirtualEnv = false; UseVEnv = !installed.Contains("virtualenv"); } else { WillInstallPip = !installed.Contains("pip"); WillInstallVirtualEnv = true; UseVEnv = false; } WillInstallElevated = (WillInstallPip || WillInstallVirtualEnv) && _project.Site.GetPythonToolsService().GeneralOptions.ElevatePip; } finally { try { _ready.Release(); } catch (ObjectDisposedException) { } } }