Skip to content

Commit

Permalink
Merge from 5.x: PR #21467
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Oct 28, 2023
2 parents 22ac3e5 + 8a478b9 commit 4297369
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ concurrency:

jobs:
build:
# Use this to disable the workflow
# if: false
name: Linux - Py${{ matrix.PYTHON_VERSION }}
runs-on: ubuntu-latest
env:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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:
Expand Down
27 changes: 25 additions & 2 deletions spyder/utils/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down Expand Up @@ -114,8 +132,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:
Expand All @@ -126,6 +145,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()
Expand Down Expand Up @@ -167,7 +190,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:
Expand Down
3 changes: 2 additions & 1 deletion spyder/utils/tests/test_conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,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', 'test', 'jedi-test-env', 'spytest-ž']

expected_envs = ['base', 'jedi-test-env', 'spytest-ž', 'test']
expected_envs = ['conda: ' + env for env in expected_envs]

assert set(expected_envs) == set(output.keys())


Expand Down

0 comments on commit 4297369

Please sign in to comment.