astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
21.75k stars 636 forks source link

requires-python specification not correctly resolved #7862

Open Wietse opened 17 hours ago

Wietse commented 17 hours ago

Hello,

I'm having a problem specifying requires-python.

My environment: MacOS M1 uv 0.4.16 (e81ed8ec5 2024-09-24) python 3.12.6 (pyenv)

To reproduce:

uv init test-requires-python --lib --python 3.12.6 --python-preference only-system
cd test-requires-python
python -m venv .venv
. ./.venv/bin/activate

Open pyproject.toml and update the value for requires-python:

requires-python = ">=3.8,<3.13,!=3.9.7"

Next:

uv lock

This gives an error:

Using CPython 3.12.6
error: The Python request from `.python-version` resolved to Python 3.12.6, which is incompatible with the project's Python requirement: `>=3.8, <3.9.7, >3.9.7, <3.13`. However, a workspace member (`test-requires-python`) supports Python >=3.8, !=3.9.7, <3.13. To install the workspace member on its own, navigate to ``, then run `uv venv --python 3.12.6` followed by `uv pip install -e .`.

I would expect the version 3.12.6 to be according to the constraints. See https://packaging.python.org/en/latest/specifications/version-specifiers/#id5 which states:

The comma (“,”) is equivalent to a logical and operator: a candidate version must match all given version clauses in order to match the specifier as a whole.

But it seems that uv transforms >=3.8,<3.13,!=3.9.7 to >=3.8, <3.9.7, >3.9.7, <3.13, which is not what is intended. OTOH, in a different code path, uv does recognize that 3.12.6 is within the constraint of >=3.8, !=3.9.7, <3.13

Thanks for a great tool! Wietse

Wietse commented 16 hours ago

I've upgraded uv to the latest uv 0.4.18 (7b55e9790 2024-10-01), but the problem still exists.

zanieb commented 12 hours ago

This looks like a weird bug, thanks for the report.