Skip to content

Commit 68f9762

Browse files
authored
chore: Use the virtualenv release URL rather than the blob URL (#2555)
1 parent 95e827e commit 68f9762

File tree

2 files changed

+34
-33
lines changed

2 files changed

+34
-33
lines changed

bin/update_virtualenv.py

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
import dataclasses
55
import difflib
66
import logging
7-
import subprocess
87
import tomllib
98
from pathlib import Path
109
from typing import Final
1110

1211
import click
1312
import rich
14-
from packaging.version import InvalidVersion, Version
13+
from packaging.version import Version
1514
from rich.logging import RichHandler
1615
from rich.syntax import Syntax
1716

17+
from cibuildwheel.extra import github_api_request
18+
1819
log = logging.getLogger("cibw")
1920

2021
# Looking up the dir instead of using utils.resources_dir
@@ -30,32 +31,26 @@
3031

3132
@dataclasses.dataclass(frozen=True, order=True)
3233
class VersionTuple:
34+
name: str
35+
download_url: str
3336
version: Version
34-
version_string: str
35-
36-
37-
def git_ls_remote_versions(url: str) -> list[VersionTuple]:
38-
versions: list[VersionTuple] = []
39-
tags = subprocess.run(
40-
["git", "ls-remote", "--tags", url], check=True, text=True, capture_output=True
41-
).stdout.splitlines()
42-
for tag in tags:
43-
_, ref = tag.split()
44-
assert ref.startswith("refs/tags/")
45-
version_string = ref[10:]
46-
try:
47-
version = Version(version_string)
48-
if version.is_devrelease:
49-
log.info("Ignoring development release %r", str(version))
50-
continue
51-
if version.is_prerelease:
52-
log.info("Ignoring pre-release %r", str(version))
53-
continue
54-
versions.append(VersionTuple(version, version_string))
55-
except InvalidVersion:
56-
log.warning("Ignoring ref %r", ref)
57-
versions.sort(reverse=True)
58-
return versions
37+
38+
39+
def get_latest_virtualenv_release() -> VersionTuple:
40+
response = github_api_request("repos/pypa/get-virtualenv/releases/latest")
41+
tag_name = response["tag_name"]
42+
43+
asset = next(
44+
(asset for asset in response["assets"] if asset["name"] == "virtualenv.pyz"),
45+
None,
46+
)
47+
if not asset:
48+
msg = "No asset named 'virtualenv.pyz' found in the latest release of get-virtualenv."
49+
raise RuntimeError(msg)
50+
51+
return VersionTuple(
52+
version=Version(tag_name), name=tag_name, download_url=asset["browser_download_url"]
53+
)
5954

6055

6156
@click.command()
@@ -78,14 +73,20 @@ def update_virtualenv(force: bool, level: str) -> None:
7873
with toml_file_path.open("rb") as f:
7974
configurations = tomllib.load(f)
8075
default = configurations.pop("default")
81-
version = str(default["version"])
82-
versions = git_ls_remote_versions(GET_VIRTUALENV_GITHUB)
83-
if versions[0].version > Version(version):
84-
version = versions[0].version_string
76+
local_version = str(default["version"])
77+
78+
latest_release = get_latest_virtualenv_release()
79+
80+
if latest_release.version > Version(local_version):
81+
version = latest_release.name
82+
url = latest_release.download_url
83+
else:
84+
version = local_version
85+
url = default["url"]
8586

8687
configurations["default"] = {
8788
"version": version,
88-
"url": GET_VIRTUALENV_URL_TEMPLATE.format(version=version),
89+
"url": url,
8990
}
9091
result_toml = "".join(
9192
f'{key} = {{ version = "{value["version"]}", url = "{value["url"]}" }}\n'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
default = { version = "20.33.1", url = "https://github.com/pypa/get-virtualenv/blob/20.33.1/public/virtualenv.pyz?raw=true" }
1+
default = { version = "20.34.0", url = "https://github.com/pypa/get-virtualenv/releases/download/20.34.0/virtualenv.pyz" }

0 commit comments

Comments
 (0)