mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-20 00:53:12 +03: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:
parent
a02303f91e
commit
e8c29fa77c
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user