-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Conversation
…ent variable fails as well
poetry/utils/shell.py
Outdated
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"] |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
If poetry is not run within a shell, like explained in #2115, shell detection fails.
shellingham itself explain how one can try to detect a default shell via environment variables. This PR implements the suggestion.
Fixes: #2115