-
Notifications
You must be signed in to change notification settings - Fork 272
Closed
Labels
Description
Suppose you have a version and a specifier, both as strings. The version is not PEP 440-compatible, but the specifier is. Creating version/specifier objects for each results in the version never meeting specifier:
>>> from packaging import version, specifiers
>>> v = version.parse('1.2.3.goofy')
>>> v
<LegacyVersion('1.2.3.goofy')>
>>> spec = specifiers.SpecifierSet('>=1.2')
>>> spec
<SpecifierSet('>=1.2')>
>>> v in spec
False
Presumably, this is because LegacyVersion
s "will always sort as less than a Version
instance."
While some people can just switch to PEP 440-compatible versions, not everyone can. In particular, I'm using this to parse non-Python versions for some tools. I could write my own code for this, but since I already need the packaging
package for other stuff, I figured I should just use what already exists.
For my particular issue, I can think of the following solutions:
- Write a new version parsing package that doesn't try to enforce PEP 440.
- Add a
legacy=False
argument toSpecifierSet
that will force all the specifiers it creates to beLegacySpecifier
s. That way, if you know you need to handle legacy versions, you can enable it. - Figure out a way to make
Version
s andLegacyVersion
s more compatible so thatLegacyVersion
s don't always count as older.
Thoughts?