Skip to content

Commit 15ca0ea

Browse files
committed
refactor: rename the remaining file
1 parent d2c43cd commit 15ca0ea

File tree

5 files changed

+80
-247
lines changed

5 files changed

+80
-247
lines changed

python/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ bzl_library(
231231
deps = [
232232
"//python/private:is_standalone_interpreter_bzl",
233233
"//python/private:py_repositories_bzl",
234+
"//python/private:python_register_multi_toolchains_bzl",
234235
"//python/private:python_register_toolchains_bzl",
235-
"//python/private:python_repositories_bzl",
236236
"//python/private:python_repository_bzl",
237237
],
238238
)

python/private/BUILD.bazel

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,12 @@ bzl_library(
189189
)
190190

191191
bzl_library(
192-
name = "python_repositories_bzl",
193-
srcs = ["python_repositories.bzl"],
192+
name = "python_register_multi_toolchains_bzl",
193+
srcs = ["python_register_multi_toolchains.bzl"],
194194
deps = [
195-
":auth_bzl",
196-
":bazel_tools_bzl",
197-
":bzlmod_enabled_bzl",
198-
":coverage_deps_bzl",
199-
":full_version_bzl",
200-
":internal_config_repo_bzl",
201-
":python_repository_bzl",
195+
":python_register_toolchains_bzl",
202196
":toolchains_repo_bzl",
203197
"//python:versions_bzl",
204-
"//python/private/pypi:deps_bzl",
205198
],
206199
)
207200

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright 2024 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""This file contains repository rules and macros to support toolchain registration.
16+
"""
17+
18+
load("//python:versions.bzl", "MINOR_MAPPING")
19+
load(":python_register_toolchains.bzl", "python_register_toolchains")
20+
load(":toolchains_repo.bzl", "multi_toolchain_aliases")
21+
22+
def python_register_multi_toolchains(
23+
name,
24+
python_versions,
25+
default_version = None,
26+
minor_mapping = None,
27+
**kwargs):
28+
"""Convenience macro for registering multiple Python toolchains.
29+
30+
Args:
31+
name: {type}`str` base name for each name in {obj}`python_register_toolchains` call.
32+
python_versions: {type}`list[str]` the Python versions.
33+
default_version: {type}`str` the default Python version. If not set,
34+
the first version in python_versions is used.
35+
minor_mapping: {type}`dict[str, str]` mapping between `X.Y` to `X.Y.Z`
36+
format. Defaults to the value in `//python:versions.bzl`.
37+
**kwargs: passed to each {obj}`python_register_toolchains` call.
38+
"""
39+
if len(python_versions) == 0:
40+
fail("python_versions must not be empty")
41+
42+
minor_mapping = minor_mapping or MINOR_MAPPING
43+
44+
if not default_version:
45+
default_version = python_versions.pop(0)
46+
for python_version in python_versions:
47+
if python_version == default_version:
48+
# We register the default version lastly so that it's not picked first when --platforms
49+
# is set with a constraint during toolchain resolution. This is due to the fact that
50+
# Bazel will match the unconstrained toolchain if we register it before the constrained
51+
# ones.
52+
continue
53+
python_register_toolchains(
54+
name = name + "_" + python_version.replace(".", "_"),
55+
python_version = python_version,
56+
set_python_version_constraint = True,
57+
minor_mapping = minor_mapping,
58+
**kwargs
59+
)
60+
python_register_toolchains(
61+
name = name + "_" + default_version.replace(".", "_"),
62+
python_version = default_version,
63+
set_python_version_constraint = False,
64+
minor_mapping = minor_mapping,
65+
**kwargs
66+
)
67+
68+
multi_toolchain_aliases(
69+
name = name,
70+
python_versions = {
71+
python_version: name + "_" + python_version.replace(".", "_")
72+
for python_version in (python_versions + [default_version])
73+
},
74+
minor_mapping = minor_mapping,
75+
)

python/private/python_repositories.bzl

Lines changed: 0 additions & 232 deletions
This file was deleted.

python/repositories.bzl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ load(
2121
_is_standalone_interpreter = "is_standalone_interpreter",
2222
)
2323
load("//python/private:py_repositories.bzl", _py_repositories = "py_repositories")
24+
load("//python/private:python_register_multi_toolchains.bzl", _python_register_multi_toolchains = "python_register_multi_toolchains")
2425
load("//python/private:python_register_toolchains.bzl", _python_register_toolchains = "python_register_toolchains")
25-
load(
26-
"//python/private:python_repositories.bzl",
27-
_python_register_multi_toolchains = "python_register_multi_toolchains",
28-
)
2926
load("//python/private:python_repository.bzl", _python_repository = "python_repository")
3027

3128
py_repositories = _py_repositories

0 commit comments

Comments
 (0)