Revert "update-python-libraries: use version key for latest release (#68857)"
This broke support for --target.
This reverts commit e8c29fa77c
.
This commit is contained in:
parent
7181aca6d9
commit
aedf4fc8fc
|
@ -116,11 +116,45 @@ 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):
|
def _get_latest_version_pypi(package, extension, current_version, target):
|
||||||
"""Get latest version and hash from PyPI."""
|
"""Get latest version and hash from PyPI."""
|
||||||
url = "{}/{}/json".format(INDEX, package)
|
url = "{}/{}/json".format(INDEX, package)
|
||||||
json = _fetch_page(url)
|
json = _fetch_page(url)
|
||||||
version = json['info']['version']
|
|
||||||
|
versions = json['releases'].keys()
|
||||||
|
version = _determine_latest_version(current_version, target, versions)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
releases = json['releases'][version]
|
releases = json['releases'][version]
|
||||||
|
@ -132,7 +166,6 @@ def _get_latest_version_pypi(package, extension, current_version, target):
|
||||||
sha256 = release['digests']['sha256']
|
sha256 = release['digests']['sha256']
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
logging.error("Release not found for extension: {}".format(extension))
|
|
||||||
sha256 = None
|
sha256 = None
|
||||||
return version, sha256
|
return version, sha256
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue