From 945da37dfb3284a50c3899dbaf78d4fe74b25746 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sun, 25 Feb 2024 14:03:27 +0100 Subject: [PATCH] Ignore PyPIClient releases with invalid PEP440 versions This commit filters all package releases returned by pypi.org, which do not provide valid PEP440 versions instead of raising invalid version exception. This is required for libraries such as `pytz` which contain releases with invalid version schemas such as "2004a", "2004b". --- package_control/clients/pypi_client.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/package_control/clients/pypi_client.py b/package_control/clients/pypi_client.py index c2cf58a5..493c9932 100644 --- a/package_control/clients/pypi_client.py +++ b/package_control/clients/pypi_client.py @@ -1,8 +1,8 @@ import re +from ..pep440 import PEP440InvalidVersionError from ..pep440 import PEP440Version from ..pep440 import PEP440VersionSpecifier -from ..package_version import version_sort from .json_api_client import JSONApiClient @@ -64,6 +64,7 @@ def download_info_from_releases(self, url, asset_templates, tag_prefix=None): :param asset_templates: A list of tuples of asset template and download_info. + ```py [ ( "coverage-${version}-cp33-*-win_amd64*.whl", @@ -73,6 +74,7 @@ def download_info_from_releases(self, url, asset_templates, tag_prefix=None): } ) ] + ``` Supported globs: @@ -192,8 +194,18 @@ def _download_info_from_latest_version(self, name, asset_templates): """ pypi_url = "https://pypi.org/pypi/{}/json".format(name) + + # fetch dictionary of form `version: [asset, asset]` releases = self.fetch_json(pypi_url)["releases"] + # create a list of valid pep440 versions + versions = [] + for version in releases: + try: + versions.append(PEP440Version(version)) + except PEP440InvalidVersionError: + continue + asset_templates = self._expand_asset_variables(asset_templates) max_releases = self.settings.get("max_releases", 0) @@ -201,16 +213,17 @@ def _download_info_from_latest_version(self, name, asset_templates): # get latest compatible release for each asset template output = [] - for version in version_sort(releases, reverse=True): + for version in sorted(versions, reverse=True): # we don"t want beta releases! - if not PEP440Version(version).is_final: + if not version.is_final: continue - assets = releases[version] + version_string = str(version) + assets = releases[version_string] for idx, (pattern, selectors) in enumerate(asset_templates): if max_releases > 0 and num_releases[idx] >= max_releases: continue - info = self._make_download_info(pattern, selectors, version, assets) + info = self._make_download_info(pattern, selectors, version_string, assets) if not info: continue output.append(info)