python-poetry / poetry

Python packaging and dependency management made easy

Home Page:https://python-poetry.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

poetry shell in git bash on Windows broken since 1.2.0

Godsmith opened this issue · comments

  • [x ] I am on the latest Poetry version.
  • [x ] I have searched the issues of this repo and believe that this is not a duplicate.
  • [ x] If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Windows 11, git 2.33.1.windows.1
  • Poetry version: 1.2.0
  • Link of a Gist with the contents of your pyproject.toml file: Not relevant

Issue

Since poetry 1.2.0, poetry shell does not work on git bash in Windows.

$ poetry shell
Spawning shell within C:\Users\filip\AppData\Local\pypoetry\Cache\virtualenvs\dinrplan-9Ih6xyvL-py3.10
/usr/bin/bash: /K: No such file or directory

Downgrading to 1.1.5 works:

filip@Marwin MINGW64 ~/workspace/python/dinrplan (master)
$ poetry --version
Poetry version 1.1.15

filip@Marwin MINGW64 ~/workspace/python/dinrplan (master)
$ poetry shell
Spawning shell within C:\Users\filip\AppData\Local\pypoetry\Cache\virtualenvs\dinrplan-T1RTjXIi-py3.9

filip@Marwin MINGW64 ~/workspace/python/dinrplan (master)
$ which python
/c/Users/filip/AppData/Local/pypoetry/Cache/virtualenvs/dinrplan-T1RTjXIi-py3.9/Scripts/python

Looking at the code, I believe 57450f2 broke the git bash support.

I think your identification of the point of change is incorrect, but we definitely need to check $SHELL instead of blindly trusting that the user is using CMD/Powershell.

Is there a suggested workaround to this, besides using powershell when running under windows?

poetry shell is just a convenience tool to start a subshell and activate an environment -- you can activate the env yourself with more typing (find the path with poetry env info --path).

The identification point is correct. For windows, we are only considering Powershell or cmd.exe. I'll add a third case to fallback to the previous behavior. The prompt modification won't happen in this situtation.

Here is what shellingham reports

$ .venv/Scripts/python.exe -i
Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import shellingham
>>> shellingham.detect_shell()
('bash', 'C:\\Program Files\\Git\\usr\\bin\\bash.exe')

@cbehopkins

From previous poetry brokenness, I ended up having a shell alias to do the right thing.

alias pshell='poetry run bash -i'

You can also hardcode which bash you want to run if you want to run.

Keep in mind that at least in my case, on Windows, poetry changed the virtual env it installs to. So if you were using 1.1.15 and upgraded to 1.2.0 or later, you'll want to check to make sure your IDE points to the right virtualenv for your python interpreter.

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.