Skip to content

Commit 7223240

Browse files
authored
Merge pull request #2651 from pypa/shell-fallback-improvement
Use COMSPEC for shell detection fallback
2 parents 5a55c88 + 9ec4ff1 commit 7223240

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

news/2651.behavior

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add ``COMSPEC`` to fallback option (along with ``SHELL`` and ``PYENV_SHELL``)
2+
if shell detection fails, improving robustness on Windows.

pipenv/environments.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@
207207
PIPENV_SKIP_VALIDATION = True
208208

209209
# Internal, the default shell to use if shell detection fails.
210-
PIPENV_SHELL = os.environ.get("SHELL") or os.environ.get("PYENV_SHELL")
210+
PIPENV_SHELL = (
211+
os.environ.get("SHELL") or
212+
os.environ.get("PYENV_SHELL") or
213+
os.environ.get("COMSPEC")
214+
)
211215

212216
# Internal, to tell whether the command line session is interactive.
213217
SESSION_IS_INTERACTIVE = bool(os.isatty(sys.stdout.fileno()))

pipenv/shells.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ def detect_info():
2929
raise ShellDetectionFailure
3030

3131

32-
def _get_activate_script(venv):
32+
def _get_activate_script(cmd, venv):
3333
"""Returns the string to activate a virtualenv.
3434
3535
This is POSIX-only at the moment since the compat (pexpect-based) shell
3636
does not work elsewhere anyway.
3737
"""
3838
# Suffix and source command for other shells.
3939
# Support for fish shell.
40-
if PIPENV_SHELL and "fish" in PIPENV_SHELL:
40+
if "fish" in cmd:
4141
suffix = ".fish"
4242
command = "source"
4343
# Support for csh shell.
44-
elif PIPENV_SHELL and "csh" in PIPENV_SHELL:
44+
elif "csh" in cmd:
4545
suffix = ".csh"
4646
command = "source"
4747
else:
@@ -104,7 +104,7 @@ def fork_compat(self, venv, cwd, args):
104104
dims = get_terminal_size()
105105
with temp_environ():
106106
c = pexpect.spawn(self.cmd, ["-i"], dimensions=(dims.lines, dims.columns))
107-
c.sendline(_get_activate_script(venv))
107+
c.sendline(_get_activate_script(self.cmd, venv))
108108
if args:
109109
c.sendline(" ".join(args))
110110

0 commit comments

Comments
 (0)