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

try to find shell via os.environ if detect_shell fail (#2115) #2147

Merged
merged 3 commits into from
Apr 6, 2020
Merged
Changes from 2 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
12 changes: 11 additions & 1 deletion poetry/utils/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from shellingham import detect_shell

from ._compat import WINDOWS
from ._compat import Path
abn marked this conversation as resolved.
Show resolved Hide resolved
from .env import VirtualEnv


Expand Down Expand Up @@ -41,7 +42,16 @@ def get(cls): # type: () -> Shell

try:
name, path = detect_shell(os.getpid())
except (RuntimeError, ShellDetectionFailure):
except ShellDetectionFailure:
if os.name == "posix":
shell = os.environ["SHELL"]
elif os.name == "nt":
shell = os.environ["COMSPEC"]
else:
raise RuntimeError("Unable to detect the current shell.")

name, path = Path(shell).stem, shell
except RuntimeError:
abn marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
except ShellDetectionFailure:
if os.name == "posix":
shell = os.environ["SHELL"]
elif os.name == "nt":
shell = os.environ["COMSPEC"]
else:
raise RuntimeError("Unable to detect the current shell.")
name, path = Path(shell).stem, shell
except RuntimeError:
except (RuntimeError, ShellDetectionFailure):
if os.name == "posix":
shell = os.environ["SHELL"]
elif os.name == "nt":
shell = os.environ["COMSPEC"]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to really guard against failure, then we should probably check the env var exists before accessing it :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://github.com/sarugaku/shellingham#notes-for-application-developers the env vars should always exists. But yes, testing it doesn't hurt.

raise RuntimeError("Unable to detect the current shell.")

cls._shell = cls(name, path)
Expand Down