mirror of https://github.com/astral-sh/uv
Improve `CPythonFinder._parse_download_url` a bit (#14780)
## Summary Rename `_parse_download_url` to `_parse_download_asset` and move the `asset['digest']` logic into it. ## Test Plan ```console uv run ./crates/uv-python/fetch-download-metadata.py ```
This commit is contained in:
parent
7c2819d1f6
commit
98d6ab6632
|
|
@ -53,8 +53,7 @@ import re
|
|||
from dataclasses import asdict, dataclass, field
|
||||
from enum import StrEnum
|
||||
from pathlib import Path
|
||||
from typing import Generator, Iterable, NamedTuple, Self
|
||||
from urllib.parse import unquote
|
||||
from typing import Any, Generator, Iterable, NamedTuple, Self
|
||||
|
||||
import httpx
|
||||
|
||||
|
|
@ -255,13 +254,7 @@ class CPythonFinder(Finder):
|
|||
# Sort the assets to ensure deterministic results
|
||||
row["assets"].sort(key=lambda asset: asset["browser_download_url"])
|
||||
for asset in row["assets"]:
|
||||
# On older versions, GitHub didn't backfill the digest.
|
||||
if digest := asset["digest"]:
|
||||
sha256 = digest.removeprefix("sha256:")
|
||||
else:
|
||||
sha256 = None
|
||||
url = asset["browser_download_url"]
|
||||
download = self._parse_download_url(url, sha256)
|
||||
download = self._parse_download_asset(asset)
|
||||
if download is None:
|
||||
continue
|
||||
if (
|
||||
|
|
@ -355,16 +348,19 @@ class CPythonFinder(Finder):
|
|||
continue
|
||||
download.sha256 = checksums.get(download.filename)
|
||||
|
||||
def _parse_download_url(
|
||||
self, url: str, sha256: str | None
|
||||
) -> PythonDownload | None:
|
||||
"""Parse an indygreg download URL into a PythonDownload object."""
|
||||
def _parse_download_asset(self, asset: dict[str, Any]) -> PythonDownload | None:
|
||||
"""Parse a python-build-standalone download asset into a PythonDownload object."""
|
||||
url = asset["browser_download_url"]
|
||||
# Ex)
|
||||
# https://github.com/astral-sh/python-build-standalone/releases/download/20240107/cpython-3.12.1%2B20240107-aarch64-unknown-linux-gnu-lto-full.tar.zst
|
||||
if url.endswith(".sha256"):
|
||||
return None
|
||||
filename = unquote(url.rsplit("/", maxsplit=1)[-1])
|
||||
release = int(url.rsplit("/")[-2])
|
||||
filename = asset["name"]
|
||||
sha256 = None
|
||||
# On older versions, GitHub didn't backfill the digest.
|
||||
if digest := asset["digest"]:
|
||||
sha256 = digest.removeprefix("sha256:")
|
||||
|
||||
match = self._filename_re.match(filename) or self._legacy_filename_re.match(
|
||||
filename
|
||||
|
|
|
|||
Loading…
Reference in New Issue