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

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 a team March 8, 2020 07:34
@finswimmer finswimmer added the area/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
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:
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.

@abn abn merged commit 518b699 into python-poetry:master Apr 6, 2020
@sdispater sdispater mentioned this pull request Jun 5, 2020
Copy link

github-actions bot commented Mar 1, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/error-handling Bad error messages/insufficient error handling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Unable to detect the current shell." when running Vagrant command
2 participants