Skip to content

Commit ef4c927

Browse files
committed
avoid circular load deps
1 parent 9bc500c commit ef4c927

File tree

5 files changed

+91
-88
lines changed

5 files changed

+91
-88
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ END_UNRELEASED_TEMPLATE
6060
* (gazelle) Types for exposed members of `python.ParserOutput` are now all public.
6161
* (toolchains): Using [20250612] release of the `python-build-standalone` release.
6262
* (toolchains): Bumped `3.13` to use `3.13.5` version.
63+
* (toolchains): Moved the `print_toolchains_checksums` to
64+
`//python/private:print_toolchains_checksums.bzl`.
6365

6466
[20250612]: https://github.com/astral-sh/python-build-standalone/releases/tag/20250612
6567

python/BUILD.bazel

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,7 @@ bzl_library(
247247
name = "versions_bzl",
248248
srcs = ["versions.bzl"],
249249
visibility = ["//:__subpackages__"],
250-
deps = [
251-
"//python/private:platform_info_bzl",
252-
"//python/private:text_util_bzl",
253-
],
250+
deps = ["//python/private:platform_info_bzl"],
254251
)
255252

256253
# NOTE: Remember to add bzl_library targets to //tests:bzl_libraries

python/private/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
1616
load("@bazel_skylib//rules:common_settings.bzl", "bool_setting")
1717
load("//python:py_binary.bzl", "py_binary")
1818
load("//python:py_library.bzl", "py_library")
19-
load("//python:versions.bzl", "print_toolchains_checksums")
19+
load("print_toolchain_checksums.bzl", "print_toolchains_checksums")
2020
load(":py_exec_tools_toolchain.bzl", "current_interpreter_executable")
2121
load(":sentinel.bzl", "sentinel")
2222
load(":stamp.bzl", "stamp_build_setting")
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"""Print the toolchain versions
2+
"""
3+
4+
load("//python:versions.bzl", "TOOL_VERSIONS", "get_release_info")
5+
load("//python/private:text_util.bzl", "render")
6+
7+
def print_toolchains_checksums(name):
8+
"""A macro to print checksums for a particular Python interpreter version.
9+
10+
Args:
11+
name: {type}`str`: the name of the runnable target.
12+
"""
13+
all_commands = []
14+
by_version = {}
15+
16+
for python_version, metadata in TOOL_VERSIONS.items():
17+
by_version[python_version] = _commands_for_version(
18+
python_version = python_version,
19+
metadata = metadata,
20+
)
21+
all_commands.append(by_version[python_version])
22+
23+
template = """\
24+
cat > "$@" <<'EOF'
25+
#!/bin/bash
26+
27+
set -o errexit -o nounset -o pipefail
28+
29+
echo "Fetching hashes..."
30+
31+
{commands}
32+
EOF
33+
"""
34+
35+
native.genrule(
36+
name = name,
37+
srcs = [],
38+
outs = ["print_toolchains_checksums.sh"],
39+
cmd = select({
40+
"//python/config_settings:is_python_{}".format(version): template.format(
41+
commands = commands,
42+
)
43+
for version, commands in by_version.items()
44+
} | {
45+
"//conditions:default": template.format(commands = "\n".join(all_commands)),
46+
}),
47+
executable = True,
48+
)
49+
50+
def _commands_for_version(*, python_version, metadata):
51+
lines = []
52+
lines += [
53+
"cat <<EOB", # end of block
54+
" \"{python_version}\": {{".format(python_version = python_version),
55+
" \"url\": \"{url}\",".format(url = metadata["url"]),
56+
" \"sha256\": {",
57+
]
58+
59+
for platform in metadata["sha256"].keys():
60+
for release_url in get_release_info(platform, python_version)[1]:
61+
# Do lines one by one so that the progress is seen better and use cat for ease of quotation
62+
lines += [
63+
"EOB",
64+
"cat <<EOB",
65+
" \"{platform}\": \"$$({get_sha256})\",".format(
66+
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(
68+
release_url = release_url,
69+
release_url_sha256 = release_url + ".sha256",
70+
),
71+
),
72+
]
73+
74+
prefix = metadata["strip_prefix"]
75+
prefix = render.indent(
76+
render.dict(prefix) if type(prefix) == type({}) else repr(prefix),
77+
indent = " " * 8,
78+
).lstrip()
79+
80+
lines += [
81+
" },",
82+
" \"strip_prefix\": {strip_prefix},".format(strip_prefix = prefix),
83+
" },",
84+
"EOB",
85+
]
86+
87+
return "\n".join(lines)

