Skip to content

Commit

Permalink
Merge pull request conda#6588 from kalefranz/fix-6579-python-not-reco…
Browse files Browse the repository at this point in the history
…gnized

fix conda#6579 python not recognized as command
  • Loading branch information
nehaljwani authored Dec 29, 2017
2 parents 03df284 + a9fe951 commit f5f6419
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions conda/activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ def build_activate(self, env_name_or_prefix):

self._update_prompt(set_vars, conda_prompt_modifier)

if on_win and self.shell == 'cmd.exe':
import ctypes
export_vars.update({
"PYTHONIOENCODING": ctypes.cdll.kernel32.GetACP(),
})

return {
'unset_vars': (),
'set_vars': set_vars,
Expand Down
6 changes: 3 additions & 3 deletions conda/shell/Library/bin/conda.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
)
:skip_conda_exe_dev

@FOR /F "delims=" %%i IN ('@python -c "import ctypes; print(ctypes.cdll.kernel32.GetACP())"') DO @SET "PYTHONIOENCODING=%%i"
@chcp %PYTHONIOENCODING% > NUL

@IF "%1"=="activate" GOTO :DO_ACTIVATE
@IF "%1"=="deactivate" GOTO :DO_DEACTIVATE

Expand Down Expand Up @@ -43,6 +40,9 @@
@DEL /F /Q "%_TEMP_SCRIPT_PATH%"
@SET _TEMP_SCRIPT_PATH=
@SET "PROMPT=%CONDA_PROMPT_MODIFIER%%PROMPT%"

@IF NOT "%PYTHONIOENCODING%"=="" @chcp %PYTHONIOENCODING% > NUL

@GOTO :End

:DO_DEACTIVATE
Expand Down
11 changes: 10 additions & 1 deletion tests/test_activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
log = getLogger(__name__)


if on_win:
import ctypes
PYTHONIOENCODING = ctypes.cdll.kernel32.GetACP()
else:
PYTHONIOENCODING = None


class ActivatorUnitTests(TestCase):

def test_activate_environment_not_found(self):
Expand Down Expand Up @@ -274,7 +281,6 @@ def test_activate_same_environment(self):
'CONDA_PROMPT_MODIFIER': "(%s) " % td,
'CONDA_SHLVL': 1,
}

assert builder['unset_vars'] == ()
assert builder['set_vars'] == {}
assert builder['export_vars'] == export_vars
Expand Down Expand Up @@ -478,6 +484,7 @@ def test_posix_basic(self):
'ps1': os.environ.get('PS1', ''),
}

@pytest.mark.skipif(not on_win, reason="cmd.exe only on Windows")
def test_cmd_exe_basic(self):
activator = Activator('cmd.exe')
self.make_dot_d_files(activator.script_extension)
Expand All @@ -500,13 +507,15 @@ def test_cmd_exe_basic(self):
@SET "CONDA_PYTHON_EXE=%(sys_executable)s"
@SET "CONDA_SHLVL=1"
@SET "PATH=%(new_path)s"
@SET "PYTHONIOENCODING=%(PYTHONIOENCODING)s"
@CALL "%(activate1)s"
""") % {
'converted_prefix': activator.path_conversion(self.prefix),
'native_prefix': self.prefix,
'new_path': activator.pathsep_join(new_path_parts),
'sys_executable': activator.path_conversion(sys.executable),
'activate1': activator.path_conversion(join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1.bat')),
'PYTHONIOENCODING': PYTHONIOENCODING,
}

with env_vars({
Expand Down

0 comments on commit f5f6419

Please sign in to comment.