python-poetry / python-poetry/poetry
Inconsistent treatment of the VIRTUAL_ENV variable
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 34.3k
- Forks
- 2.5k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 30
Description
-
I am on the latest Poetry version.
-
I have searched the issues of this repo and believe that this is not a duplicate.
-
OS version and name: macOS Mojave 10.14.2
-
Poetry version: 1.0.3
-
Link of a Gist with the contents of your pyproject.toml file: n/a
Issue
With VIRTUAL_ENV set, when switching into a project using a local .venv, poetry continues to use the env pointed to by VIRTUAL_ENV. However, when switching into a project using the common virtualenvs directory, VIRTUAL_ENV is ignored and the project virtualenv is used.
Switching from project using common virtualenvs location to one using local .venv while VIRTUAL_ENV is set - notice output of poetry env info -p is incorrect (or more specifically, reflects VIRTUAL_ENV):
npyscreen$ echo `poetry env info -p`
/Users/ryan/Library/Caches/pypoetry/virtualenvs/npyscreen-KP5NaiQl-py3.8
npyscreen$ export VIRTUAL_ENV=/Users/ryan/Library/Caches/pypoetry/virtualenvs/npyscreen-KP5NaiQl-py3.8
npyscreen$ cd ../testproj/
testproj$ echo `poetry env info -p`
/Users/ryan/Library/Caches/pypoetry/virtualenvs/npyscreen-KP5NaiQl-py3.8
testproj$ unset VIRTUAL_ENV && echo `poetry env info -p`
/Users/ryan/Documents/workspace/testproj/.venv
Switching from project using local .venv to one using common virtualenvs dir - output of poetry env info -p reflects project setting despite VIRTUAL_ENV:
testproj$ export VIRTUAL_ENV=/Users/ryan/Documents/workspace/testproj/.venv
testproj$ cd ../npyscreen
npyscreen$ echo `poetry env info -p`
/Users/ryan/Library/Caches/pypoetry/virtualenvs/npyscreen-KP5NaiQl-py3.8
This is due to code starting at:
https://github.com/python-poetry/poetry/blob/12db4a5e189ea8514e70f22279ae540274a0e5af/poetry/utils/env.py#L303
which sets env for the common directory virtual envs but not the local .venv envs, which is then checked a few lines later at:
https://github.com/python-poetry/poetry/blob/12db4a5e189ea8514e70f22279ae540274a0e5af/poetry/utils/env.py#L322
I have not attempted a fix/PR (though it should be simple) as I am not knowledgeable on the reasons the code might have been written this way, or what other (negative?) effects a change here might induce.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in poetry/utils/env.py at the logic around the referenced lines 303 and 322, then reproduce the two project-switching scenarios with VIRTUAL_ENV set and unset. Confirm the intended behavior for local .venv and common-directory environments, and add or update coverage so both cases treat VIRTUAL_ENV consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100