Skip to content
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

Local version labels in version specifiers #661

Closed
edible-programs opened this issue Jan 14, 2023 · 3 comments
Closed

Local version labels in version specifiers #661

edible-programs opened this issue Jan 14, 2023 · 3 comments

Comments

@edible-programs
Copy link

from packaging import requirements
requirements.parse_requirement("torch>=1.13.1+cu117")
# Expected end or semicolon (after version specifier)
@pradyunsg pradyunsg changed the title [BUG] local version labels not parsed correctly from parse_requirement Local version labels not parsed correctly by parse_requirement Jan 14, 2023
@pradyunsg
Copy link
Member

pradyunsg commented Jan 14, 2023

Argh, parse_requirement isn't supposed to be a public function.

Beyond that, >=1.13.1+cu117 isn't a valid version specifier per the existing language of PEP 508 and PEP 440. You can also see that this was being parsed as a LegacySpecifier within older versions of packaging (with 21.3 below).

>>> # packaging 21.3
>>> from packaging.requirements import Requirement
>>> list(Requirement("torch>=1.13.1+cu117").specifier)
[<LegacySpecifier('>=1.13.1+cu117')>]

It does have reasonable semantics if you expect to have a monotonically increasing number (although it'd work better with a . between cu and the number).

>>> # packaging 21.3
>>> Requirement("torch>=1.13.1+cu117").specifier.contains(Version("1.13.1+cu117"))
True
>>> Requirement("torch>=1.13.1+cu117").specifier.contains(Version("1.13.1+cu116"))
False
>>> Requirement("torch>=1.13.1+cu117").specifier.contains(Version("1.13.1+cu118"))
True

It does seem like a valid version specifier and a valid usecase but, as it stands, PEP 508 and PEP 440 don't permit using local version labels in version specifiers. This works in pip and packaging 21.3 for the same reasons that the following "works":

>>> # packaging 21.3
>>> list(Requirement("torch>=absolutelyanythinghere").specifier)
[<LegacySpecifier('>=absolutelyanythinghere')>]

@pradyunsg pradyunsg changed the title Local version labels not parsed correctly by parse_requirement Local version labels in version specifiers Jan 14, 2023
@pradyunsg
Copy link
Member

pradyunsg commented Jan 14, 2023

@pradyunsg
Copy link
Member

We’ve settled on no for this. See the discussion above for the details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants