Require a path separator when detecting the active virtualenv - #11001
Open
tarann26 wants to merge 1 commit into
Open
Require a path separator when detecting the active virtualenv#11001tarann26 wants to merge 1 commit into
tarann26 wants to merge 1 commit into
Conversation
create_venv() used a plain string startswith() check to decide whether Poetry is already running inside the venv it just built, so a sibling venv whose name textually extends the target's (e.g. hosting Poetry from .venv-poetry while the project venv is .venv) false-matched and Poetry silently installed the project into the system Python instead.
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In the new regression test, consider using
os.environ.pop("VIRTUAL_ENV", None)instead ofdel os.environ["VIRTUAL_ENV"]to avoid a potentialKeyErrorwhen the variable is absent. - The test hardcodes a
bin/python3.9path which is POSIX-specific; if the test suite is expected to run on Windows, you may want to construct the sibling executable path in a platform-aware way.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the new regression test, consider using `os.environ.pop("VIRTUAL_ENV", None)` instead of `del os.environ["VIRTUAL_ENV"]` to avoid a potential `KeyError` when the variable is absent.
- The test hardcodes a `bin/python3.9` path which is POSIX-specific; if the test suite is expected to run on Windows, you may want to construct the sibling executable path in a platform-aware way.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Check List
Resolves: #10357
Problem
When Poetry is itself hosted in a virtualenv whose name is a textual prefix-superset of the project venv — for example Poetry runs from
.venv-poetrywhile the project venv is.venv—create_venv()mistakes the two for the same environment and installs the project's dependencies into the base/system Python instead of the project venv.After building the target venv,
create_venv()walkssys.executable's symlink chain to decide whether Poetry is already running inside it:str.startswithhas no path boundary, so".../.venv-poetry/bin/python".startswith(".../.venv")isTrue. Poetry wrongly concludes it is inside.venv, returnsget_system_env(), and the install lands in the base Python.Fix
Require a path-separator boundary:
A real in-venv interpreter (
<venv>/bin/python) still matches viap_venv + os.sep, while a sibling such as.venv-poetryno longer does. Bothpandp_venvare already passed throughos.path.normcase, soos.sepis the correct native boundary on POSIX and Windows.A regression test covering the sibling-venv scenario is included.