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 LegacyVersions "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 to SpecifierSet that will force all the specifiers it creates to be LegacySpecifiers. That way, if you know you need to handle legacy versions, you can enable it.
- Figure out a way to make
Versions and LegacyVersions more compatible so that LegacyVersions don't always count as older.
Thoughts?
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:
Presumably, this is because
LegacyVersions "will always sort as less than aVersioninstance."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
packagingpackage for other stuff, I figured I should just use what already exists.For my particular issue, I can think of the following solutions:
legacy=Falseargument toSpecifierSetthat will force all the specifiers it creates to beLegacySpecifiers. That way, if you know you need to handle legacy versions, you can enable it.Versions andLegacyVersions more compatible so thatLegacyVersions don't always count as older.Thoughts?