Skip to content

Commit 6cbe12a

Browse files
committed
move some of the constants to a versions.bzl for better naming
1 parent 6a9a53f commit 6cbe12a

File tree

8 files changed

+31
-14
lines changed

8 files changed

+31
-14
lines changed

WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ load("//:internal_setup.bzl", "rules_python_internal_setup")
4141

4242
rules_python_internal_setup()
4343

44-
load("@pythons_hub//:interpreters.bzl", "MINOR_MAPPING", "PYTHON_VERSIONS")
44+
load("@pythons_hub//:versions.bzl", "MINOR_MAPPING", "PYTHON_VERSIONS")
4545
load("//python:repositories.bzl", "python_register_multi_toolchains")
4646

4747
python_register_multi_toolchains(

examples/bzlmod/MODULE.bazel.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/bzlmod/tests/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
load("@python_versions//3.10:defs.bzl", py_binary_3_10 = "py_binary", py_test_3_10 = "py_test")
22
load("@python_versions//3.11:defs.bzl", py_binary_3_11 = "py_binary", py_test_3_11 = "py_test")
33
load("@python_versions//3.9:defs.bzl", py_binary_3_9 = "py_binary", py_test_3_9 = "py_test")
4-
load("@pythons_hub//:interpreters.bzl", "MINOR_MAPPING")
4+
load("@pythons_hub//:versions.bzl", "MINOR_MAPPING")
55
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
66
load("@rules_python//python/config_settings:transition.bzl", py_versioned_binary = "py_binary", py_versioned_test = "py_test")
77

python/config_settings/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
2-
load("@pythons_hub//:interpreters.bzl", "DEFAULT_PYTHON_VERSION", "MINOR_MAPPING", "PYTHON_VERSIONS")
2+
load("@pythons_hub//:versions.bzl", "DEFAULT_PYTHON_VERSION", "MINOR_MAPPING", "PYTHON_VERSIONS")
33
load(
44
"//python/private:flags.bzl",
55
"BootstrapImplFlag",

python/private/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ bzl_library(
175175
":internal_config_repo_bzl",
176176
":python_repository_bzl",
177177
":toolchains_repo_bzl",
178-
"//python:versions_bzl",
179178
"//python/private/pypi:deps_bzl",
179+
"@pythons_hub//:versions_bzl",
180180
],
181181
)
182182

python/private/pypi/BUILD.bazel

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
16-
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED")
1716

1817
package(default_visibility = ["//:__subpackages__"])
1918

@@ -59,22 +58,21 @@ bzl_library(
5958
srcs = ["extension.bzl"],
6059
deps = [
6160
":attrs_bzl",
61+
":evaluate_markers_bzl",
6262
":hub_repository_bzl",
6363
":parse_requirements_bzl",
64-
":evaluate_markers_bzl",
6564
":parse_whl_name_bzl",
6665
":pip_repository_attrs_bzl",
6766
":simpleapi_download_bzl",
6867
":whl_library_bzl",
6968
":whl_repo_name_bzl",
7069
"//python/private:full_version_bzl",
7170
"//python/private:normalize_name_bzl",
72-
"//python/private:version_label_bzl",
7371
"//python/private:semver_bzl",
72+
"//python/private:version_label_bzl",
7473
"@bazel_features//:features",
75-
] + [
7674
"@pythons_hub//:interpreters_bzl",
77-
] if BZLMOD_ENABLED else [],
75+
],
7876
)
7977

8078
bzl_library(

python/private/python_register_multi_toolchains.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""This file contains repository rules and macros to support toolchain registration.
1616
"""
1717

18-
load("@pythons_hub//:interpreters.bzl", "MINOR_MAPPING")
18+
load("@pythons_hub//:versions.bzl", "MINOR_MAPPING")
1919
load(":python_register_toolchains.bzl", "python_register_toolchains")
2020
load(":toolchains_repo.bzl", "multi_toolchain_aliases")
2121

python/private/pythons_hub.bzl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ bzl_library(
3232
visibility = ["@rules_python//:__subpackages__"],
3333
)
3434
35+
bzl_library(
36+
name = "versions_bzl",
37+
srcs = ["versions.bzl"],
38+
visibility = ["@rules_python//:__subpackages__"],
39+
)
40+
3541
{toolchains}
3642
"""
3743

@@ -74,14 +80,18 @@ INTERPRETER_LABELS = {{
7480
{interpreter_labels}
7581
}}
7682
DEFAULT_PYTHON_VERSION = "{default_python_version}"
77-
MINOR_MAPPING = {minor_mapping}
78-
PYTHON_VERSIONS = {python_versions}
7983
"""
8084

8185
_line_for_hub_template = """\
8286
"{name}_host": Label("@{name}_host//:python"),
8387
"""
8488

89+
_versions_bzl_template = """
90+
DEFAULT_PYTHON_VERSION = "{default_python_version}"
91+
MINOR_MAPPING = {minor_mapping}
92+
PYTHON_VERSIONS = {python_versions}
93+
"""
94+
8595
def _hub_repo_impl(rctx):
8696
# Create the various toolchain definitions and
8797
# write them to the BUILD file.
@@ -107,8 +117,17 @@ def _hub_repo_impl(rctx):
107117
rctx.file(
108118
"interpreters.bzl",
109119
_interpreters_bzl_template.format(
120+
# TODO @aignas 2024-09-28: before 1.0 remove the value from here
110121
default_python_version = rctx.attr.default_python_version,
111122
interpreter_labels = interpreter_labels,
123+
),
124+
executable = False,
125+
)
126+
127+
rctx.file(
128+
"versions.bzl",
129+
_versions_bzl_template.format(
130+
default_python_version = rctx.attr.default_python_version,
112131
minor_mapping = render.dict(rctx.attr.minor_mapping),
113132
python_versions = rctx.attr.python_versions or render.list(sorted({
114133
v: None

0 commit comments

Comments
 (0)