From 059dacdd3c45e08d64792b7704c261f775fb2e88 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Thu, 26 Jul 2018 17:04:59 +0800 Subject: [PATCH 1/2] Use COMSPEC for shell detection fallback The subshell logic now considers: * PIPENV_SHELL * Auto detection * SHELL (should very likely work for POSIX) * PYENV_SHELL * COMSPEC (should always work for Windows) --- pipenv/environments.py | 6 +++++- pipenv/shells.py | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pipenv/environments.py b/pipenv/environments.py index afe82988e1..6e0c865126 100644 --- a/pipenv/environments.py +++ b/pipenv/environments.py @@ -207,7 +207,11 @@ PIPENV_SKIP_VALIDATION = True # Internal, the default shell to use if shell detection fails. -PIPENV_SHELL = os.environ.get("SHELL") or os.environ.get("PYENV_SHELL") +PIPENV_SHELL = ( + os.environ.get("SHELL") or + os.environ.get("PYENV_SHELL") or + os.environ.get("COMSPEC") +) # Internal, to tell if pyenv is installed. PYENV_ROOT = os.environ.get("PYENV_ROOT", os.path.expanduser("~/.pyenv")) diff --git a/pipenv/shells.py b/pipenv/shells.py index 10826f228a..70b236ea07 100644 --- a/pipenv/shells.py +++ b/pipenv/shells.py @@ -29,7 +29,7 @@ def detect_info(): raise ShellDetectionFailure -def _get_activate_script(venv): +def _get_activate_script(cmd, venv): """Returns the string to activate a virtualenv. This is POSIX-only at the moment since the compat (pexpect-based) shell @@ -37,11 +37,11 @@ def _get_activate_script(venv): """ # Suffix and source command for other shells. # Support for fish shell. - if PIPENV_SHELL and "fish" in PIPENV_SHELL: + if "fish" in cmd: suffix = ".fish" command = "source" # Support for csh shell. - elif PIPENV_SHELL and "csh" in PIPENV_SHELL: + elif "csh" in cmd: suffix = ".csh" command = "source" else: @@ -104,7 +104,7 @@ def fork_compat(self, venv, cwd, args): dims = get_terminal_size() with temp_environ(): c = pexpect.spawn(self.cmd, ["-i"], dimensions=(dims.lines, dims.columns)) - c.sendline(_get_activate_script(venv)) + c.sendline(_get_activate_script(self.cmd, venv)) if args: c.sendline(" ".join(args)) From 7758d745a8bed0c1da9fba31745378e58732029f Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Mon, 30 Jul 2018 12:51:25 +0800 Subject: [PATCH 2/2] News --- news/2651.behavior | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 news/2651.behavior diff --git a/news/2651.behavior b/news/2651.behavior new file mode 100644 index 0000000000..be5f2d014d --- /dev/null +++ b/news/2651.behavior @@ -0,0 +1,2 @@ +Add ``COMSPEC`` to fallback option (along with ``SHELL`` and ``PYENV_SHELL``) +if shell detection fails, improving robustness on Windows.