Skip to content

🐛 fix(venv): resolve Python spec from env name when tox passes fallback path#308

Merged
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:main
Mar 10, 2026
Merged

🐛 fix(venv): resolve Python spec from env name when tox passes fallback path#308
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:main

Conversation

@gaborbernat
Copy link
Member

@gaborbernat gaborbernat commented Mar 9, 2026

Tox 4.47.1 changed how base_python is extracted from environment names (PR #3846). When parsing multi-factor env names like 3.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.14 instead of cpython9.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 a PythonSpec. ✨ If the name contains version info, that spec is used. If not (like env name py), the absolute path is probed and stored in PythonInfo.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).

@gaborbernat gaborbernat added the bug Something isn't working label Mar 9, 2026
@gaborbernat gaborbernat marked this pull request as draft March 9, 2026 23:54
@gaborbernat gaborbernat force-pushed the main branch 5 times, most recently from 887094e to 339a9e7 Compare March 10, 2026 03:31
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.
@gaborbernat gaborbernat changed the title 🐛 fix(venv): pass implementation spec to uv instead of executable path 🐛 fix(venv): resolve Python spec from env name when tox passes fallback path Mar 10, 2026
@gaborbernat gaborbernat marked this pull request as ready for review March 10, 2026 03:45
@gaborbernat gaborbernat merged commit 906a243 into tox-dev:main Mar 10, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant