Skip to content

Commit 327c2bc

Browse files
authored
Use SHA256 from GitHub API for Python downloads (#14708)
We recently ran over the file limit and had to drop hash file from the releases page in favor of bulk SHA256SUMS files (astral-sh/python-build-standalone#691). Conveniently, GitHub has recently started to add a SHA256 digest to the API. GitHub did not backfill the hashes for the old releases, so use the API hashes for newer assets, and eventually only download SHA256SUMS for older releases.
1 parent bce2ea4 commit 327c2bc

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

crates/uv-python/fetch-download-metadata.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,13 @@ async def _fetch_downloads(self, pages: int = 100) -> list[PythonDownload]:
255255
# Sort the assets to ensure deterministic results
256256
row["assets"].sort(key=lambda asset: asset["browser_download_url"])
257257
for asset in row["assets"]:
258+
# On older versions, GitHub didn't backfill the digest.
259+
if digest := asset["digest"]:
260+
sha256 = digest.removeprefix("sha256:")
261+
else:
262+
sha256 = None
258263
url = asset["browser_download_url"]
259-
download = self._parse_download_url(url)
264+
download = self._parse_download_url(url, sha256)
260265
if download is None:
261266
continue
262267
if (
@@ -305,6 +310,9 @@ async def _fetch_checksums(self, downloads: list[PythonDownload], n: int) -> Non
305310
"""Fetch the checksums for the given downloads."""
306311
checksum_urls = set()
307312
for download in downloads:
313+
# Skip the newer releases where we got the hash from the GitHub API
314+
if download.sha256:
315+
continue
308316
release_base_url = download.url.rsplit("/", maxsplit=1)[0]
309317
checksum_url = release_base_url + "/SHA256SUMS"
310318
checksum_urls.add(checksum_url)
@@ -343,9 +351,13 @@ async def fetch_checksums(url: str) -> httpx.Response | None:
343351
checksums[filename] = checksum
344352

345353
for download in downloads:
354+
if download.sha256:
355+
continue
346356
download.sha256 = checksums.get(download.filename)
347357

348-
def _parse_download_url(self, url: str) -> PythonDownload | None:
358+
def _parse_download_url(
359+
self, url: str, sha256: str | None
360+
) -> PythonDownload | None:
349361
"""Parse an indygreg download URL into a PythonDownload object."""
350362
# Ex)
351363
# https://github.com/astral-sh/python-build-standalone/releases/download/20240107/cpython-3.12.1%2B20240107-aarch64-unknown-linux-gnu-lto-full.tar.zst
@@ -391,6 +403,7 @@ def _parse_download_url(self, url: str) -> PythonDownload | None:
391403
url=url,
392404
build_options=build_options,
393405
variant=variant,
406+
sha256=sha256,
394407
)
395408

396409
def _normalize_triple(self, triple: str) -> PlatformTriple | None:

0 commit comments

Comments
 (0)