You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you're inside of a poetry shell for one project and you run poetry --directory OTHER-PROJECT-PATH ..., the --directory option is ignored.
Steps to Reproduce
Convenience Scripts
Steps to reproduce are in bash scripts step-one.sh, step-two.sh, and reset.sh for clarity and easy repetition. Alternately copy desired file contents and paste into a shell.
step-one.sh
# step one: create two projects and start a shell in one of them#
poetry new poetry-bug-repro-one && poetry new poetry-bug-repro-two
cd poetry-bug-repro-one && poetry install &&cd - ||echo fail
cd poetry-bug-repro-two && poetry install && poetry shell ||echo fail
step-two.sh
# step two: run poetry --directory OTHER-PROJECT-PATH env info -p# and demonstrate that it doesn't produce the correct venv path#
other_path=
read -r other_path <<(poetry --directory $(realpath ../poetry-bug-repro-one) env info -p)
[[ ${other_path##*/}=~ ^poetry-bug-repro-one ]] &&echo OK ||echo"FAIL Directory name should start with 'poetry-bug-repro-one' but instead is: '${other_path##*/}'"&&echoecho"Other venv path:"
poetry --directory $(realpath ../poetry-bug-repro-one) env info -p
reset.sh
# reset: remove project directories and virtual envs#
rm -rf $(poetry config virtualenvs.path)/poetry-bug-repro-*
rm -rf "${PWD%/poetry-bug-repro-*}"/poetry-bug-repro-*
[[ -n"${VIRTUAL_ENV}" ]] &&exit# NOTE: You must `cd ..` after sourcing this step if you're in a project shell
I've found that this seems to be caused by the VIRTUAL_ENV environment variable. When you run poetry shell (or I think any poetry command), it sets this variable. Unfortunately if you try to use the -C/--directory OTHER-PROJECT-PATH option when this variable is set, the environment variable overrides the CLI option for choosing the virtualenv to use. i.e., if you add unset VIRTUAL_ENV to the top of step-two.sh, it works as expected.
IMO the correct behaviour here should be that path provided by the --directory CLI option should have higher precedence than the VIRTUAL_ENV environment variable when choosing the virtual environment to use.
I'm having similar issues - I'm tyring to write a python a script that cleans up my dev dir and tries to identify poetry venv paths - if I run poetry env info using subprocess.run and remove the VIRTUAL_ENV environment variable, poetry silently quits with exit code 1, if I don't, then it thinks the virtualenv is the "parent project's" venv.
Description
When you're inside of a
poetry shell
for one project and you runpoetry --directory OTHER-PROJECT-PATH ...
, the--directory
option is ignored.Steps to Reproduce
Convenience Scripts
step-one.sh
step-two.sh
reset.sh
Reproduce the Bug
Start Over
Workarounds
Exit the poetry shell before running
poetry --directory OTHER-PROJECT-PATH ...
(step-two.sh
).Poetry Installation Method
install.python-poetry.org
Operating System
Darwin 23.4.0 arm64
Poetry Version
Poetry (version 1.8.3)
Poetry Configuration
The text was updated successfully, but these errors were encountered: