✨ feat(env): add virtualenv_spec for per-env version pinning#3794
Merged
gaborbernat merged 1 commit intotox-dev:mainfrom Feb 20, 2026
Merged
✨ feat(env): add virtualenv_spec for per-env version pinning#3794gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat merged 1 commit intotox-dev:mainfrom
Conversation
9e78de8 to
f6768d5
Compare
No single virtualenv version supports both very old (3.6) and very new (3.15+) Python versions. When the installed virtualenv cannot handle a target Python, the entire environment fails with no workaround. The new `virtualenv_spec` config key (e.g. `virtualenv<20.22.0`) lets users pin a different virtualenv version per environment. When set, tox bootstraps that version into a cached venv under `.virtualenv-bootstrap` and drives it via subprocess instead of the imported library. This keeps the default zero-overhead path for normal usage while enabling mixed old/new Python testing in a single tox config. Closes tox-dev#3656
f6768d5 to
d9bdb5f
Compare
Contributor
|
Thank you. |
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.
No single virtualenv release covers the full range of Python versions that projects need to test against — older versions like
virtualenv<20.22.0are required for Python 3.6, while the latest virtualenv is needed for Python 3.15+. Since tox imports virtualenv as a library, environments targeting unsupported Python versions simply fail with no workaround. ✨ This becomes a real blocker for projects that must maintain compatibility across a wide Python version range in a singletox.toml.The new
virtualenv_specper-environment config key (e.g.virtualenv_spec = "virtualenv<20.22.0") solves this by bootstrapping the specified virtualenv version into a cached venv under.tox/.virtualenv-bootstrap/and driving it via subprocess instead of the imported library. The bootstrap is content-addressed by spec hash, protected by file locks for concurrent safety, and reused across runs. Whenvirtualenv_specis empty (the default), tox continues using the imported virtualenv with zero overhead — the subprocess path only activates when explicitly configured.The
VirtualEnvclass now operates in dual mode: itssessionproperty routes to either the importedsession_via_clior a newSubprocessSessionthat mimics the sameSession/Creator/Describeinterface. Path accessors (bin_dir,purelib,exe, etc.) dispatch throughisinstancechecks so both modes integrate transparently with the rest of the environment lifecycle. Thepython_cache()dict includes the spec string when set, ensuring environments are automatically recreated when the pinned version changes.Closes #3656