diff --git a/.github/workflows/test-files.yml b/.github/workflows/test-files.yml index c62115945be..e96ac895916 100644 --- a/.github/workflows/test-files.yml +++ b/.github/workflows/test-files.yml @@ -41,6 +41,8 @@ concurrency: jobs: build: + # Use this to disable the workflow + # if: false name: Linux - Py${{ matrix.PYTHON_VERSION }} runs-on: ubuntu-latest env: diff --git a/.github/workflows/test-linux.yml b/.github/workflows/test-linux.yml index 81b060d9491..f0708ce5682 100644 --- a/.github/workflows/test-linux.yml +++ b/.github/workflows/test-linux.yml @@ -41,6 +41,8 @@ concurrency: jobs: build: + # Use this to disable the workflow + # if: false name: Linux - Py${{ matrix.PYTHON_VERSION }}, ${{ matrix.INSTALL_TYPE }}, ${{ matrix.TEST_TYPE }} runs-on: ubuntu-20.04 env: diff --git a/.github/workflows/test-mac.yml b/.github/workflows/test-mac.yml index 123cd500eba..5872c129d17 100644 --- a/.github/workflows/test-mac.yml +++ b/.github/workflows/test-mac.yml @@ -41,6 +41,8 @@ concurrency: jobs: build: + # Use this to disable the workflow + # if: false name: Mac - Py${{ matrix.PYTHON_VERSION }}, ${{ matrix.INSTALL_TYPE }}, ${{ matrix.TEST_TYPE }} runs-on: macos-12 env: diff --git a/.github/workflows/test-win.yml b/.github/workflows/test-win.yml index 28a50d66049..6cb97a1e15a 100644 --- a/.github/workflows/test-win.yml +++ b/.github/workflows/test-win.yml @@ -41,6 +41,8 @@ concurrency: jobs: build: + # Use this to disable the workflow + # if: false name: Windows - Py${{ matrix.PYTHON_VERSION }}, ${{ matrix.INSTALL_TYPE }}, ${{ matrix.TEST_TYPE }} runs-on: windows-latest env: diff --git a/spyder/utils/conda.py b/spyder/utils/conda.py index 6b2064fc0cd..c1a68b242b9 100644 --- a/spyder/utils/conda.py +++ b/spyder/utils/conda.py @@ -20,6 +20,24 @@ CONDA_ENV_LIST_CACHE = {} +def _env_for_conda(): + """ + Required environment variables for Conda to work as expected. + + Notes + ----- + This is needed on Windows since Conda 23.9.0 + """ + env = {} + if os.name == 'nt': + env_vars = [("HOMEDRIVE", "C:"), ("HOMEPATH", "\\Users\\xxxxx")] + for var, default in env_vars: + value = os.environ.get(var, default) + env[var] = value + + return env + + def add_quotes(path): """Return quotes if needed for spaces on path.""" quotes = '"' if ' ' in path and '"' not in path else '' @@ -133,8 +151,9 @@ def get_list_conda_envs(): return env_list cmdstr = ' '.join([conda, 'env', 'list', '--json']) + try: - out, __ = run_shell_command(cmdstr, env={}).communicate() + out, __ = run_shell_command(cmdstr, env=_env_for_conda()).communicate() out = out.decode() out = json.loads(out) except Exception: @@ -145,6 +164,10 @@ def get_list_conda_envs(): path = osp.join(env, 'python.exe') if WINDOWS else osp.join( env, 'bin', 'python') + # In case the environment doesn't have Python + if not osp.isfile(path): + continue + try: version, __ = run_program(path, ['--version']).communicate() version = version.decode() @@ -186,7 +209,7 @@ def get_spyder_conda_channel(): cmdstr = ' '.join([conda, 'list', 'spyder', '--json', '--prefix', env]) try: - out, __ = run_shell_command(cmdstr, env={}).communicate() + out, __ = run_shell_command(cmdstr, env=_env_for_conda()).communicate() out = out.decode() out = json.loads(out) except Exception: diff --git a/spyder/utils/tests/test_conda.py b/spyder/utils/tests/test_conda.py index bd57e6f2a00..c0c0804b84c 100644 --- a/spyder/utils/tests/test_conda.py +++ b/spyder/utils/tests/test_conda.py @@ -71,13 +71,10 @@ def test_find_conda(): @pytest.mark.skipif(not running_in_ci(), reason="Only meant for CIs") def test_get_list_conda_envs(): output = get_list_conda_envs() - expected_envs = ['base', 'jedi-test-env', 'spytest-ž'] - - # Conda can't detect the test env on Windows, don't know why. - if os.name != 'nt': - expected_envs.append('test') + expected_envs = ['base', 'jedi-test-env', 'spytest-ž', 'test'] expected_envs = ['conda: ' + env for env in expected_envs] + assert set(expected_envs) == set(output.keys())