Skip to content

Commit 0091770

Browse files
committed
Use SHA256 from GitHub API for Python downloads
We recently ran over the file limit and had to drop hash file from the releases page (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, while we use our own hash files for older releases.
1 parent e724ddc commit 0091770

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,14 @@ 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 more recent versions we don't have files with hashes anymore,
259+
# but on older versions GitHub didn't backfill the digest.
260+
if digest := asset["digest"]:
261+
sha256 = digest.removeprefix("sha256:")
262+
else:
263+
sha256 = None
258264
url = asset["browser_download_url"]
259-
download = self._parse_download_url(url)
265+
download = self._parse_download_url(url, sha256)
260266
if download is None:
261267
continue
262268
if (
@@ -305,6 +311,9 @@ async def _fetch_checksums(self, downloads: list[PythonDownload], n: int) -> Non
305311
"""Fetch the checksums for the given downloads."""
306312
checksum_urls = set()
307313
for download in downloads:
314+
# Skip the newer releases where we got the hash from the GitHub API
315+
if download.sha256:
316+
continue
308317
release_base_url = download.url.rsplit("/", maxsplit=1)[0]
309318
checksum_url = release_base_url + "/SHA256SUMS"
310319
checksum_urls.add(checksum_url)
@@ -343,9 +352,13 @@ async def fetch_checksums(url: str) -> httpx.Response | None:
343352
checksums[filename] = checksum
344353

345354
for download in downloads:
355+
if download.sha256:
356+
continue
346357
download.sha256 = checksums.get(download.filename)
347358

348-
def _parse_download_url(self, url: str) -> PythonDownload | None:
359+
def _parse_download_url(
360+
self, url: str, sha256: str | None
361+
) -> PythonDownload | None:
349362
"""Parse an indygreg download URL into a PythonDownload object."""
350363
# Ex)
351364
# 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 +404,7 @@ def _parse_download_url(self, url: str) -> PythonDownload | None:
391404
url=url,
392405
build_options=build_options,
393406
variant=variant,
407+
sha256=sha256,
394408
)
395409

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

0 commit comments

Comments
 (0)