fix(venv): a ~ in venv.location hides every created virtualenv - #3847
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3847 +/- ##
=======================================
Coverage 88.36% 88.37%
=======================================
Files 121 121
Lines 13249 13251 +2
Branches 2251 2251
=======================================
+ Hits 11708 11710 +2
Misses 969 969
Partials 572 572
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
frostming
approved these changes
Aug 17, 2026
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.
A
~invenv.locationis expanded when a virtualenv is created but not whenone is looked up, so every
pdm venvsubcommand reports nothing after asuccessful create.
With
venv.location = ~/my-venvs:list,remove,activate,purgeandpdm venv --pathare all affected. Thevenv exists and works, it is simply invisible to pdm.
Cause
Backend.get_locationexpands the path:but the two iterators do not:
So the venv is created under
/home/me/my-venvsand then looked for under adirectory literally named
~, which is also why a stray~/directory appearsin the working directory.
The fix
One
get_venv_parent(project)helper doing the expansion, used byget_location,iter_venvsanditer_central_venvs, so the three cannot driftapart again.
Verification
test_venv_list_with_tilde_locationsets a~location against a fake home,creates a venv and checks
pdm venv listfinds it.Removing the expansion from the helper fails it, and the failure names the
symptom exactly:
tests/cli/test_venv.pyis 36 passed. On the wider suite the baseline is 1346passed on a stashed tree and 1347 with this change, no failures either way.
Two tests are excluded from that count because they fail identically on an
unmodified tree here:
test_create_venv_in_project[venv-True](this sandbox'spython -m venv --promptexits non-zero) and the OIDC tests intests/cli/test_publish.py, which needpytest-httpx.ruff checkandruff format --checkare clean.Pull Request Checklist
news/describing what is new.Disclosure: written with AI assistance (Claude Code). I produced the before and after by running the real
pdm venvcommands against a~location, and ran the mutation check and the suite baseline myself.