Skip to content

Strip the free-threaded suffix before handing a version to uv - #2403

Open
SirHegel wants to merge 1 commit into
pypa:masterfrom
SirHegel:strip-freethreaded-suffix-for-uv
Open

Strip the free-threaded suffix before handing a version to uv#2403
SirHegel wants to merge 1 commit into
pypa:masterfrom
SirHegel:strip-freethreaded-suffix-for-uv

Conversation

@SirHegel

Copy link
Copy Markdown

Fixes #2393.

Both places that build a uv command pass the environment's python setting straight to --python-version:

  • src/hatch/env/lockers/uv.py (uv pip compile)
  • src/hatch/env/virtual.py (uv pip sync)

uv resolves for a version, not for a build, so a free-threaded selector is not something it can parse:

$ uv pip compile pyproject.toml --python-version 3.14t
error: invalid value '3.14t' for '--python-version <PYTHON_VERSION>': Python version `3.14t`
could not be parsed: after parsing `3.14`, found `t`, which is not part of a valid version

hatch-test lists 3.14t in its default matrix (src/hatch/env/internal/test.py), so this is hit without any custom configuration.

The change

Run the value through normalize_distribution_name first. It is already used for exactly this in virtual.py::_get_available_distribution, and it only drops the suffix when the base version really has a free-threaded variant:

setting passed to uv
3.14t 3.14
3.13t 3.13
3.14 3.14
3.9t 3.9t — 3.9 has no free-threaded build, left alone
pypy3.10 pypy3.10

Checked against uv 0.12.5: --python-version 3.14 compiles, 3.14t is the error above.

Tests

I did not add one. There is no existing harness for these two command builders — nothing in tests/ constructs a VirtualEnvironment or calls UVLocker._compile — and normalize_distribution_name is the tested part. Happy to add coverage if you would like it, but I did not want to stand up a fixture for it uninvited.

tests/env reports the same 187 collection errors before and after this change on my machine, so I could not use it as a signal either way; they look like a missing environment variable in my local setup rather than anything from this.

Both places that build a uv command pass the environment's python setting
straight to --python-version. uv resolves for a version rather than for a
build, so a free-threaded selector is not something it can parse:

    error: invalid value '3.14t' for '--python-version': Python version
    `3.14t` could not be parsed: after parsing `3.14`, found `t`

hatch-test lists 3.14t in its default matrix, so hatch env lock fails out
of the box.

Run the value through normalize_distribution_name first, which is already
used for the same purpose in virtual.py. It only drops the suffix when
the base version actually has a free-threaded variant, so 3.9t, pypy3.10
and a plain 3.14 are all left alone.

Fixes pypa#2393.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wrongly passes build variant to uv's --python-version

1 participant