Skip to content

Commit 2dadcf0

Browse files
chore(semantics): Remove 6.0 compat version flag (#701)
We don't need it on reasonable Bazels anymore, move for now to relying on the rules_python version flag which we also use in the new UV machinery. ### Changes are visible to end-users: yes - Searched for relevant documentation and updated as needed: yes - Breaking change (forces users to change their own code or config): yes - Suggested release notes appear below: yes BREAKING: Support for Bazel 6.X dropped. Bazel 7 and the Python `interpreter_version_info` machinery is now required. ### Test plan - Covered by existing test cases --------- Co-authored-by: aspect-marvin[bot] <[email protected]>
1 parent bbed6aa commit 2dadcf0

File tree

6 files changed

+3
-49
lines changed

6 files changed

+3
-49
lines changed

py/BUILD.bazel

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
load("@aspect_bazel_lib//:bzl_library.bzl", "bzl_library")
2-
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
32

4-
# For Bazel 6.x compatibility, since
5-
# PyRuntimeInfo shipped only with Bazel 7
6-
# Users can set, e.g. --@aspect_rules_py//py:interpreter_version=3.9.18
7-
string_flag(
3+
alias(
84
name = "interpreter_version",
9-
build_setting_default = "",
5+
actual = "@rules_python//python/config_settings:python_version",
106
visibility = ["//visibility:public"],
117
)
128

py/private/py_binary.bzl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,6 @@ A collision can occur when multiple packages providing the same file are install
169169
"_runfiles_lib": attr.label(
170170
default = "@bazel_tools//tools/bash/runfiles",
171171
),
172-
# NB: this is read by _resolve_toolchain in py_semantics.
173-
"_interpreter_version_flag": attr.label(
174-
default = "//py:interpreter_version",
175-
),
176172
# Required for py_version attribute
177173
"_allowlist_function_transition": attr.label(
178174
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",

py/private/py_pex_binary.bzl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ The placeholder strings `{major}`, `{minor}`, `{patch}` can be used for gatherin
156156
information from the hermetic python toolchain.
157157
""",
158158
),
159-
# NB: this is read by _resolve_toolchain in py_semantics.
160-
"_interpreter_version_flag": attr.label(
161-
default = "//py:interpreter_version",
162-
),
163159
"_pex": attr.label(executable = True, cfg = "exec", default = "//py/tools/pex"),
164160
})
165161

py/private/py_semantics.bzl

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Functions to determine which Python toolchain to use"""
22

3-
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
43
load("//py/private/toolchain:types.bzl", "PY_TOOLCHAIN")
54

65
_INTERPRETER_FLAGS = [
@@ -13,21 +12,6 @@ _INTERPRETER_FLAGS = [
1312
"-I",
1413
]
1514

16-
_MUST_SET_INTERPRETER_VERSION_FLAG = """\
17-
ERROR: Prior to Bazel 7.x, the python interpreter version must be explicitly provided.
18-
19-
For example in `.bazelrc` with Bazel 6.4, add
20-
21-
common --@aspect_rules_py//py:interpreter_version=3.9.18
22-
23-
Bazel 6.3 and earlier didn't handle the `common` verb for custom flags.
24-
Repeat the flag to avoid discarding the analysis cache:
25-
26-
build --@aspect_rules_py//py:interpreter_version=3.9.18
27-
fetch --@aspect_rules_py//py:interpreter_version=3.9.18
28-
query --@aspect_rules_py//py:interpreter_version=3.9.18
29-
"""
30-
3115
_MUST_SET_TOOLCHAIN_INTERPRETER_VERSION_INFO = """
3216
ERROR: In Bazel 7.x and later, the python toolchain py_runtime interpreter_version_info must be set \
3317
to a dict with keys "major", "minor", and "micro".
@@ -89,18 +73,8 @@ def _resolve_toolchain(ctx):
8973
if not hasattr(py3_toolchain.interpreter_version_info, attr):
9074
fail(_MUST_SET_TOOLCHAIN_INTERPRETER_VERSION_INFO)
9175
interpreter_version_info = py3_toolchain.interpreter_version_info
92-
elif ctx.attr._interpreter_version_flag[BuildSettingInfo].value:
93-
# Back-compat for Bazel 6.
94-
# Same code as rules_python:
95-
# https://github.com/bazelbuild/rules_python/blob/76f1c76f60ccb536d3b3e2c9f023d8063f40bcd5/python/repositories.bzl#L109
96-
major, minor, micro = ctx.attr._interpreter_version_flag[BuildSettingInfo].value.split(".")
97-
interpreter_version_info = struct(
98-
major = major,
99-
minor = minor,
100-
micro = micro,
101-
)
10276
else:
103-
fail(_MUST_SET_INTERPRETER_VERSION_FLAG)
77+
fail(_MUST_SET_TOOLCHAIN_INTERPRETER_VERSION_INFO)
10478

10579
return struct(
10680
toolchain = py3_toolchain,

py/private/py_unpacked_wheel.bzl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ _attrs = {
6161
allow_single_file = [".whl"],
6262
mandatory = True,
6363
),
64-
# NB: this is read by _resolve_toolchain in py_semantics.
65-
"_interpreter_version_flag": attr.label(
66-
default = "//py:interpreter_version",
67-
),
6864
}
6965

7066
py_unpacked_wheel = rule(

py/private/py_venv/py_venv.bzl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,6 @@ A collision can occur when multiple packages providing the same file are install
297297
doc = "Additional options to pass to the Python interpreter.",
298298
default = [],
299299
),
300-
# NB: this is read by _resolve_toolchain in py_semantics.
301-
"_interpreter_version_flag": attr.label(
302-
default = "//py:interpreter_version",
303-
),
304300
# Required for py_version attribute
305301
"_allowlist_function_transition": attr.label(
306302
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",

0 commit comments

Comments
 (0)