def _get_envs(self): """Get the list of environments in the system.""" # Compute info of default interpreter to have it available in # case we need to switch to it. This will avoid lags when # doing that in get_value. if sys.executable not in self.path_to_env: self._get_env_info(sys.executable) # Get envs conda_env = get_list_conda_envs() pyenv_env = get_list_pyenv_envs() return {**conda_env, **pyenv_env}
def __init__(self, parent, statusbar, icon=None): """Status bar widget for displaying the current conda environment.""" self._interpreter = None super(InterpreterStatus, self).__init__(parent, statusbar, icon=icon) self.main = parent self.env_actions = [] self.path_to_env = {} conda_env = get_list_conda_envs() pyenv_env = get_list_pyenv_envs() self.envs = {**conda_env, **pyenv_env} for env in list(self.envs.keys()): path, version = self.envs[env] # Save paths in lowercase on Windows to avoid issues with # capitalization. path = path.lower() if os.name == 'nt' else path self.path_to_env[path] = env self.menu = QMenu(self) self.sig_clicked.connect(self.show_menu)
def __init__(self, parent, main): GeneralConfigPage.__init__(self, parent, main) self.cus_exec_radio = None self.pyexec_edit = None self.cus_exec_combo = None conda_env = get_list_conda_envs() pyenv_env = get_list_pyenv_envs() envs = {**conda_env, **pyenv_env} valid_custom_list = [] for env in envs.keys(): path, _ = envs[env] valid_custom_list.append(path) self.set_option('custom_interpreters_list', valid_custom_list) # Python executable selection (initializing default values as well) executable = self.get_option('executable', get_python_executable()) if self.get_option('default'): executable = get_python_executable() if not osp.isfile(executable): # This is absolutely necessary, in case the Python interpreter # executable has been moved since last Spyder execution (following # a Python distribution upgrade for example) self.set_option('executable', get_python_executable()) elif executable.endswith('pythonw.exe'): # That should not be necessary because this case is already taken # care of by the `get_python_executable` function but, this was # implemented too late, so we have to fix it here too, in case # the Python executable has already been set with pythonw.exe: self.set_option('executable', executable.replace("pythonw.exe", "python.exe")) if not self.get_option('default'): if not self.get_option('custom_interpreter'): self.set_option('custom_interpreter', ' ') self.set_custom_interpreters_list(executable) self.validate_custom_interpreters_list()
def test_get_list_conda_envs(): output = get_list_conda_envs() expected_envs = ['base', 'test', 'jedi-test-env', 'spytest-ΕΎ'] expected_envs = ['conda: ' + env for env in expected_envs] assert set(expected_envs) == set(output.keys())
# Local imports from spyder.api.plugins import Plugins from spyder.api.plugin_registration.registry import PLUGIN_REGISTRY from spyder.config.manager import CONF from spyder.plugins.preferences.api import PreferencePages from spyder.plugins.maininterpreter.plugin import MainInterpreter from spyder.plugins.preferences.tests.conftest import MainWindowMock from spyder.utils.conda import get_list_conda_envs from spyder.utils.pyenv import get_list_pyenv_envs # Get envs to show them in the Main interpreter page. This is actually # done in a thread in the InterpreterStatus widget. # We also recording the time needed to get them to compare it with the # loading time of that config page. t0 = time.time() get_list_conda_envs() get_list_pyenv_envs() GET_ENVS_TIME = time.time() - t0 def test_load_time(qtbot): from spyder.plugins.maininterpreter.confpage import ( MainInterpreterConfigPage) # Create Preferences dialog main = MainWindowMock() preferences = main.get_plugin(Plugins.Preferences) main_interpreter = PLUGIN_REGISTRY.register_plugin(main, MainInterpreter) # Create page and measure time to do it
import pytest # Local imports from spyder.api.plugins import Plugins from spyder.api.plugin_registration.registry import PLUGIN_REGISTRY from spyder.plugins.maininterpreter.plugin import MainInterpreter from spyder.plugins.preferences.tests.conftest import MainWindowMock from spyder.utils.conda import get_list_conda_envs from spyder.utils.pyenv import get_list_pyenv_envs # Get envs to show them in the Main interpreter page. This is actually # done in a thread in the InterpreterStatus widget. # We're also recording the time needed to get them to compare it with the # loading time of that config page. t0 = time.time() conda_envs = get_list_conda_envs() pyenv_envs = get_list_pyenv_envs() GET_ENVS_TIME = time.time() - t0 @pytest.mark.skipif( len(conda_envs) == 0 and len(pyenv_envs) == 0, reason="Makes no sense if conda and pyenv are not installed") def test_load_time(qtbot): # Create Preferences dialog main = MainWindowMock(None) preferences = main.get_plugin(Plugins.Preferences) PLUGIN_REGISTRY.register_plugin(main, MainInterpreter) # Create page and measure time to do it