15
15
"Python toolchain module extensions for use with bzlmod"
16
16
17
17
load ("@bazel_features//:features.bzl" , "bazel_features" )
18
- load ("//python:repositories.bzl" , "python_register_toolchains" )
19
18
load ("//python:versions.bzl" , "TOOL_VERSIONS" )
20
- load ("//python/private:repo_utils .bzl" , "repo_utils " )
19
+ load (":python_repositories .bzl" , "python_register_toolchains " )
21
20
load (":pythons_hub.bzl" , "hub_repo" )
21
+ load (":repo_utils.bzl" , "repo_utils" )
22
22
load (":text_util.bzl" , "render" )
23
23
load (":toolchains_repo.bzl" , "multi_toolchain_aliases" )
24
24
load (":util.bzl" , "IS_BAZEL_6_4_OR_HIGHER" )
@@ -28,14 +28,14 @@ load(":util.bzl", "IS_BAZEL_6_4_OR_HIGHER")
28
28
_MAX_NUM_TOOLCHAINS = 9999
29
29
_TOOLCHAIN_INDEX_PAD_LENGTH = len (str (_MAX_NUM_TOOLCHAINS ))
30
30
31
- def _python_register_toolchains (name , toolchain_attr , module , ignore_root_user_error ):
31
+ def _python_register_toolchains (name , toolchain_attr , module , ** kwargs ):
32
32
"""Calls python_register_toolchains and returns a struct used to collect the toolchains.
33
33
"""
34
34
python_register_toolchains (
35
35
name = name ,
36
36
python_version = toolchain_attr .python_version ,
37
37
register_coverage_tool = toolchain_attr .configure_coverage_tool ,
38
- ignore_root_user_error = ignore_root_user_error ,
38
+ ** kwargs
39
39
)
40
40
return struct (
41
41
python_version = toolchain_attr .python_version ,
@@ -76,9 +76,9 @@ def _python_impl(module_ctx):
76
76
for mod in module_ctx .modules :
77
77
module_toolchain_versions = []
78
78
79
- toolchain_attr_structs = _create_toolchain_attr_structs (mod )
79
+ python_tools = _process_tag_classes (mod )
80
80
81
- for toolchain_attr in toolchain_attr_structs :
81
+ for toolchain_attr in python_tools . registrations :
82
82
toolchain_version = toolchain_attr .python_version
83
83
toolchain_name = "python_" + toolchain_version .replace ("." , "_" )
84
84
@@ -144,6 +144,10 @@ def _python_impl(module_ctx):
144
144
toolchain_attr ,
145
145
module = mod ,
146
146
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 ,
147
151
)
148
152
global_toolchain_versions [toolchain_version ] = toolchain_info
149
153
if debug_info :
@@ -252,9 +256,11 @@ def _fail_multiple_default_toolchains(first, second):
252
256
second = second ,
253
257
))
254
258
255
- def _create_toolchain_attr_structs (mod ):
259
+ def _process_tag_classes (mod ):
256
260
arg_structs = []
257
261
seen_versions = {}
262
+ available_versions = TOOL_VERSIONS
263
+
258
264
for tag in mod .tags .toolchain :
259
265
arg_structs .append (_create_toolchain_attrs_struct (tag = tag , toolchain_tag_count = len (mod .tags .toolchain )))
260
266
seen_versions [tag .python_version ] = True
@@ -268,10 +274,14 @@ def _create_toolchain_attr_structs(mod):
268
274
if register_all :
269
275
arg_structs .extend ([
270
276
_create_toolchain_attrs_struct (python_version = v )
271
- for v in TOOL_VERSIONS .keys ()
277
+ for v in available_versions .keys ()
272
278
if v not in seen_versions
273
279
])
274
- return arg_structs
280
+
281
+ return struct (
282
+ registrations = arg_structs ,
283
+ available_versions = available_versions ,
284
+ )
275
285
276
286
def _create_toolchain_attrs_struct (* , tag = None , python_version = None , toolchain_tag_count = None ):
277
287
if tag and python_version :
0 commit comments