chore: Use the virtualenv release URL rather than the blob URL (#2555)
This commit is contained in:
+31
-30
@@ -4,17 +4,18 @@
|
|||||||
import dataclasses
|
import dataclasses
|
||||||
import difflib
|
import difflib
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
|
||||||
import tomllib
|
import tomllib
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Final
|
from typing import Final
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import rich
|
import rich
|
||||||
from packaging.version import InvalidVersion, Version
|
from packaging.version import Version
|
||||||
from rich.logging import RichHandler
|
from rich.logging import RichHandler
|
||||||
from rich.syntax import Syntax
|
from rich.syntax import Syntax
|
||||||
|
|
||||||
|
from cibuildwheel.extra import github_api_request
|
||||||
|
|
||||||
log = logging.getLogger("cibw")
|
log = logging.getLogger("cibw")
|
||||||
|
|
||||||
# Looking up the dir instead of using utils.resources_dir
|
# Looking up the dir instead of using utils.resources_dir
|
||||||
@@ -30,32 +31,26 @@ GET_VIRTUALENV_URL_TEMPLATE: Final[str] = (
|
|||||||
|
|
||||||
@dataclasses.dataclass(frozen=True, order=True)
|
@dataclasses.dataclass(frozen=True, order=True)
|
||||||
class VersionTuple:
|
class VersionTuple:
|
||||||
|
name: str
|
||||||
|
download_url: str
|
||||||
version: Version
|
version: Version
|
||||||
version_string: str
|
|
||||||
|
|
||||||
|
|
||||||
def git_ls_remote_versions(url: str) -> list[VersionTuple]:
|
def get_latest_virtualenv_release() -> VersionTuple:
|
||||||
versions: list[VersionTuple] = []
|
response = github_api_request("repos/pypa/get-virtualenv/releases/latest")
|
||||||
tags = subprocess.run(
|
tag_name = response["tag_name"]
|
||||||
["git", "ls-remote", "--tags", url], check=True, text=True, capture_output=True
|
|
||||||
).stdout.splitlines()
|
asset = next(
|
||||||
for tag in tags:
|
(asset for asset in response["assets"] if asset["name"] == "virtualenv.pyz"),
|
||||||
_, ref = tag.split()
|
None,
|
||||||
assert ref.startswith("refs/tags/")
|
)
|
||||||
version_string = ref[10:]
|
if not asset:
|
||||||
try:
|
msg = "No asset named 'virtualenv.pyz' found in the latest release of get-virtualenv."
|
||||||
version = Version(version_string)
|
raise RuntimeError(msg)
|
||||||
if version.is_devrelease:
|
|
||||||
log.info("Ignoring development release %r", str(version))
|
return VersionTuple(
|
||||||
continue
|
version=Version(tag_name), name=tag_name, download_url=asset["browser_download_url"]
|
||||||
if version.is_prerelease:
|
)
|
||||||
log.info("Ignoring pre-release %r", str(version))
|
|
||||||
continue
|
|
||||||
versions.append(VersionTuple(version, version_string))
|
|
||||||
except InvalidVersion:
|
|
||||||
log.warning("Ignoring ref %r", ref)
|
|
||||||
versions.sort(reverse=True)
|
|
||||||
return versions
|
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@@ -78,14 +73,20 @@ def update_virtualenv(force: bool, level: str) -> None:
|
|||||||
with toml_file_path.open("rb") as f:
|
with toml_file_path.open("rb") as f:
|
||||||
configurations = tomllib.load(f)
|
configurations = tomllib.load(f)
|
||||||
default = configurations.pop("default")
|
default = configurations.pop("default")
|
||||||
version = str(default["version"])
|
local_version = str(default["version"])
|
||||||
versions = git_ls_remote_versions(GET_VIRTUALENV_GITHUB)
|
|
||||||
if versions[0].version > Version(version):
|
latest_release = get_latest_virtualenv_release()
|
||||||
version = versions[0].version_string
|
|
||||||
|
if latest_release.version > Version(local_version):
|
||||||
|
version = latest_release.name
|
||||||
|
url = latest_release.download_url
|
||||||
|
else:
|
||||||
|
version = local_version
|
||||||
|
url = default["url"]
|
||||||
|
|
||||||
configurations["default"] = {
|
configurations["default"] = {
|
||||||
"version": version,
|
"version": version,
|
||||||
"url": GET_VIRTUALENV_URL_TEMPLATE.format(version=version),
|
"url": url,
|
||||||
}
|
}
|
||||||
result_toml = "".join(
|
result_toml = "".join(
|
||||||
f'{key} = {{ version = "{value["version"]}", url = "{value["url"]}" }}\n'
|
f'{key} = {{ version = "{value["version"]}", url = "{value["url"]}" }}\n'
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
default = { version = "20.33.1", url = "https://github.com/pypa/get-virtualenv/blob/20.33.1/public/virtualenv.pyz?raw=true" }
|
default = { version = "20.34.0", url = "https://github.com/pypa/get-virtualenv/releases/download/20.34.0/virtualenv.pyz" }
|
||||||
|
|||||||
Reference in New Issue
Block a user