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

zsh: poetry shell doesn't work if space character in .venv path #7244

Closed
4 tasks done
dimstunt opened this issue Dec 23, 2022 · 6 comments · Fixed by #7245
Closed
4 tasks done

zsh: poetry shell doesn't work if space character in .venv path #7244

dimstunt opened this issue Dec 23, 2022 · 6 comments · Fixed by #7245
Labels
area/shell Related to `poetry shell` kind/bug Something isn't working as expected

Comments

@dimstunt
Copy link
Contributor

dimstunt commented Dec 23, 2022

  • Poetry version: Poetry (version 1.3.1)
  • Python version:
Poetry Version: 1.3.1
Python:  3.9.5

Virtualenv
Python:         3.9.5
Implementation: CPython
Path:           /Applications/Dwarf Fortress LMP/LNP/Utilities/Ann2/AnnouncementWindow/.venv
Executable:     /Applications/Dwarf Fortress LMP/LNP/Utilities/Ann2/AnnouncementWindow/.venv/bin/python
Valid:          True

System
Platform:   darwin
OS:         posix
Python:     3.9.5
Path:       /Users/dimstunt/.pyenv/versions/3.9.5
Executable: /Users/dimstunt/.pyenv/versions/3.9.5/bin/python3.9
  • OS version and name: macOS 13.0.1
  • pyproject.toml: any
  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

If there is a space in the path to the virtual environment (e.g. when using virtualenvs.in-project=true) the poetry shell command is not executed as expected, because the shlex.quote function wraps that path in single quotes, and when running in zsh, that wrapped path is wrapped in quotes again.

executed:

poetry shell
# Spawning shell within /Applications/Dwarf Fortress LMP/LNP/Utilities/Ann2/AnnouncementWindow/.venv
emulate bash -c '. '/Applications/Dwarf Fortress LMP/LNP/Utilities/Ann2/AnnouncementWindow/.venv/bin/activate''
# emulate: unknown argument Fortress

expected:

poetry shell
# Spawning shell within /Applications/Dwarf Fortress LMP/LNP/Utilities/Ann2/AnnouncementWindow/.venv
emulate bash -c ". '/Applications/Dwarf Fortress LMP/LNP/Utilities/Ann2/AnnouncementWindow/.venv/bin/activate'"
@dimstunt dimstunt added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Dec 23, 2022
dimstunt added a commit to dimstunt/poetry that referenced this issue Dec 23, 2022
fix zsh: poetry shell doesn't work if space character in .venv path

python-poetry#7244
@d3cryptofc
Copy link

i have the same problem..

@OllionDavidCunliffe
Copy link

Bumping as I have the same issue, I was able to manually resolve by passing the same argument as the expected outcome to get the shell to activate in my project.

@budivoogt
Copy link

Running into the same issue. Manually resolving by escaping the spaces doesn't work for me either.

What does work is simply activating the venv like you normally would with:

source .venv/bin/activate

I installed Poetry with pipx and am using Oh My Zsh. Have carefully followed the instructions, including executing the following in terminal:

mkdir $ZSH_CUSTOM/plugins/poetry poetry completions zsh > $ZSH_CUSTOM/plugins/poetry/_poetry

And adding the poetry plugin to the ~/.zshrc plugin array.

@fatveg
Copy link

fatveg commented Jan 19, 2024

It appears like there is a pull request to fix this from a year ago but it hasn't been accepted (looks like there was a timeout on a test).

In the meantime I just added:

alias v_activate="source .venv/bin/activate"

to my .zshrc and use that instead of poetry shell

@radoering
Copy link
Member

It appears like there is a pull request to fix this from a year ago but it hasn't been accepted (looks like there was a timeout on a test).

Thanks for the hint. The PR looks good to me.

@radoering radoering added area/shell Related to `poetry shell` and removed status/triage This issue needs to be triaged labels Jan 20, 2024
Copy link

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 Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/shell Related to `poetry shell` kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants