Skip to content

Legacy versions aren't in SpecifierSets if the specifier is PEP 440-compatible #74

@jimporter

Description

@jimporter

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:

  1. Write a new version parsing package that doesn't try to enforce PEP 440.
  2. 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.
  3. Figure out a way to make Versions and LegacyVersions more compatible so that LegacyVersions don't always count as older.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions