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

On windows poetry shell always start a cmd #2030

Closed
2 tasks done
ggtools opened this issue Feb 12, 2020 · 3 comments · Fixed by #3706
Closed
2 tasks done

On windows poetry shell always start a cmd #2030

ggtools opened this issue Feb 12, 2020 · 3 comments · Fixed by #3706
Labels
kind/feature Feature requests/implementations

Comments

@ggtools
Copy link

ggtools commented Feb 12, 2020

  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

Feature Request

On Windows it looks like poetry shell always spawn a cmd even when run from a Powershell window. As expected the $SHELL environment variable is not working. This could be worked around by using poetry run "C:\Program Files\PowerShell\7-preview\pwsh.exe"

@TBBle
Copy link
Contributor

TBBle commented Jan 4, 2021

tl;dr: This is a bug in the get-poetry.py install script, it creates poetry.bat on Windows, so the closest shell is always cmd.exe.

Workaround is to install Poetry using pip or pipx.

Fix would be for get-poetry.py to create an executable instead of a batch file, e.g., what pip does using distlib.scripts.

(I think this is a general bug in Poetry, I just noticed that "scripts" created in my project are also shell scripts, not binaries, as they would be if installed using setuptools and setup.py)


I'm not sure why shellingham.detect_shell() is not working, but always starting cmd.exe is because on Windows, Poetry ignores $SHELL and uses $COMPSEC instead.

A quick test suggested that shellingham.detect_shell() should work, returning ('pwsh', 'C:\...\pwsh.exe') as I'd expect when I just install shellingham from PyPI.

I tried setting $ENV:COMSPEC before running poetry shell and it broke poetry shell, and also poetry run ... and in fact any other poetry command, because the installation of Poetry has put a poetry.bat in my path, which tries to use $ENV:COMSPEC if it's set, to run.

So if I in-line the batch file, and set $ENV:COMPSEC, it works...

$ENV:COMSPEC="C:\Program Files\PowerShell\7\pwsh.exe"
py -3 "${ENV:USERPROFILE}\.poetry\bin\poetry" shell

Of course, that's not a workaround, but suggests that if Poetry honoured $SHELL if present, and only if absent fell back to $COMPSEC, it'd be doing that the help says it does.

Edit: Oh, in fact, shellingham.detect_shell() is not failing, it's returning ('cmd', 'cmd.exe'). That makes sense, because as mentioned, poetry is running via poetry.bat, so the closest-to-Poetry shell is cmd.

So the $COMSPEC change isn't changing what Poetry does, it's affecting the cmd.exe launched by Poetry.

So this is a problem with the way Poetry is installed. I've had similar issues, because calling poetry run pytest for example from batch files tends to terminate the batch file, it needs to be call poetry run pytest.

I'm not sure if poetry.bat is under Poetry's control, or if it happens with a pip/pipx install, this install was done via the recommended get-poetry.py script.

Edit: Yeah, it's the get-poetry.py script that creates the .bat file. Running the included Python script, i.e.

py -3 ${ENV:USERPROFILE}\.poetry\bin\poetry shell

correctly launches pwsh.exe

So the fix for this would be for the get-poetry.py installer to create an executable (like pip does using distlib.scripts) instead of a batch file on Windows.

In the meantime, I might switch to pipx to manage Poetry. I've confirmed that poetry shell from pipx install poetry does launch pwsh when run from pwsh. So that's the workaround.

Edit: I'm not even sure how the $SHELL env-var works anywhere, if Poetry uses the current detected shell by default, and only checks $SHELL if detection fails. Perhaps detection always fails on non-Windows? Or something else is honouring $SHELL elsewhere, but not on Windows.

@issam-seghir
Copy link

issam-seghir commented Mar 8, 2022

py -3 ${ENV:USERPROFILE}\.poetry\bin\poetry shell

this command work for me 💯

Copy link

github-actions bot commented Mar 2, 2024

This issue 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 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature Feature requests/implementations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants