Skip to content

Commit

Permalink
fix legacy activate for cmd.exe
Browse files Browse the repository at this point in the history
Signed-off-by: Kale Franz <[email protected]>
  • Loading branch information
kalefranz committed May 1, 2018
1 parent 4d6112a commit b9ea45c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ test:
- conda_env
commands:
{% if on_win %}
- SET CONDA_SHLVL=
- CALL %PREFIX%\condacmd\conda_hook.bat
- CALL conda.bat activate base
- FOR /F "delims=" %%i IN ('python -c "import sys; print(sys.version_info[0])"') DO set "PYTHON_MAJOR_VERSION=%%i"
Expand All @@ -74,6 +75,7 @@ test:
- CALL conda.bat deactivate
- py.test tests -m "not integration and not installed" -vv
{% else %}
- unset CONDA_SHLVL
- eval "$(python -m conda shell.bash hook)"
- conda activate base
- export PYTHON_MAJOR_VERSION=$(python -c "import sys; print(sys.version_info[0])")
Expand Down
6 changes: 3 additions & 3 deletions conda/activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _build_activate_stack(self, env_name_or_prefix, stack):
prefix = normpath(prefix)

# query environment
old_conda_shlvl = int(self.environ.get('CONDA_SHLVL', 0))
old_conda_shlvl = int(self.environ.get('CONDA_SHLVL', '').strip() or 0)
new_conda_shlvl = old_conda_shlvl + 1
old_conda_prefix = self.environ.get('CONDA_PREFIX')

Expand Down Expand Up @@ -269,7 +269,7 @@ def _build_activate_stack(self, env_name_or_prefix, stack):
def build_deactivate(self):
# query environment
old_conda_prefix = self.environ.get('CONDA_PREFIX')
old_conda_shlvl = int(self.environ.get('CONDA_SHLVL', 0))
old_conda_shlvl = int(self.environ.get('CONDA_SHLVL', '').strip() or 0)
if not old_conda_prefix or old_conda_shlvl < 1:
# no active environment, so cannot deactivate; do nothing
return {
Expand Down Expand Up @@ -340,7 +340,7 @@ def build_deactivate(self):

def build_reactivate(self):
conda_prefix = self.environ.get('CONDA_PREFIX')
conda_shlvl = int(self.environ.get('CONDA_SHLVL', 0))
conda_shlvl = int(self.environ.get('CONDA_SHLVL', '').strip() or 0)
if not conda_prefix or conda_shlvl < 1:
# no active environment, so cannot reactivate; do nothing
return {
Expand Down
5 changes: 3 additions & 2 deletions tests/test_activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,9 @@ class InteractiveShell(object):
},
'cmd.exe': {
'activator': 'cmd.exe',
'init_command': 'conda\\shell\\condacmd\\conda-hook.bat',
'init_command': 'set CONDA_SHLVL= '
'&& conda\\shell\\condacmd\\conda_hook.bat '
'&& set CONDA_EXE="python -m conda"',
'print_env_var': '@echo %%%s%%',
},
'csh': {
Expand Down Expand Up @@ -1491,7 +1493,6 @@ def test_legacy_activate_deactivate_bash(self):
def test_legacy_activate_deactivate_cmd_exe(self):
with InteractiveShell('cmd.exe') as shell:
shell.sendline("echo off")
shell.sendline("SET CONDA_EXE=python -m conda")

shell.sendline("SET \"PATH=%s\\shell\\Scripts;%%PATH%%\"" % CONDA_PACKAGE_ROOT)
shell.sendline("activate \"%s\"" % self.prefix2)
Expand Down

0 comments on commit b9ea45c

Please sign in to comment.