🐛 fix(venv): resolve Python spec from env name when tox passes fallback path#308
Merged
gaborbernat merged 1 commit intotox-dev:mainfrom Mar 10, 2026
Merged
🐛 fix(venv): resolve Python spec from env name when tox passes fallback path#308gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat merged 1 commit intotox-dev:mainfrom
Conversation
887094e to
339a9e7
Compare
Tox 4.47.1+ extracts base_python from version factors in env names (PR #3846). When the requested Python doesn't exist (e.g. 9.99), tox passes a fallback interpreter path to _get_python(). The old code used this fallback path's Python info, losing the original version spec. This caused test_uv_venv_spec_full_implementation to fail because uv was invoked with the fallback Python version instead of the requested 9.99. The fix: when _get_python() receives an absolute path, parse the env name (self.name) as a PythonSpec first. If it contains version info, use that spec. Otherwise fall back to probing the absolute path. This preserves the user's intent from the env name while handling cases like 'demo' that have no version info. Also simplified env_version_spec() by removing the executable and sys.executable shortcircuits that are no longer needed with this approach.
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.
Tox 4.47.1 changed how
base_pythonis extracted from environment names (PR #3846). When parsing multi-factor env names like3.10-tests, it now checks each factor against version patterns. 🔍 If the requested Python doesn't exist, tox passes a fallback interpreter's absolute path to_get_python()instead of a version spec.The previous code used this fallback path directly in
env_version_spec(), losing the original version specification from the environment name. When tests requested Python 9.99 to validate spec generation, uv received/usr/bin/python3.14instead ofcpython9.99, causing failures.The fix separates version-aware environments from generic ones. When
_get_python()receives an absolute path, it parses the environment name (self.name) as aPythonSpec. ✨ If the name contains version info, that spec is used. If not (like env namepy), the absolute path is probed and stored inPythonInfo.extra["executable"]for environments that need a specific interpreter.This preserves the user's intent from the environment name while handling both lock runner workflows (which need absolute paths for generic envs) and regular workflows (which need version specs for versioned envs).