-
Notifications
You must be signed in to change notification settings - Fork 256
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
parse(">3.6") >= parse(">=3") is False #591
Comments
Testing straight against the
This will be interesting to witness on the pypi.org packaging system. Programmatically I get that you can do |
You want to use specifier set instead of version, for parsing this form. |
They are not comparable tho. SpecifierSet('>=3.6') >= SpecifierSet('>=3')
TypeError: '>=' not supported between instances of 'SpecifierSet' and 'SpecifierSet' And sure, you could use I'll add to this problem of comparing, that it doesn't support
Which would have solved this use case as I could do |
I don’t think comparison between SpecifierSet instances makes sense. Set operations may make sense (it needs to return something else e.g. SpecifierSetCollection because it’s impossible to serialise |
My case that I'd like to argue here, is that the And I would assume that comparing equal objects is within the scope, given that they follow the right format I'm getting the impression that I'm wild and crazy for suggestion this to be sane: SpecifierSet('>=3.6') >= SpecifierSet('>=3') How would people generally compare two version statements? Just to clarify, I get that this is a "workaround" to the above statement. SpecifierSet('>=3.6').contains("3.10") But it's also not the same. As you would have to iterate every version aspect imagined within |
What are you trying to do? Why do you want to compare these strings and what is your expectation for how the comparison would work? |
I'm comparing a supported version of python defined by the operating system which happens to be The second use case is that of using it for general package management in the operating system I'm using. tl;dr: Take package cms-figure for instance, it defines My expectation is as I stated in my first post: VersionParser('>=3.6') > VersionParser('>=3') # == True And not what's currently happening, which is incorrect since VersionParser('>3.6') > VersionParser('>=3') # == False As described above by others. This only works on the current stable release, on future versions this will fail and you need to use |
None of these are versions; they are version constraints. The only reason this doesn't raise is that the version's being parsed as a |
No. Partially yes but strictly no.
Yes, as the comparison is if any version above 3.6 is greater than any version above 3.
Sure, but constraints or versions - I'd still expect to be able to compare equal object types in this instance. (I'd also expect |
All numbers greater than 3.6 are greater than 3. But greater than 3.6 is not greater than greater than 3; ⊃ does not mean > unless you define the ordering of sets in such terms.
It does work. |
Apologies, it didn't work earlier on two other machines. Works locally on a third and I'm not sure what the difference is at this moment but earlier it required a |
It's an interesting idea but set operations for version specifiers are not formalised. Your best bet's simply to take a min version and a max version as input instead of a version specifier. |
I understand the desire behind the feature request, but Python packaging has a separate concept for determining whether a specific version ( |
@brettcannon sorry for the late answer, but I've been trying to twist and turn on your claim that there is a separate concept implying a solution to this problem. Specifically the statement:
As you did not point to a specific solution, some attempts: >>> packaging.specifiers.Specifier('>=3').contains('>3.6')
False >>> list(packaging.specifiers.Specifier('>=3').filter(['>3.6']))
[] There doesn't seem to be support for ranges anywhere on these objects you propose. Or if All the tests I could find: packaging/tests/test_specifiers.py Lines 330 to 336 in e184fee
Are done on a fixed I think I've wasted a great deal of time trying to investigate the current concept by thinking there was a solution. Would a PR be welcome to introduce the |
Ah, this is the stupidness1 thanks to legacy version: >>> from packaging.version import *
>>> Version(">3.6")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/pradyunsg/Developer/github/pip/.venv/lib/python3.10/site-packages/packaging/version.py", line 266, in __init__
raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: '>3.6'
>>> parse(">3.6")
<LegacyVersion('>3.6')> That's been removed in #530, so the behaviour on >>> from packaging.version import *
>>> parse(">3.6")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/pradyunsg/Developer/github/packaging/packaging/version.py", line 52, in parse
return Version(version)
File "/Users/pradyunsg/Developer/github/packaging/packaging/version.py", line 197, in __init__
raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: '>3.6' Adding an example from what you tried: >>> import packaging.specifiers
>>> packaging.specifiers.Specifier('>=3').contains('>3.6')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/pradyunsg/Developer/github/packaging/packaging/specifiers.py", line 552, in contains
normalized_item = _coerce_version(item)
File "/Users/pradyunsg/Developer/github/packaging/packaging/specifiers.py", line 25, in _coerce_version
version = Version(version)
File "/Users/pradyunsg/Developer/github/packaging/packaging/version.py", line 197, in __init__
raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: '>3.6' Footnotes
|
Correct. My comment was strictly addressing the fact you can't compare versions like you were trying and that we just have a concept of whether a version fits into a specifier(s), not that there was some solution to ranges. Sorry if that's the impression you got.
I personally don't see enough of a need for this functionality for such a thing to live in this package. We purposefully try to keep this project small as it's just two of us maintaining it and it's trying to cover all the low-level packaging standards. Since this isn't necessary for e.g. pip to determine whether it can install something, I think it's a better fit for some other project. |
I would kindly suggest not to encourage contributions if the contribution isn't actually worthwhile.
Unless you meant another project within PyPi, in which case perhaps point towards what project would welcome it. In any case, I still believe versioning ranges should be allowed as a comparison. Maybe not for I don't expect anyone else to implement complex version checks in their specific applications when it's tied to the chosen data structure by PyPi, much like I wouldn't expect anyone to implement version check for pacman (ArchLinux Package Manager) when there's libalpm. With that said, not all features have to be accepted and implemented. It's entirely up to you the maintainers. If you feel this strongly about it I'm happy to let it go. But know that it would have helped to offload pypi.org in a sense and the desire to have it (although not among the masses) is still there :) |
Yes, I meant another project on PyPI. If I had wanted to suggest we would consider the functionality I would have said something like, "please submit a PR and we will be happy to review/consider it" or something like that where I reference us as a project.
I honestly have no idea as there isn't any "higher-level utility library for packaging-related things" project that I'm aware of; most projects at that level of end-user tools and have code to meet their own needs. I personally would consider creating your own project for this. |
I'm wondering if my assumptions are wrong here, or if this is unintentional behavior?
I would assume that anything greater than
3.6
is also greater than3
.But in this case the result will be
False
followed byTrue
if I instead use>=
.But if you're parsing other peoples packages, from pypi.org for instance you're not really in a position to alter from
>
to>=
.Hope the example is clear and maybe it's just my assumption that's off.
The text was updated successfully, but these errors were encountered: