Skip to content

Commit

Permalink
Ignore PyPIClient releases with invalid PEP440 versions
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
deathaxe committed Feb 25, 2024
1 parent 4607c31 commit 945da37
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions package_control/clients/pypi_client.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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",
Expand All @@ -73,6 +74,7 @@ def download_info_from_releases(self, url, asset_templates, tag_prefix=None):
}
)
]
```
Supported globs:
Expand Down Expand Up @@ -192,25 +194,36 @@ 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)
num_releases = [0] * len(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)
Expand Down

0 comments on commit 945da37

Please sign in to comment.