fix(poetry-env): handle Poetry returning "." for venv path #13183
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.
Took me a while to find and reproduce the issue. The fix itself was simple.
I'm not a bot, I only enriched this PR summary with ALL context information.
Standards checklist:
Changes:
Fixed poetry-env plugin failure with in-project virtual environments
poetry env info --path
returns"."
instead of full path whenvirtualenvs.in-project = true
"."
to"$PWD/.venv"
to locate the correct virtual environment directoryactivate
script exists before attempting to source itRoot cause: When Poetry is configured with
virtualenvs.in-project = true
, the commandpoetry env info --path
returns"."
instead of the full path to the virtual environment. This causes the plugin to attempt sourcing"./bin/activate"
which fails with"no such file or directory"
.Solution: Check if the returned path is
"."
and convert it to the proper in-project virtual environment path"$PWD/.venv"
, then verify the activate script exists before sourcing.Comprehensive Issue Analysis:
When This Issue Occurs:
Poetry Version Impact:
"."
(affected by bug)Specific Scenarios That Trigger the Bug:
Documented Poetry
-C
Bug (GitHub Issue #9247)poetry -C <directory>
returns relative paths instead of absoluteBroken/Transitional Virtual Environment States
.venv
directory exists but is incompletepoetry install
)Sophisticated Development Setups
How to Reproduce:
Method 1: Create broken venv state
Method 2: Monorepo + git worktree setup
Error Reproduced:
Why This Fix "Can't Hurt" Even Though It's an Edge Case:
Defensive Programming Benefits:
"."
- a clearly broken stateReal-World Impact:
Maintenance Perspective:
Other comments:
Related PRs:
poetry info --path
cannot find directory '/bin/activate'
because... #12270: Previous attempt usedpoetry shell
instead of fixing the path issue, but was rejected by maintainers for "changing too much the way it works" and "spawning a new shell is not desirable"deactivate
if needed #12701, feat(poetry-env): support changing between two venv dirs #12346, fix(poetry-env): activate only if env exists #12301 - all made incremental improvements to poetry-env pluginWhy This Approach is Better:
poetry info --path
cannot find directory '/bin/activate'
because... #12270, this doesn't change the fundamental mechanismTechnical Details:
This issue commonly affects users who:
virtualenvs.in-project = true
) - a recommended setupTesting:
virtualenvs.in-project = true
) and centralized virtual environmentsPoetry Version Analysis:
While Poetry 2.1.3+ fixes the underlying bug, this defensive programming approach is valuable because:
The fix is minimal, backward-compatible, and follows the existing code style and patterns used in the plugin.