Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use COMSPEC for shell detection fallback #2651

Merged
merged 3 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/2651.behavior
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add ``COMSPEC`` to fallback option (along with ``SHELL`` and ``PYENV_SHELL``)
if shell detection fails, improving robustness on Windows.
6 changes: 5 additions & 1 deletion pipenv/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 whether the command line session is interactive.
SESSION_IS_INTERACTIVE = bool(os.isatty(sys.stdout.fileno()))
8 changes: 4 additions & 4 deletions pipenv/shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ 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
does not work elsewhere anyway.
"""
# 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:
Expand Down Expand Up @@ -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))

Expand Down