1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-25 23:20:55 +00:00

update-python-libraries: use version key for latest release (#68857)

From warehouse API reference [1]:

     GET /pypi/<project_name>/json

     Returns metadata (info) about an individual project at the latest
     version […]

[1] https://warehouse.pypa.io/api-reference/json/#project
This commit is contained in:
Mario Rodas 2019-09-16 17:34:15 -05:00 committed by GitHub
parent a02303f91e
commit e8c29fa77c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -116,45 +116,11 @@ SEMVER = {
}
def _determine_latest_version(current_version, target, versions):
"""Determine latest version, given `target`.
"""
current_version = Version(current_version)
def _parse_versions(versions):
for v in versions:
try:
yield Version(v)
except InvalidVersion:
pass
versions = _parse_versions(versions)
index = SEMVER[target]
ceiling = list(current_version[0:index])
if len(ceiling) == 0:
ceiling = None
else:
ceiling[-1]+=1
ceiling = Version(".".join(map(str, ceiling)))
# We do not want prereleases
versions = SpecifierSet(prereleases=PRERELEASES).filter(versions)
if ceiling is not None:
versions = SpecifierSet(f"<{ceiling}").filter(versions)
return (max(sorted(versions))).raw_version
def _get_latest_version_pypi(package, extension, current_version, target):
"""Get latest version and hash from PyPI."""
url = "{}/{}/json".format(INDEX, package)
json = _fetch_page(url)
versions = json['releases'].keys()
version = _determine_latest_version(current_version, target, versions)
version = json['info']['version']
try:
releases = json['releases'][version]
@ -166,6 +132,7 @@ def _get_latest_version_pypi(package, extension, current_version, target):
sha256 = release['digests']['sha256']
break
else:
logging.error("Release not found for extension: {}".format(extension))
sha256 = None
return version, sha256