python/versions.bzl

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"""
1717

1818
load("//python/private:platform_info.bzl", "platform_info")
19-
load("//python/private:text_util.bzl", "render")
2019

2120
# Values present in the @platforms//os package
2221
MACOS_NAME = "osx"
@@ -441,88 +440,6 @@ def get_release_info(platform, python_version, base_url = DEFAULT_RELEASE_BASE_U
441440

442441
return (release_filename, rendered_urls, strip_prefix, patches, patch_strip)
443442

444-
def print_toolchains_checksums(name):
445-
"""A macro to print checksums for a particular Python interpreter version.
446-
447-
Args:
448-
name: {type}`str`: the name of the runnable target.
449-
"""
450-
all_commands = []
451-
by_version = {}
452-
453-
for python_version, metadata in TOOL_VERSIONS.items():
454-
by_version[python_version] = _commands_for_version(
455-
python_version = python_version,
456-
metadata = metadata,
457-
)
458-
all_commands.append(by_version[python_version])
459-
460-
template = """\
461-
cat > "$@" <<'EOF'
462-
#!/bin/bash
463-
464-
set -o errexit -o nounset -o pipefail
465-
466-
echo "Fetching hashes..."
467-
468-
{commands}
469-
EOF
470-
"""
471-
472-
native.genrule(
473-
name = name,
474-
srcs = [],
475-
outs = ["print_toolchains_checksums.sh"],
476-
cmd = select({
477-
"//python/config_settings:is_python_{}".format(version): template.format(
478-
commands = commands,
479-
)
480-
for version, commands in by_version.items()
481-
} | {
482-
"//conditions:default": template.format(commands = "\n".join(all_commands)),
483-
}),
484-
executable = True,
485-
)
486-
487-
def _commands_for_version(*, python_version, metadata):
488-
lines = []
489-
lines += [
490-
"cat <<EOB", # end of block
491-
" \"{python_version}\": {{".format(python_version = python_version),
492-
" \"url\": \"{url}\",".format(url = metadata["url"]),
493-
" \"sha256\": {",
494-
]
495-
496-
for platform in metadata["sha256"].keys():
497-
for release_url in get_release_info(platform, python_version)[1]:
498-
# Do lines one by one so that the progress is seen better and use cat for ease of quotation
499-
lines += [
500-
"EOB",
501-
"cat <<EOB",
502-
" \"{platform}\": \"$$({get_sha256})\",".format(
503-
platform = platform,
504-
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(
505-
release_url = release_url,
506-
release_url_sha256 = release_url + ".sha256",
507-
),
508-
),
509-
]
510-
511-
prefix = metadata["strip_prefix"]
512-
prefix = render.indent(
513-
render.dict(prefix) if type(prefix) == type({}) else repr(prefix),
514-
indent = " " * 8,
515-
).lstrip()
516-
517-
lines += [
518-
" },",
519-
" \"strip_prefix\": {strip_prefix},".format(strip_prefix = prefix),
520-
" },",
521-
"EOB",
522-
]
523-
524-
return "\n".join(lines)
525-
526443
def gen_python_config_settings(name = ""):
527444
for platform in PLATFORMS.keys():
528445
native.config_setting(

0 commit comments

Comments
 (0)