try to find shell via os.environ if detect_shell fail (#2115)#2147
Merged
abn merged 3 commits intopython-poetry:masterfrom Apr 6, 2020
Merged
try to find shell via os.environ if detect_shell fail (#2115)#2147abn merged 3 commits intopython-poetry:masterfrom
abn merged 3 commits intopython-poetry:masterfrom
Conversation
3 tasks
ghost
reviewed
Mar 8, 2020
…ent variable fails as well
abn
requested changes
Apr 3, 2020
poetry/utils/shell.py
Outdated
Comment on lines
45
to
54
| 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: |
Member
There was a problem hiding this comment.
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"] |
Member
There was a problem hiding this comment.
If you want to really guard against failure, then we should probably check the env var exists before accessing it :)
Member
Author
There was a problem hiding this comment.
According to https://github.com/sarugaku/shellingham#notes-for-application-developers the env vars should always exists. But yes, testing it doesn't hurt.
abn
approved these changes
Apr 6, 2020
Merged
3 tasks
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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