Skip to content

Commit 160c4e1

Browse files
committed
refactor: rename some classes and thread the available tool versions
1 parent a983bd0 commit 160c4e1

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

python/private/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ bzl_library(
131131
name = "python_bzl",
132132
srcs = ["python.bzl"],
133133
deps = [
134+
":python_repositories_bzl",
134135
":pythons_hub_bzl",
135136
":repo_utils_bzl",
136137
":toolchains_repo_bzl",
137138
":util_bzl",
138-
"//python:repositories_bzl",
139139
"@bazel_features//:features",
140140
],
141141
)

python/private/python.bzl

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
"Python toolchain module extensions for use with bzlmod"
1616

1717
load("@bazel_features//:features.bzl", "bazel_features")
18-
load("//python:repositories.bzl", "python_register_toolchains")
1918
load("//python:versions.bzl", "TOOL_VERSIONS")
20-
load("//python/private:repo_utils.bzl", "repo_utils")
19+
load(":python_repositories.bzl", "python_register_toolchains")
2120
load(":pythons_hub.bzl", "hub_repo")
21+
load(":repo_utils.bzl", "repo_utils")
2222
load(":text_util.bzl", "render")
2323
load(":toolchains_repo.bzl", "multi_toolchain_aliases")
2424
load(":util.bzl", "IS_BAZEL_6_4_OR_HIGHER")
@@ -28,14 +28,14 @@ load(":util.bzl", "IS_BAZEL_6_4_OR_HIGHER")
2828
_MAX_NUM_TOOLCHAINS = 9999
2929
_TOOLCHAIN_INDEX_PAD_LENGTH = len(str(_MAX_NUM_TOOLCHAINS))
3030

31-
def _python_register_toolchains(name, toolchain_attr, module, ignore_root_user_error):
31+
def _python_register_toolchains(name, toolchain_attr, module, **kwargs):
3232
"""Calls python_register_toolchains and returns a struct used to collect the toolchains.
3333
"""
3434
python_register_toolchains(
3535
name = name,
3636
python_version = toolchain_attr.python_version,
3737
register_coverage_tool = toolchain_attr.configure_coverage_tool,
38-
ignore_root_user_error = ignore_root_user_error,
38+
**kwargs
3939
)
4040
return struct(
4141
python_version = toolchain_attr.python_version,
@@ -76,9 +76,9 @@ def _python_impl(module_ctx):
7676
for mod in module_ctx.modules:
7777
module_toolchain_versions = []
7878

79-
toolchain_attr_structs = _create_toolchain_attr_structs(mod)
79+
python_tools = _process_tag_classes(mod)
8080

81-
for toolchain_attr in toolchain_attr_structs:
81+
for toolchain_attr in python_tools.registrations:
8282
toolchain_version = toolchain_attr.python_version
8383
toolchain_name = "python_" + toolchain_version.replace(".", "_")
8484

@@ -144,6 +144,10 @@ def _python_impl(module_ctx):
144144
toolchain_attr,
145145
module = mod,
146146
ignore_root_user_error = ignore_root_user_error,
147+
# TODO @aignas 2024-08-08: allow to modify these values via the bzlmod extension
148+
# distutils_content = None,
149+
# register_toolchains = True,
150+
tool_versions = python_tools.available_versions,
147151
)
148152
global_toolchain_versions[toolchain_version] = toolchain_info
149153
if debug_info:
@@ -252,9 +256,11 @@ def _fail_multiple_default_toolchains(first, second):
252256
second = second,
253257
))
254258

255-
def _create_toolchain_attr_structs(mod):
259+
def _process_tag_classes(mod):
256260
arg_structs = []
257261
seen_versions = {}
262+
available_versions = TOOL_VERSIONS
263+
258264
for tag in mod.tags.toolchain:
259265
arg_structs.append(_create_toolchain_attrs_struct(tag = tag, toolchain_tag_count = len(mod.tags.toolchain)))
260266
seen_versions[tag.python_version] = True
@@ -268,10 +274,14 @@ def _create_toolchain_attr_structs(mod):
268274
if register_all:
269275
arg_structs.extend([
270276
_create_toolchain_attrs_struct(python_version = v)
271-
for v in TOOL_VERSIONS.keys()
277+
for v in available_versions.keys()
272278
if v not in seen_versions
273279
])
274-
return arg_structs
280+
281+
return struct(
282+
registrations = arg_structs,
283+
available_versions = available_versions,
284+
)
275285

276286
def _create_toolchain_attrs_struct(*, tag = None, python_version = None, toolchain_tag_count = None):
277287
if tag and python_version:

0 commit comments

Comments
 (0)