Skip to content

Commit

Permalink
Avoid using LegacyVersion from packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
Chih-Hsuan Yen committed Dec 10, 2020
1 parent b6bbe23 commit 2cfb491
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,17 @@ def _by_version(name):
"""
name, ext = os.path.splitext(name)
parts = itertools.chain(name.split('-'), [ext])
return [packaging.version.parse(part) for part in parts]

def parse_version_ignore_invalid(version):
try:
return packaging.version.Version(version)
except packaging.version.InvalidVersion:
# Per PEP 440, version strings are compared in a
# case-insensitive manner. Do the same for
# non-version strings.
return version.lower()

return [parse_version_ignore_invalid(part) for part in parts]

return sorted(names, key=_by_version, reverse=True)

Expand Down

0 comments on commit 2cfb491

Please sign in to comment.