✨ feat(config): catalog environments in a PEP 832 .python-envs file - #4013
Draft
gaborbernat wants to merge 1 commit into
Draft
✨ feat(config): catalog environments in a PEP 832 .python-envs file#4013gaborbernat wants to merge 1 commit into
gaborbernat wants to merge 1 commit into
Conversation
Editors have no way to find the environments tox builds under .tox, so using one means copying a path out of tox devenv and pasting it into a settings dialog, again after every recreate. PEP 832 fixes that with a .python-envs file at the project root that any tool can write and any editor can read, with the last line naming the default environment. tox now writes that file at the end of a run. The ordering puts the environment a developer edits code against last: one named dev, then a develop install, then the earlier entries of env_list, so trimming lines from the bottom falls back to the next best choice. Lines outside the work dir belong to another tool and survive untouched, including their claim on the last line. A recreated environment leaves the catalog while it rebuilds so nothing points at a half-built interpreter. Writing into the project root is on by default, since the convention only pays off when tools follow it without being asked; python_envs turns it off.
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.
Nothing tells an editor where tox put its environments. They live under
.tox, a directory no editor searches, so picking one as your interpreter means runningtox devenv, copying the path out of the output, pasting it into a settings dialog, and doing it again after the next recreate. 🔍PEP 832 gives tools a place to publish that answer: a
.python-envsfile at the project root listing one environment directory per line, where the last line names the default. VS Code reads it today. tox now writes it at the end of a run, listing the environments that exist on disk, and orders them by how useful they are to someone editing code: an environment nameddevtakes the last line, then one that installs the project in development mode, then the earlier entries ofenv_list. Trimming lines off the bottom falls back to the next best choice rather than to whatever ran last.Lines pointing outside the work dir came from another tool, so tox leaves them alone, including a claim on the last line. If you or another tool chose the default, tox writes its own block above it. An environment drops out of the catalog while
-rrebuilds it and returns once the run finishes, so nothing sends a reader to a half-built interpreter. A.venvgets no line at all, since PEP 832 already treats it as the implicit final entry.Writing into the project root is on by default, because a discovery convention only pays off when tools follow it without being asked. Set
python_envstofalseto opt out. The docs cover it across all four sections: a step in the tutorial, a recipe for pointing an editor at an environment, the config reference, and the reasoning in the concepts page.