Skip to content

Comments

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

Merged
abn merged 3 commits intopython-poetry:masterfrom
finswimmer:issue-2115-detect-shell
Apr 6, 2020
Merged

try to find shell via os.environ if detect_shell fail (#2115)#2147
abn merged 3 commits intopython-poetry:masterfrom
finswimmer:issue-2115-detect-shell

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
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.

@abn abn merged commit 518b699 into python-poetry:master Apr 6, 2020
@sdispater sdispater mentioned this pull request Jun 5, 2020
@github-actions
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