strip trailing +
from version number of local Python builds
#1771
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.
(This PR message is mostly copied from the comment in the code.)
For local builds of Python, at time of writing, the version numbers end with
a
+
. This makes the version non-PEP-440 compatible since a+
indicatesthe start of a local segment which must be non-empty. Thus,
uv
chokes on itand spits out an error when trying to create a venv using a "local" build
of Python. Arguably, the right fix for this is for CPython to use a PEP-440
compatible version number.
However, as a work-around for now, as suggested by pradyunsg as one
possible direction forward, we strip the
+
.This fix does unfortunately mean that one cannot specify a Python version
constraint that specifically selects a local version. But at the time of
writing, it seems reasonable to block such functionality on this being fixed
upstream (in some way).
Another alternative would be to treat such invalid versions as strings (which
is what PEP-508 suggests), but this leads to undesirable behavior in this
case. For example, let's say you have a Python constraint of
>=3.9.1
anda local build of Python with a version
3.11.1+
. Using string comparisonswould mean the constraint wouldn't be satisfied:
So in the end, we just strip the trailing
+
, as was done in the days of oldfor legacy version numbers.
I tested this fix by manually confirming that
failed before it and succeeded after it.
Fixes #1357