Repository navigation
Description
The tests job declares a nine-way matrix over Python 3.11, 3.12 and 3.13, but every leg runs on 3.13. The uv sync step honors the matrix, and then the first bare uv run step discards the environment it has just created and rebuilds it on 3.13, so codespell, ruff, pyright, pytest and uv build all run on the same interpreter whichever leg they are on.
From the "Python 3.11 on ubuntu-latest" job of the most recent run of the workflow:
Using CPython 3.11.16
Creating virtual environment at: .venv
Installed 29 packages in 145ms
Using CPython 3.13.15
Removed virtual environment at: .venv
Creating virtual environment at: .venv
Installed 29 packages in 119ms
platform linux -- Python 3.13.15, pytest-9.1.1, pluggy-1.6.0
https://github.com/harp-tech/python/actions/runs/33352529214/job/99368513652
Cause
--python on the sync step applies to that invocation alone and is not recorded as a project preference. The next uv run resolves an interpreter again, reads .python-version and takes the first entry, 3.13. The existing environment no longer matches that request, so uv removes and recreates it.
Reproduced outside CI on uv 0.11.2, with a minimal project carrying the same three-line file:
uv sync --python 3.11 -> Using CPython 3.11.14
uv run python -V -> Using CPython 3.13.9
Removed virtual environment at: .venv
Creating virtual environment at: .venv
Python 3.13.9
With the file absent the same sequence stays on 3.11, so this is the file taking precedence rather than a defect in uv run.
Suggested fix
Set UV_PYTHON on the job, so every step in it resolves to the matrix version:
tests:
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
UV_PYTHON: ${{ matrix.python-version }}
UV_PYTHON takes precedence over .python-version, verified against the same reproduction. It also covers any step added later, where --python covers only the step that carries it, so the flag on the sync step becomes redundant and can be removed.
The extra entries in .python-version have no effect
Worth raising alongside, since it affects what the file should look like once the matrix is fixed. uv reads only the first entry when selecting a version and does not fall back to later ones. With requires-python = ">=3.12" and a file listing 3.11 then 3.13:
Using CPython 3.11.14
error: The Python request from `.python-version` resolved to Python 3.11.14, which is
incompatible with the project's Python requirement: `>=3.12`
It took line 1, found it incompatible and stopped rather than trying line 2. So 3.12 and 3.11 are invisible to uv sync, uv run and uv venv. uv sync already downloads a missing interpreter by itself, so there is no need for the extra entries.
Activity