Skip to content

Commit f8fdce9

Browse files
committed
remove the bazel.7 conditionals but leave bazel 7.4 conditionals
1 parent 2dc82cc commit f8fdce9

12 files changed

Lines changed: 39 additions & 88 deletions

File tree

python/private/py_runtime_pair_rule.bzl

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@
1717
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
1818
load("//python:py_runtime_info.bzl", "PyRuntimeInfo")
1919
load(":common_labels.bzl", "labels")
20-
load(":reexports.bzl", "BuiltinPyRuntimeInfo")
21-
load(":util.bzl", "IS_BAZEL_7_OR_HIGHER")
2220

2321
def _py_runtime_pair_impl(ctx):
2422
if ctx.attr.py2_runtime != None:
25-
py2_runtime = _get_py_runtime_info(ctx.attr.py2_runtime)
23+
py2_runtime = ctx.attr.py2_runtime[PyRuntimeInfo]
2624
if py2_runtime.python_version != "PY2":
2725
fail("The Python runtime in the 'py2_runtime' attribute did not have " +
2826
"version 'PY2'")
2927
else:
3028
py2_runtime = None
3129

3230
if ctx.attr.py3_runtime != None:
33-
py3_runtime = _get_py_runtime_info(ctx.attr.py3_runtime)
31+
py3_runtime = ctx.attr.py3_runtime[PyRuntimeInfo]
3432
if py3_runtime.python_version != "PY3":
3533
fail("The Python runtime in the 'py3_runtime' attribute did not have " +
3634
"version 'PY3'")
@@ -52,42 +50,30 @@ def _py_runtime_pair_impl(ctx):
5250
**extra_kwargs
5351
)]
5452

55-
def _get_py_runtime_info(target):
56-
# Prior to Bazel 7, the builtin PyRuntimeInfo object must be used because
57-
# py_binary (implemented in Java) performs a type check on the provider
58-
# value to verify it is an instance of the Java-implemented PyRuntimeInfo
59-
# class.
60-
if (IS_BAZEL_7_OR_HIGHER and PyRuntimeInfo in target) or BuiltinPyRuntimeInfo == None:
61-
return target[PyRuntimeInfo]
62-
else:
63-
return target[BuiltinPyRuntimeInfo]
64-
6553
# buildifier: disable=unused-variable
6654
def _is_py2_disabled(ctx):
6755
# Because this file isn't bundled with Bazel, so we have to conditionally
6856
# check for this flag.
69-
# TODO: Remove this once all supported Balze versions have this flag.
57+
# TODO: Remove this once all supported Blaze versions have this flag.
7058
if not hasattr(ctx.fragments.py, "disable_py"):
7159
return False
7260
return ctx.fragments.py.disable_py2
7361

74-
_MaybeBuiltinPyRuntimeInfo = [[BuiltinPyRuntimeInfo]] if BuiltinPyRuntimeInfo != None else []
75-
7662
py_runtime_pair = rule(
7763
implementation = _py_runtime_pair_impl,
7864
attrs = {
7965
# The two runtimes are used by the py_binary at runtime, and so need to
8066
# be built for the target platform.
8167
"py2_runtime": attr.label(
82-
providers = [[PyRuntimeInfo]] + _MaybeBuiltinPyRuntimeInfo,
68+
providers = [[PyRuntimeInfo]],
8369
cfg = "target",
8470
doc = """\
8571
The runtime to use for Python 2 targets. Must have `python_version` set to
8672
`PY2`.
8773
""",
8874
),
8975
"py3_runtime": attr.label(
90-
providers = [[PyRuntimeInfo]] + _MaybeBuiltinPyRuntimeInfo,
76+
providers = [[PyRuntimeInfo]],
9177
cfg = "target",
9278
doc = """\
9379
The runtime to use for Python 3 targets. Must have `python_version` set to

python/private/py_runtime_rule.bzl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ load(":common_labels.bzl", "labels")
2020
load(":flags.bzl", "FreeThreadedFlag")
2121
load(":py_runtime_info.bzl", "DEFAULT_STUB_SHEBANG", "PyRuntimeInfo")
2222
load(":reexports.bzl", "BuiltinPyRuntimeInfo")
23-
load(":util.bzl", "IS_BAZEL_7_OR_HIGHER")
2423

2524
def _py_runtime_impl(ctx):
2625
interpreter_path = ctx.attr.interpreter_path or None # Convert empty string to None
@@ -130,9 +129,6 @@ def _py_runtime_impl(ctx):
130129
supports_build_time_venv = ctx.attr.supports_build_time_venv,
131130
))
132131

133-
if not IS_BAZEL_7_OR_HIGHER:
134-
builtin_py_runtime_info_kwargs.pop("bootstrap_template")
135-
136132
providers = [
137133
PyRuntimeInfo(**py_runtime_info_kwargs),
138134
DefaultInfo(

python/private/util.bzl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,3 @@ def add_tag(attrs, tag):
8787
attrs["tags"] = [tag]
8888

8989
IS_BAZEL_7_4_OR_HIGHER = hasattr(native, "legacy_globals")
90-
91-
IS_BAZEL_7_OR_HIGHER = hasattr(native, "starlark_doc_extract")

sphinxdocs/tests/proto_to_markdown/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
# limitations under the License.
1414

1515
load("//python:py_test.bzl", "py_test")
16-
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
1716

1817
py_test(
1918
name = "proto_to_markdown_test",
2019
srcs = ["proto_to_markdown_test.py"],
21-
target_compatible_with = [] if IS_BAZEL_7_OR_HIGHER else ["@platforms//:incompatible"],
2220
deps = [
2321
"//sphinxdocs/private:proto_to_markdown_lib",
2422
"@dev_pip//absl_py",

sphinxdocs/tests/sphinx_docs/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
load("@bazel_skylib//rules:build_test.bzl", "build_test")
2-
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
32
load("//sphinxdocs:sphinx.bzl", "sphinx_build_binary", "sphinx_docs")
43
load(":defs.bzl", "gen_directory")
54

@@ -13,7 +12,7 @@ _TARGET_COMPATIBLE_WITH = select({
1312
"@platforms//os:linux": [],
1413
"@platforms//os:macos": [],
1514
"//conditions:default": ["@platforms//:incompatible"],
16-
}) if IS_BAZEL_7_OR_HIGHER else ["@platforms//:incompatible"]
15+
})
1716

1817
sphinx_docs(
1918
name = "docs",

sphinxdocs/tests/sphinx_stardoc/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22
load("@bazel_skylib//rules:build_test.bzl", "build_test")
33
load("//python:py_test.bzl", "py_test")
4-
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
54
load("//sphinxdocs:sphinx.bzl", "sphinx_build_binary", "sphinx_docs")
65
load("//sphinxdocs:sphinx_stardoc.bzl", "sphinx_stardoc", "sphinx_stardocs")
76

@@ -15,7 +14,7 @@ _TARGET_COMPATIBLE_WITH = select({
1514
"@platforms//os:linux": [],
1615
"@platforms//os:macos": [],
1716
"//conditions:default": ["@platforms//:incompatible"],
18-
}) if IS_BAZEL_7_OR_HIGHER else ["@platforms//:incompatible"]
17+
})
1918

2019
sphinx_docs(
2120
name = "docs",

tests/base_rules/py_executable_base_tests.bzl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ load("@rules_testing//lib:util.bzl", rt_util = "util")
2121
load("//python:py_executable_info.bzl", "PyExecutableInfo")
2222
load("//python/private:common_labels.bzl", "labels") # buildifier: disable=bzl-visibility
2323
load("//python/private:reexports.bzl", "BuiltinPyRuntimeInfo") # buildifier: disable=bzl-visibility
24-
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
2524
load("//tests/base_rules:base_tests.bzl", "create_base_tests")
2625
load("//tests/base_rules:util.bzl", "WINDOWS_ATTR", pt_util = "util")
2726
load("//tests/support:py_executable_info_subject.bzl", "PyExecutableInfoSubject")
@@ -295,15 +294,14 @@ def _test_files_to_build_impl(env, target):
295294
"{package}/{test_name}_subject.py",
296295
])
297296

298-
if IS_BAZEL_7_OR_HIGHER:
299-
# As of Bazel 7, the first default output is the executable, so
300-
# verify that is the case. rules_testing
301-
# DepsetFileSubject.contains_exactly doesn't provide an in_order()
302-
# call, nor access to the underlying depset, so we have to do things
303-
# manually.
304-
first_default_output = target[DefaultInfo].files.to_list()[0]
305-
executable = target[DefaultInfo].files_to_run.executable
306-
env.expect.that_file(first_default_output).equals(executable)
297+
# As of Bazel 7, the first default output is the executable, so
298+
# verify that is the case. rules_testing
299+
# DepsetFileSubject.contains_exactly doesn't provide an in_order()
300+
# call, nor access to the underlying depset, so we have to do things
301+
# manually.
302+
first_default_output = target[DefaultInfo].files.to_list()[0]
303+
executable = target[DefaultInfo].files_to_run.executable
304+
env.expect.that_file(first_default_output).equals(executable)
307305

308306
def _test_name_cannot_end_in_py(name, config):
309307
rt_util.helper_target(

tests/bootstrap_impls/a/b/c/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
21
load("//tests/support:py_reconfig.bzl", "py_reconfig_test")
32

43
_SUPPORTS_BOOTSTRAP_SCRIPT = select({
54
"@platforms//os:windows": ["@platforms//:incompatible"],
65
"//conditions:default": [],
7-
}) if IS_BAZEL_7_OR_HIGHER else ["@platforms//:incompatible"]
6+
})
87

98
py_reconfig_test(
109
name = "nested_dir_test",

tests/config_settings/transition/multi_version_tests.bzl

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
load("@pythons_hub//:versions.bzl", "DEFAULT_PYTHON_VERSION")
1717
load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
1818
load("@rules_testing//lib:test_suite.bzl", "test_suite")
19-
load("@rules_testing//lib:util.bzl", "TestingAspectInfo", rt_util = "util")
19+
load("@rules_testing//lib:util.bzl", rt_util = "util")
2020
load("//python:py_binary.bzl", "py_binary")
2121
load("//python:py_info.bzl", "PyInfo")
2222
load("//python:py_test.bzl", "py_test")
2323
load("//python/private:reexports.bzl", "BuiltinPyInfo") # buildifier: disable=bzl-visibility
24-
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
2524
load("//tests/support:support.bzl", "CC_TOOLCHAIN")
2625

2726
# NOTE @aignas 2024-06-04: we are using here something that is registered in the MODULE.Bazel
@@ -105,21 +104,14 @@ def _test_py_binary_windows_build_python_zip_false(name):
105104
)
106105

107106
def _test_py_binary_windows_build_python_zip_false_impl(env, target):
108-
default_outputs = env.expect.that_target(target).default_outputs()
109-
if IS_BAZEL_7_OR_HIGHER:
110-
# TODO: These outputs aren't correct. The outputs shouldn't
111-
# have the "_" prefix on them (those are coming from the underlying
112-
# wrapped binary).
113-
env.expect.that_target(target).default_outputs().contains_exactly([
114-
"{package}/{test_name}_subject.exe",
115-
"{package}/{test_name}_subject",
116-
"{package}/{test_name}_subject.py",
117-
])
118-
else:
119-
inner_exe = target[TestingAspectInfo].attrs.target[DefaultInfo].files_to_run.executable
120-
default_outputs.contains_at_least([
121-
inner_exe.short_path,
122-
])
107+
# TODO: These outputs aren't correct. The outputs shouldn't
108+
# have the "_" prefix on them (those are coming from the underlying
109+
# wrapped binary).
110+
env.expect.that_target(target).default_outputs().contains_exactly([
111+
"{package}/{test_name}_subject.exe",
112+
"{package}/{test_name}_subject",
113+
"{package}/{test_name}_subject.py",
114+
])
123115

124116
_tests.append(_test_py_binary_windows_build_python_zip_false)
125117

@@ -132,21 +124,15 @@ def _test_py_binary_windows_build_python_zip_true(name):
132124

133125
def _test_py_binary_windows_build_python_zip_true_impl(env, target):
134126
default_outputs = env.expect.that_target(target).default_outputs()
135-
if IS_BAZEL_7_OR_HIGHER:
136-
# TODO: These outputs aren't correct. The outputs shouldn't
137-
# have the "_" prefix on them (those are coming from the underlying
138-
# wrapped binary).
139-
default_outputs.contains_exactly([
140-
"{package}/{test_name}_subject.exe",
141-
"{package}/{test_name}_subject.py",
142-
"{package}/{test_name}_subject.zip",
143-
])
144-
else:
145-
inner_exe = target[TestingAspectInfo].attrs.target[DefaultInfo].files_to_run.executable
146-
default_outputs.contains_at_least([
147-
"{package}/{test_name}_subject.zip",
148-
inner_exe.short_path,
149-
])
127+
128+
# TODO: These outputs aren't correct. The outputs shouldn't
129+
# have the "_" prefix on them (those are coming from the underlying
130+
# wrapped binary).
131+
default_outputs.contains_exactly([
132+
"{package}/{test_name}_subject.exe",
133+
"{package}/{test_name}_subject.py",
134+
"{package}/{test_name}_subject.zip",
135+
])
150136

151137
_tests.append(_test_py_binary_windows_build_python_zip_true)
152138

tests/exec_toolchain_matching/exec_toolchain_matching_tests.bzl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ load("//python:py_runtime.bzl", "py_runtime")
2020
load("//python:py_runtime_pair.bzl", "py_runtime_pair")
2121
load("//python/private:common_labels.bzl", "labels") # buildifier: disable=bzl-visibility
2222
load("//python/private:toolchain_types.bzl", "EXEC_TOOLS_TOOLCHAIN_TYPE", "TARGET_TOOLCHAIN_TYPE") # buildifier: disable=bzl-visibility
23-
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
2423
load("//tests/support:support.bzl", "LINUX", "MAC")
2524

2625
_LookupInfo = provider() # buildifier: disable=provider-params
@@ -143,11 +142,10 @@ def _test_exec_matches_target_python_version_impl(env, target):
143142
env.expect.that_str(target_runtime.interpreter_path).equals("/linux/python3.12")
144143
env.expect.that_str(exec_runtime.interpreter_path).equals("/mac/python3.12")
145144

146-
if IS_BAZEL_7_OR_HIGHER:
147-
target_version = target_runtime.interpreter_version_info
148-
exec_version = exec_runtime.interpreter_version_info
145+
target_version = target_runtime.interpreter_version_info
146+
exec_version = exec_runtime.interpreter_version_info
149147

150-
env.expect.that_bool(target_version == exec_version)
148+
env.expect.that_bool(target_version == exec_version)
151149

152150
def exec_toolchain_matching_test_suite(name):
153151
test_suite(name = name, tests = _tests)

0 commit comments

Comments
 (0)