Skip to content

Commit b5c8873

Browse files
authored
fix(toolchains): add releases.astral.sh mirror for python-build-standalone (#3761)
Currently, python-build-standalone runtimes are only downloaded from github.com. If github.com is down or experiencing 5xx errors, builds will fail because the runtimes cannot be fetched. To fix this, add releases.astral.sh as a secondary fallback mirror URL. If the requested base_url starts with the standard or legacy github.com release prefix, we append the equivalent releases.astral.sh URL to rendered_urls.
1 parent ca066b8 commit b5c8873

2 files changed

Lines changed: 69 additions & 1 deletion

File tree

python/versions.bzl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ INSTALL_ONLY = "install_only"
2828

2929
DEFAULT_RELEASE_BASE_URL = "https://github.com/astral-sh/python-build-standalone/releases/download"
3030

31+
_GITHUB_PREFIX = "https://github.com/astral-sh/python-build-standalone/releases/download"
32+
_LEGACY_GITHUB_PREFIX = "https://github.com/indygreg/python-build-standalone/releases/download"
33+
_ASTRAL_PREFIX = "https://releases.astral.sh/github/python-build-standalone/releases/download"
34+
3135
# When updating the versions and releases, run the following command to get
3236
# the hashes:
3337
# bazel run //python/private:print_toolchains_checksums --//python/config_settings:python_version={major}.{minor}.{patch}
@@ -1435,6 +1439,14 @@ def get_release_info(platform, python_version, base_url = DEFAULT_RELEASE_BASE_U
14351439
A tuple of (filename, url, archive strip prefix, patches, patch_strip)
14361440
"""
14371441

1442+
base_urls = [base_url]
1443+
if base_url == DEFAULT_RELEASE_BASE_URL or base_url.startswith(_GITHUB_PREFIX):
1444+
suffix = base_url[len(_GITHUB_PREFIX):]
1445+
base_urls.append(_ASTRAL_PREFIX + suffix)
1446+
elif base_url.startswith(_LEGACY_GITHUB_PREFIX):
1447+
suffix = base_url[len(_LEGACY_GITHUB_PREFIX):]
1448+
base_urls.append(_ASTRAL_PREFIX + suffix)
1449+
14381450
url = tool_versions[python_version]["url"]
14391451

14401452
if type(url) == type({}):
@@ -1490,7 +1502,8 @@ def get_release_info(platform, python_version, base_url = DEFAULT_RELEASE_BASE_U
14901502
if "://" in release_filename: # is absolute url?
14911503
rendered_urls.append(release_filename)
14921504
else:
1493-
rendered_urls.append("/".join([base_url, release_filename]))
1505+
for b_url in base_urls:
1506+
rendered_urls.append("/".join([b_url, release_filename]))
14941507

14951508
if release_filename == None:
14961509
fail("release_filename should be set by now; were any download URLs given?")

tests/get_release_info/get_release_info_tests.bzl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,61 @@ def _test_file_url(env):
4848

4949
_tests.append(_test_file_url)
5050

51+
def _test_astral_mirror(env):
52+
"""Tests that the releases.astral.sh mirror is added as a secondary URL."""
53+
tool_versions = {
54+
"3.11.5": {
55+
"sha256": {
56+
"x86_64-unknown-linux-gnu": "fbed6f7694b2faae5d7c401a856219c945397f772eea5ca50c6eb825cbc9d1e1",
57+
},
58+
"strip_prefix": "python",
59+
"url": "20230826/cpython-{python_version}+20230826-{platform}-{build}.tar.gz",
60+
},
61+
}
62+
63+
expected_urls = [
64+
"https://github.com/astral-sh/python-build-standalone/releases/download/20230826/cpython-3.11.5+20230826-x86_64-unknown-linux-gnu-install_only.tar.gz",
65+
"https://releases.astral.sh/github/python-build-standalone/releases/download/20230826/cpython-3.11.5+20230826-x86_64-unknown-linux-gnu-install_only.tar.gz",
66+
]
67+
68+
_, urls, _, _, _ = get_release_info(
69+
platform = "x86_64-unknown-linux-gnu",
70+
python_version = "3.11.5",
71+
tool_versions = tool_versions,
72+
)
73+
74+
env.expect.that_collection(urls).contains_exactly(expected_urls)
75+
76+
_tests.append(_test_astral_mirror)
77+
78+
def _test_astral_mirror_legacy(env):
79+
"""Tests that the releases.astral.sh mirror is added for legacy indygreg URLs."""
80+
tool_versions = {
81+
"3.11.5": {
82+
"sha256": {
83+
"x86_64-unknown-linux-gnu": "fbed6f7694b2faae5d7c401a856219c945397f772eea5ca50c6eb825cbc9d1e1",
84+
},
85+
"strip_prefix": "python",
86+
"url": "20230826/cpython-{python_version}+20230826-{platform}-{build}.tar.gz",
87+
},
88+
}
89+
90+
expected_urls = [
91+
"https://github.com/indygreg/python-build-standalone/releases/download/20230826/cpython-3.11.5+20230826-x86_64-unknown-linux-gnu-install_only.tar.gz",
92+
"https://releases.astral.sh/github/python-build-standalone/releases/download/20230826/cpython-3.11.5+20230826-x86_64-unknown-linux-gnu-install_only.tar.gz",
93+
]
94+
95+
_, urls, _, _, _ = get_release_info(
96+
platform = "x86_64-unknown-linux-gnu",
97+
python_version = "3.11.5",
98+
base_url = "https://github.com/indygreg/python-build-standalone/releases/download",
99+
tool_versions = tool_versions,
100+
)
101+
102+
env.expect.that_collection(urls).contains_exactly(expected_urls)
103+
104+
_tests.append(_test_astral_mirror_legacy)
105+
51106
def get_release_info_test_suite(name):
52107
"""Defines the test suite for get_release_info."""
53108
test_suite(

0 commit comments

Comments
 (0)