Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Create release archive and notes
run: .github/workflows/create_archive_and_notes.sh ${{ inputs.tag_name || github.ref_name }}
- name: Release
uses: softprops/action-gh-release@v2
uses: softprops/action-gh-release@v3
with:
# Use GH feature to populate the changelog automatically
generate_release_notes: true
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ END_UNRELEASED_TEMPLATE
files ([#3126](https://github.com/bazel-contrib/rules_python/issues/3126)).
* (pypi) Support `--experimental_isolated_extension_usages`
([#3668](https://github.com/bazel-contrib/rules_python/issues/3668)).
* (uv) use the astral.sh mirror as the preferred url for binary downloads,
with github.com as a fallback; for uv >= 0.11.0, read the checksums directly
from the dist-manifest contents.

{#v0-0-0-added}
### Added
Expand Down
49 changes: 42 additions & 7 deletions python/uv/private/uv.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ def _overlap(first_collection, second_collection):

return False

# See https://github.com/astral-sh/setup-uv/pull/809.
GITHUB_RELEASES_PREFIX = "https://github.com/astral-sh/uv/releases/download/"
ASTRAL_MIRROR_PREFIX = "https://releases.astral.sh/github/uv/releases/download/"

def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename, platforms, get_auth = get_auth, **auth_attrs):
"""Download the results about remote tool sources.

Expand Down Expand Up @@ -452,6 +456,8 @@ def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename
}
]
checksum "uv-aarch64-apple-darwin.tar.gz.sha256"
checksums
sha256 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
uv-aarch64-apple-darwin.tar.gz.sha256
name "uv-aarch64-apple-darwin.tar.gz.sha256"
kind "checksum"
Expand All @@ -471,29 +477,55 @@ def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename
fail(result)
dist_manifest = json.decode(module_ctx.read(dist_manifest))

base_url = (
# Use the simple download_url from the manifest, when available.
dist_base_url = (
dist_manifest
.get("releases", [{}])[0]
.get("hosting", {})
.get("simple", {})
.get("download_url", base_url)
)

# For official releases, add the astral mirror to improve availability.
# See https://github.com/astral-sh/setup-uv/pull/809.
if dist_base_url.startswith(GITHUB_RELEASES_PREFIX):
astral_base_url = ASTRAL_MIRROR_PREFIX + dist_base_url[len(GITHUB_RELEASES_PREFIX):]
base_urls = [
astral_base_url,
dist_base_url,
]
else:
base_urls = [dist_base_url]

artifacts = dist_manifest["artifacts"]
tool_sources = {}
downloads = {}
for fname, artifact in artifacts.items():
if artifact.get("kind") != "executable-zip":
continue
target_triples = artifact["target_triples"]
if not _overlap(target_triples, platforms):
# We are not interested in this platform, so skip.
continue

checksum = artifacts[artifact["checksum"]]
if not _overlap(checksum["target_triples"], platforms):
# we are not interested in this platform, so skip
# Releases of uv >= 0.11.0 have the sha256 directly inline.
sha256 = artifact.get("checksums", {}).get("sha256", "")
if len(sha256) > 0:
for platform in target_triples:
tool_sources[platform] = struct(
urls = [
"{}/{}".format(base, fname)
for base in base_urls
],
sha256 = sha256,
)
continue

# For uv < 0.11.0, we'll need to fetch the individual sha256 files.
checksum = artifacts[artifact["checksum"]]
checksum_fname = checksum["name"]
checksum_path = module_ctx.path(checksum_fname)
urls = ["{}/{}".format(base_url, checksum_fname)]
urls = ["{}/{}".format(dist_base_url, checksum_fname)]
downloads[checksum_path] = struct(
download = module_ctx.download(
url = urls,
Expand All @@ -502,7 +534,7 @@ def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename
auth = get_auth(module_ctx, urls, ctx_attr = auth_attr),
),
archive_fname = fname,
platforms = checksum["target_triples"],
platforms = target_triples,
)

for checksum_path, download in downloads.items():
Expand All @@ -522,7 +554,10 @@ def _get_tool_urls_from_dist_manifest(module_ctx, *, base_url, manifest_filename

for platform in download.platforms:
tool_sources[platform] = struct(
urls = ["{}/{}".format(base_url, archive_fname)],
urls = [
"{}/{}".format(base, archive_fname)
for base in base_urls
],
sha256 = sha256,
)

Expand Down
2 changes: 2 additions & 0 deletions tests/uv/uv/uv_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def _uv_mock_mctx(*modules, download = None):
x: {
"checksum": x + ".sha256",
"kind": "executable-zip",
"target_triples": [x],
}
for x in ["linux", "osx"]
} | {
Expand All @@ -47,6 +48,7 @@ def _uv_mock_mctx(*modules, download = None):
x: {
"checksum": x + ".sha256",
"kind": "executable-zip",
"target_triples": [x],
}
for x in ["linux", "os", "osx", "something_extra"]
} | {
Expand Down