summaryrefslogtreecommitdiff
path: root/pkg_resources
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-11-15 17:41:14 -0500
committerJason R. Coombs <jaraco@jaraco.com>2021-11-15 17:41:14 -0500
commit47b9bf5e5f75cadf20fc1eedbd26e1945a3be0cc (patch)
tree9dab32319035b152520b16b9c539c08e4dfd3ae3 /pkg_resources
parent0ec5f0917fb659ae636d62a182883b45de167870 (diff)
downloadpython-setuptools-git-47b9bf5e5f75cadf20fc1eedbd26e1945a3be0cc.tar.gz
Fix sorting of filenames not to rely on LegacyVersion. Fixes #2885.
Diffstat (limited to 'pkg_resources')
-rw-r--r--pkg_resources/__init__.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index 4aece3c4..c615bc09 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -2015,7 +2015,7 @@ def _by_version_descending(names):
>>> names = 'bar', 'foo', 'Python-2.7.10.egg', 'Python-2.7.2.egg'
>>> _by_version_descending(names)
- ['Python-2.7.10.egg', 'Python-2.7.2.egg', 'foo', 'bar']
+ ['Python-2.7.10.egg', 'Python-2.7.2.egg', 'bar', 'foo']
>>> names = 'Setuptools-1.2.3b1.egg', 'Setuptools-1.2.3.egg'
>>> _by_version_descending(names)
['Setuptools-1.2.3.egg', 'Setuptools-1.2.3b1.egg']
@@ -2023,13 +2023,22 @@ def _by_version_descending(names):
>>> _by_version_descending(names)
['Setuptools-1.2.3.post1.egg', 'Setuptools-1.2.3b1.egg']
"""
+ def try_parse(name):
+ """
+ Attempt to parse as a version or return a null version.
+ """
+ try:
+ return packaging.version.Version(name)
+ except Exception:
+ return packaging.version.Version('0')
+
def _by_version(name):
"""
Parse each component of the filename
"""
name, ext = os.path.splitext(name)
parts = itertools.chain(name.split('-'), [ext])
- return [packaging.version.parse(part) for part in parts]
+ return [try_parse(part) for part in parts]
return sorted(names, key=_by_version, reverse=True)