I'm trying to write a function which replicates the behaviour of python_requires
from setup.py
, because I failed to find the implementation in the source code of setuptools and pip. Comparing version numbers in Python should be easy enough, I'm using packaging.version which does all the work for me, except...
Let's look at a version string like ">=2.6, !=3.0.*, !=3.1.*"
. I split at every comma, then look at each comparison individually:
from packaging import version
version.parse("3.0.5") >= version.parse("2.6")
Version 3.0.5 is greater than 2.6, as expected. Next:
version.parse("3.0.5") != version.parse("3.0.*")
This returns True (i.e. 3.0.5
is not the same as 3.0.*
), but version 3.0.5
should actually match 3.0.*
. Is there a standard way in Python to check if a version number with wildcards matches another version number?
edit: also related, how would I implement a compatible version matcher, like ~= 3.0.5
, which should match any version >= 3.0.5
but < 3.1.0
?
It looks like I'm trying to implement the version specifiers of PEP 440 here...