Skip to content

Fix: GenericEnv.is_venv() in src/poetry/utils/env/generic_env.py compared... - #11011

Open
M001N wants to merge 1 commit into
python-poetry:mainfrom
M001N:oss-engine/5fce2d6c-ff49e06e
Open

Fix: GenericEnv.is_venv() in src/poetry/utils/env/generic_env.py compared...#11011
M001N wants to merge 1 commit into
python-poetry:mainfrom
M001N:oss-engine/5fce2d6c-ff49e06e

Conversation

@M001N

@M001N M001N commented Aug 12, 2026

Copy link
Copy Markdown

Summary

Changed is_venv() to resolve both paths before comparing: return self._path.resolve() != self._base.resolve().

Problem

python-poetry/poetry issue reference: #10991

Root Cause

GenericEnv.is_venv() in src/poetry/utils/env/generic_env.py compared self._path and self._base with plain inequality (self._path != self._base) without resolving symlinks/aliases. When a Python version manager exposes the same interpreter via two different filesystem paths (e.g. an unversioned symlink and the concrete versioned directory it points to), the unresolved paths differ even though they refer to the same interpreter, so is_venv() incorrectly returns True. This causes EnvManager.create_venv() to believe Poetry is already running inside an isolated virtualenv and skip creating a project-specific venv.

Testing

PASS - 35 passed, 1 skipped (pre-existing nix-only symlink test skipped on Windows); new test also independently verified to fail on unmodified code and pass with the fix.

Related Issue

#10991

A version manager (e.g. mise) may expose the same interpreter through
two different filesystem paths -- an unversioned symlink and the
concrete fully-versioned install dir it points to. is_venv() compared
self._path and self._base without normalizing such aliases, so it
could incorrectly report True and cause create_venv() to skip
creating a project-specific virtualenv.

Fixes python-poetry#10991

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Using Path.resolve() on every is_venv() call introduces filesystem access and potential exceptions if either path is missing; consider pre-normalizing/caching resolved paths at construction time or handling resolution failures explicitly.
  • The new test reaches into env._path and env._base directly, which couples it to internals; if possible, construct the GenericEnv in a way that reflects realistic initialization while still exercising the aliasing behavior, to avoid future brittleness when internals change.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Using `Path.resolve()` on every `is_venv()` call introduces filesystem access and potential exceptions if either path is missing; consider pre-normalizing/caching resolved paths at construction time or handling resolution failures explicitly.
- The new test reaches into `env._path` and `env._base` directly, which couples it to internals; if possible, construct the `GenericEnv` in a way that reflects realistic initialization while still exercising the aliasing behavior, to avoid future brittleness when internals change.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant