From: JinWang An Date: Mon, 27 Mar 2023 08:02:38 +0000 (+0900) Subject: Imported Upstream version 59.1.1 X-Git-Tag: upstream/59.1.1^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=09301175112052050008a3054b2a6e3611765346;p=platform%2Fupstream%2Fpython-setuptools.git Imported Upstream version 59.1.1 --- diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 03facc2..c7a9e9c 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 59.1.0 +current_version = 59.1.1 commit = True tag = True diff --git a/CHANGES.rst b/CHANGES.rst index 73f243c..b87e436 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,12 @@ +v59.1.1 +------- + + +Misc +^^^^ +* #2885: Fixed errors when encountering LegacyVersions. + + v59.1.0 ------- diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 4aece3c..c615bc0 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) diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 965a7c0..107dda7 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -703,7 +703,7 @@ class TestParsing: ) def test_local_version(self): - req, = parse_requirements('foo==1.0.org1') + req, = parse_requirements('foo==1.0+org1') def test_spaces_between_multiple_versions(self): req, = parse_requirements('foo>=1.0, <3') diff --git a/pytest.ini b/pytest.ini index 975baf6..8cc1052 100644 --- a/pytest.ini +++ b/pytest.ini @@ -34,7 +34,6 @@ filterwarnings= # https://github.com/pypa/setuptools/issues/2497 ignore:.* is an invalid version and will not be supported::pkg_resources - ignore:Creating a LegacyVersion has been deprecated # https://github.com/pypa/setuptools/pull/2865#issuecomment-965700112 # ideally would apply to Python 3.10+ when diff --git a/setup.cfg b/setup.cfg index cb7281e..30f06b8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = setuptools -version = 59.1.0 +version = 59.1.1 author = Python Packaging Authority author_email = distutils-sig@python.org description = Easily download, build, install, upgrade, and uninstall Python packages diff --git a/setuptools/config.py b/setuptools/config.py index e3e44c2..b4e968e 100644 --- a/setuptools/config.py +++ b/setuptools/config.py @@ -13,7 +13,7 @@ from glob import iglob import contextlib from distutils.errors import DistutilsOptionError, DistutilsFileError -from setuptools.extern.packaging.version import LegacyVersion, parse +from setuptools.extern.packaging.version import Version, InvalidVersion from setuptools.extern.packaging.specifiers import SpecifierSet @@ -585,7 +585,9 @@ class ConfigMetadataHandler(ConfigHandler): version = version.strip() # Be strict about versions loaded from file because it's easy to # accidentally include newlines and other unintended content - if isinstance(parse(version), LegacyVersion): + try: + Version(version) + except InvalidVersion: tmpl = ( 'Version loaded from {value} does not ' 'comply with PEP 440: {version}' diff --git a/setuptools/package_index.py b/setuptools/package_index.py index d818f44..270e7f3 100644 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -21,7 +21,7 @@ import setuptools from pkg_resources import ( CHECKOUT_DIST, Distribution, BINARY_DIST, normalize_path, SOURCE_DIST, Environment, find_distributions, safe_name, safe_version, - to_filename, Requirement, DEVELOP_DIST, EGG_DIST, + to_filename, Requirement, DEVELOP_DIST, EGG_DIST, parse_version, ) from distutils import log from distutils.errors import DistutilsError @@ -294,6 +294,14 @@ class PackageIndex(Environment): self.to_scan = [] self.opener = urllib.request.urlopen + def add(self, dist): + # ignore invalid versions + try: + parse_version(dist.version) + except Exception: + return + return super().add(dist) + # FIXME: 'PackageIndex.process_url' is too complex (14) def process_url(self, url, retrieve=False): # noqa: C901 """Evaluate a URL as a possible download, and maybe retrieve it"""