-
Notifications
You must be signed in to change notification settings - Fork 251
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
Unexpected handling of versions with "local" components by pip #275
Comments
This seems like a bug in from packaging import version
from packaging.specifiers import SpecifierSet
version.parse('1.10.9') in SpecifierSet('>=1!1.10.7+local.6') # True
# Interestingly though, Version itself gets it right.
version.parse('1.10.9') >= version.parse('1!1.10.7+local.6') # False |
Hmm, I think the problem is not about epoch, but the local version identifier ( >>> version.parse('1.10.9') in specifiers.Specifier('>=1!1.10.7')
False I found this paragraph in PEP 440:
And indeed, >>> specifiers.Specifier('>=1!1.10.7+local.6')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "packaging/specifiers.py", line 111, in __init__
raise InvalidSpecifier("Invalid specifier: '{0}'".format(spec))
packaging.specifiers.InvalidSpecifier: Invalid specifier: '>=1!1.10.7+local.6'
>>> list(specifiers.SpecifierSet('>=1!1.10.7+local.6'))
[<LegacySpecifier('>=1!1.10.7+local.6')>] The confusing part is that '1.10.9' >= '1!1.10.7+local.6' which would return True because I’m not sure what the best resolution is here. We already promised to maintain the possibility to compare arbitrary strings, and can’t outright reject |
Ohhh - I hit all the edge cases there :) I didn't read the full spec (clearly), but I assumed that it would only fallback to a string compare on the local part, not the full version specifier. Hmm. |
I read this bit of the spec about local releases:
And went "this is exactly what I'm doing"! The spec says and then this a few paragraphs later:
That bit about "Comparison and ordering of local versions" seems entirely pointless if the non-strict ordering comparisons (compatible, inclusive and exclusive ordered comparison) say local versions aren't permitted -- leaving only Sounds like a bug in the spec?, as disallowing local versions means that the structure of the local version is never checked. |
I did all my testing of this with packaging.version, which is why I thought the bug was around epochs:
Which from the section about local versions was how I expected pip to behave too |
And packaging.version does more than a string compare of local version parts:
|
I think the implication is that you can release multiple local versions, but you can’t make that show in the specifier. So you are allowed to release multiple local versions, and they are ordered (so |
Note: This thread probably should be moved to either pypa/packaging or pypa/packaging-problems to make it more visible for people more familiar with the spec. /cc @pradyunsg |
Taking a customary skim through this, ISTM that this is indeed a case of hitting a whole bunch of edge cases. :) It'll probably take a bit more time to understand the nuances than I have right now. For now, I've transferred this to pypa/packaging. |
I think the quick summary is: Pip follows the PEP-440 spec as defined around local version comopnents, but I (naievly) assumed it would follow what ever packaging.version did with it's ordering/comparison of Version objects (and I checked they were "valid", not LegacyVersion after parsing) |
If pip's (and therefore packaging's) behaviour is consistent with pep 440, I don't think there's anything actionable here. |
I'd like the PEP to be changed/relaxed if possible! It makes local versions much much harder to use, and makes them behave very differently to debian etc. I'd like the spec to treat local versions how ever Edit: at least for |
@ashb I see -- in that case, consider clearly articulating why (and possibly how) the behavior should change at https://discuss.python.org/c/packaging, to make a case for changing the behavior. Updates to such standards need a discussion for concensus-building (which may, or may not, be trivial) that there's a problem and then, how we want to solve it. :) |
Closing since #321 is the approach we've taken here. |
Environment
Description
I am investigating using version epochs for a local/private "fork" of a project, and want to push out updates without accidental upgrading to the upstream version.
So I have specified my requirement as
apache-airflow>=1!1.10.7+local.6
, and since there is an epoch in there (1!
prefix) I should expect that to fail. As per PEP-440 Summary of permitted suffixes and relative orderingHowever it appears that the implicit epoch is being treated as 1.
If I change the explicit epoch I required to
2!
then it works as expected:(Yes I acknowledge I am abusing version epochs for this purpose, but this behaviour is still against what the spec says)
The text was updated successfully, but these errors were encountered: