Skip to content

✨ feat(create): record created environments per PEP 832 - #3204

Draft
gaborbernat wants to merge 1 commit into
pypa:mainfrom
gaborbernat:832
Draft

✨ feat(create): record created environments per PEP 832#3204
gaborbernat wants to merge 1 commit into
pypa:mainfrom
gaborbernat:832

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Editors and type checkers have no standard way to find a project's environments without an activated shell, so each one hard-codes a search per tool that creates environments. PEP 832 addresses that with a .python-envs file listing one environment per line, where the last line names the default environment and a .venv folder alongside counts as the implicit last line.

virtualenv creates environments, so this covers the write half. After creation it records the destination in the .python-envs file of the parent folder and moves any existing entry for it to the end, making the fresh environment the default. It leaves a destination named .venv alone, since the PEP treats it as the implicit last line. A read or write failure warns and leaves the environment usable. Pass --no-python-envs to opt out.

Rewriting the whole file loses entries when several environments land in one folder at once. Eight concurrent creations dropped between one and four of them on every attempt, so the read-modify-write runs under a .python-envs.lock file next to the recorded one. 🔒 Locking beside the resource rather than inside the app data folder holds the guarantee when the app data is read-only or disabled, and gives any other PEP 832 writer a location to agree on.

Editors and type checkers have no standard way to find a project's
environments without an activated shell, so each one hard-codes a search
per tool that creates environments. PEP 832 replaces that with a
.python-envs file whose last line names the default environment.

virtualenv creates environments, so it covers the write half. After
creation it records the destination in the .python-envs file of the
parent folder and moves any existing entry for it to the end, making the
fresh environment the default. A destination named .venv is left alone,
since the PEP counts it as the implicit last line. A read or write
failure warns and leaves the environment usable. Pass --no-python-envs
to opt out.

Recording rewrites the whole file, which loses entries when several
environments land in one folder at once: eight concurrent creations
dropped between one and four of them on every attempt. The
read-modify-write therefore runs under a .python-envs.lock file next to
the recorded one. Locking beside the resource rather than inside the app
data folder holds the guarantee when the app data is read-only or
disabled, and gives any other PEP 832 writer a location to agree on.

Documented across all four Diataxis dimensions, including a new
reference page cataloguing every file virtualenv writes inside and
beside an environment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant