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

Conversation

finswimmer
Copy link
Member

@finswimmer finswimmer commented Mar 8, 2020

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

@finswimmer finswimmer requested a review from Mar 8, 2020
@finswimmer finswimmer added the Error Handling Bad error messages/insufficient error handling label Mar 8, 2020
poetry/utils/shell.py Show resolved Hide resolved
poetry/utils/shell.py Outdated Show resolved Hide resolved
poetry/utils/shell.py Outdated Show resolved Hide resolved
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:
Copy link
Member

@abn abn Apr 3, 2020

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

@abn abn Apr 3, 2020

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

@finswimmer finswimmer Apr 4, 2020

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.

abn
abn approved these changes Apr 6, 2020
@abn abn merged commit 518b699 into python-poetry:master Apr 6, 2020
16 checks passed
@sdispater sdispater mentioned this pull request Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Handling Bad error messages/insufficient error handling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants