Skip to content

Commit ece4b77

Browse files
committed
simplify and test
1 parent a92fea4 commit ece4b77

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

python/private/print_toolchain_checksums.bzl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,27 @@
33

44
load("//python:versions.bzl", "TOOL_VERSIONS", "get_release_info")
55
load("//python/private:text_util.bzl", "render")
6+
load("//python/private:version.bzl", "version")
67

78
def print_toolchains_checksums(name):
89
"""A macro to print checksums for a particular Python interpreter version.
910
1011
Args:
1112
name: {type}`str`: the name of the runnable target.
1213
"""
13-
all_commands = []
1414
by_version = {}
1515

1616
for python_version, metadata in TOOL_VERSIONS.items():
1717
by_version[python_version] = _commands_for_version(
1818
python_version = python_version,
1919
metadata = metadata,
2020
)
21-
all_commands.append(by_version[python_version])
21+
22+
all_commands = sorted(
23+
by_version.items(),
24+
key = lambda x: version.key(version.parse(x[0], strict = True)),
25+
)
26+
all_commands = [x[1] for x in all_commands]
2227

2328
template = """\
2429
cat > "$@" <<'EOF'
@@ -37,10 +42,10 @@ EOF
3742
srcs = [],
3843
outs = ["print_toolchains_checksums.sh"],
3944
cmd = select({
40-
"//python/config_settings:is_python_{}".format(version): template.format(
45+
"//python/config_settings:is_python_{}".format(version_str): template.format(
4146
commands = commands,
4247
)
43-
for version, commands in by_version.items()
48+
for version_str, commands in by_version.items()
4449
} | {
4550
"//conditions:default": template.format(commands = "\n".join(all_commands)),
4651
}),
@@ -64,7 +69,7 @@ def _commands_for_version(*, python_version, metadata):
6469
"cat <<EOB",
6570
" \"{platform}\": \"$$({get_sha256})\",".format(
6671
platform = platform,
67-
get_sha256 = "curl --location --fail {release_url_sha256} 2>/dev/null || curl --location --fail {release_url} 2>/dev/null | shasum -a 256 | awk '{{ print $$1 }}'".format(
72+
get_sha256 = "curl --silent --show-error --location --fail {release_url_sha256}".format(
6873
release_url = release_url,
6974
release_url_sha256 = release_url + ".sha256",
7075
),

python/versions.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ DEFAULT_RELEASE_BASE_URL = "https://github.com/astral-sh/python-build-standalone
3232
# the hashes:
3333
# bazel run //python/private:print_toolchains_checksums --//python/config_settings:python_version={major}.{minor}.{patch}
3434
#
35+
# To print hashes for all of the specified versions, run:
36+
# bazel run //python/private:print_toolchains_checksums --//python/config_settings:python_version=""
37+
#
3538
# Note, to users looking at how to specify their tool versions, coverage_tool version for each
3639
# interpreter can be specified by:
3740
# "3.8.10": {

0 commit comments

Comments
 (0)