Skip to content

.python-version is not necessarily a version specifier (per PEP 440) and thus cannot necessarily be used for environment.python.requires #659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Lytol opened this issue Apr 24, 2025 · 2 comments · Fixed by #662
Assignees
Labels
bug Something isn't working

Comments

@Lytol
Copy link
Contributor

Lytol commented Apr 24, 2025

Per PEP 440, a version specifier must contain a comparison operator (i.e. >, ==, etc). Connect expects a PEP-440 compliant version specifier for the environment.python.requires manifest property.

A few options that I see:

  1. Ensure that .python-version is a valid version specifier; otherwise, skip.
  2. Modify the version that we get from .python-version to make it a compliant version specifier (i.e. prepend ==)
  3. Do not use .python-version at all 🤷

I'm fine with any of these, but here's my 2 cents:

Given that .python-version appears to be pretty bespoke for uv and can contain a wide variety of non-version-specifier values (see https://docs.astral.sh/uv/concepts/python-versions/#requesting-a-version), then I'd vote to drop the precedence of .python-version below pyproject.toml and setup.cfg, and then (1) skip if not a valid version specifier.

@amol- What do you think?

@amol-
Copy link
Contributor

amol- commented Apr 25, 2025

According to PEP440 version specification 3.12 would mean 3.12.0 as version numbers are 0 padded.
But that's not the behaviour you get in UV, as uv will use any available patch version.

As the presence of a .python-version file means the user is managing the application environment via uv, I would suggest we replicate uv behaviour. So we should intend 3.12 as ==3.12.*.

When parsing .python-version should check if it's a valid version specifier ( https://packaging.python.org/en/latest/specifications/version-specifiers/#id5 ) and if none of the comparison operators is specified ( ~=, ==, !=, <=, >=, <, >) it should prefix it with ~= as it's the operator that matches default uv behaviour.

Thus a file like

3.12

would result in python.environment.requires = "~=3.12" leading to the same behaviour you would get locally with uv and any available version of python 3.12 being used.

Regarding the fact that in uv you can specify a python implementation, I don't think I have ever seen that used outside of very specific and highly vertical contexts where for example pypy is required. So for those we can probably just error and say that connect doesn't currently handle those. There wouldn't be a way to request pypy anyway in connect, so we aren't removing any feature.

@Lytol
Copy link
Contributor Author

Lytol commented Apr 25, 2025

Agreed with your conclusions @amol-, thanks much!

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 a pull request may close this issue.

2 participants