Skip to content

Commit 726ffa2

Browse files
authored
chore: cleanup bazel flags related to bazel 6 or below (#3282)
Summary: * refactor: use rules_shell runfiles lib * refactor: remove watch helpers * refactor: remove usage of select helper * refactor: make enable_pystar fixed and cleanup code * refactor: remove migration tag helper * refactor: remove is_bazel_6_or_higher * refactor: remove is_bazel_6_4_or_higher * refactor: remove is_bazel_7_or_greater * remove: is_bazel_7_4_or_greater * fix: pipstar env var is now respected * chore: drop bazel 5 support code * chore: add an override for bzlmod example * chore: remove version specific globs, since the supported versions support spaces in filenames and the file becomes redundant.
1 parent f266829 commit 726ffa2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+146
-610
lines changed

docs/BUILD.bazel

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
load("@bazel_skylib//rules:build_test.bzl", "build_test")
1616
load("@dev_pip//:requirements.bzl", "requirement")
1717
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility
18-
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
1918
load("//python/uv:lock.bzl", "lock") # buildifier: disable=bzl-visibility
2019
load("//sphinxdocs:readthedocs.bzl", "readthedocs_install")
2120
load("//sphinxdocs:sphinx.bzl", "sphinx_build_binary", "sphinx_docs")
@@ -107,6 +106,7 @@ sphinx_stardocs(
107106
"//python/cc:py_cc_toolchain_bzl",
108107
"//python/cc:py_cc_toolchain_info_bzl",
109108
"//python/entry_points:py_console_script_binary_bzl",
109+
"//python/extensions:python_bzl",
110110
"//python/local_toolchains:repos_bzl",
111111
"//python/private:attr_builders_bzl",
112112
"//python/private:builders_util_bzl",
@@ -128,12 +128,9 @@ sphinx_stardocs(
128128
"//python/uv:uv_toolchain_bzl",
129129
"//python/uv:uv_toolchain_info_bzl",
130130
] + ([
131-
# Bazel 6 + Stardoc isn't able to parse something about the python bzlmod extension
132-
"//python/extensions:python_bzl",
133-
] if IS_BAZEL_7_OR_HIGHER else []) + ([
134131
# This depends on @pythons_hub, which is only created under bzlmod,
135132
"//python/extensions:pip_bzl",
136-
] if IS_BAZEL_7_OR_HIGHER and BZLMOD_ENABLED else []),
133+
] if BZLMOD_ENABLED else []),
137134
prefix = "api/rules_python/",
138135
tags = ["docs"],
139136
target_compatible_with = _TARGET_COMPATIBLE_WITH,

examples/bzlmod/other_module/MODULE.bazel

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,10 @@ module(
55
# This module is using the same version of rules_python
66
# that the parent module uses.
77
bazel_dep(name = "rules_python", version = "")
8-
9-
# The story behind this commented out override:
10-
# This override is necessary to generate/update the requirements file
11-
# for this module. This is because running it via the outer
12-
# module doesn't work -- the `requirements.update` target can't find
13-
# the correct file to update.
14-
# Running in the submodule itself works, but submodules using overrides
15-
# is considered an error until Bazel 6.3, which prevents the outer module
16-
# from depending on this module.
17-
# So until 6.3 and higher is the minimum, we leave this commented out.
18-
# local_path_override(
19-
# module_name = "rules_python",
20-
# path = "../../..",
21-
# )
8+
local_path_override(
9+
module_name = "rules_python",
10+
path = "../../..",
11+
)
2212

2313
PYTHON_NAME_39 = "python_3_9"
2414

python/BUILD.bazel

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ bzl_library(
8181
bzl_library(
8282
name = "features_bzl",
8383
srcs = ["features.bzl"],
84-
deps = [
85-
"@rules_python_internal//:rules_python_config_bzl",
86-
],
8784
)
8885

8986
bzl_library(
@@ -130,8 +127,6 @@ bzl_library(
130127
deps = [
131128
"//python/private:py_binary_macro_bzl",
132129
"//python/private:register_extension_info_bzl",
133-
"//python/private:util_bzl",
134-
"@rules_python_internal//:rules_python_config_bzl",
135130
],
136131
)
137132

@@ -140,7 +135,6 @@ bzl_library(
140135
srcs = ["py_cc_link_params_info.bzl"],
141136
deps = [
142137
"//python/private:py_cc_link_params_info_bzl",
143-
"@rules_python_internal//:rules_python_config_bzl",
144138
],
145139
)
146140

@@ -173,8 +167,6 @@ bzl_library(
173167
srcs = ["py_info.bzl"],
174168
deps = [
175169
"//python/private:py_info_bzl",
176-
"//python/private:reexports_bzl",
177-
"@rules_python_internal//:rules_python_config_bzl",
178170
],
179171
)
180172

@@ -184,8 +176,6 @@ bzl_library(
184176
deps = [
185177
"//python/private:py_library_macro_bzl",
186178
"//python/private:register_extension_info_bzl",
187-
"//python/private:util_bzl",
188-
"@rules_python_internal//:rules_python_config_bzl",
189179
],
190180
)
191181

@@ -194,17 +184,14 @@ bzl_library(
194184
srcs = ["py_runtime.bzl"],
195185
deps = [
196186
"//python/private:py_runtime_macro_bzl",
197-
"//python/private:util_bzl",
198187
],
199188
)
200189

201190
bzl_library(
202191
name = "py_runtime_pair_bzl",
203192
srcs = ["py_runtime_pair.bzl"],
204193
deps = [
205-
"//python/private:bazel_tools_bzl",
206194
"//python/private:py_runtime_pair_macro_bzl",
207-
"//python/private:util_bzl",
208195
],
209196
)
210197

@@ -213,8 +200,6 @@ bzl_library(
213200
srcs = ["py_runtime_info.bzl"],
214201
deps = [
215202
"//python/private:py_runtime_info_bzl",
216-
"//python/private:reexports_bzl",
217-
"@rules_python_internal//:rules_python_config_bzl",
218203
],
219204
)
220205

@@ -224,8 +209,6 @@ bzl_library(
224209
deps = [
225210
"//python/private:py_test_macro_bzl",
226211
"//python/private:register_extension_info_bzl",
227-
"//python/private:util_bzl",
228-
"@rules_python_internal//:rules_python_config_bzl",
229212
],
230213
)
231214

python/features.bzl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
# limitations under the License.
1414
"""Allows detecting of rules_python features that aren't easily detected."""
1515

16-
load("@rules_python_internal//:rules_python_config.bzl", "config")
17-
1816
# This is a magic string expanded by `git archive`, as set by `.gitattributes`
1917
# See https://git-scm.com/docs/git-archive/2.29.0#Documentation/git-archive.txt-export-subst
2018
_VERSION_PRIVATE = "$Format:%(describe:tags=true)$"
@@ -73,6 +71,6 @@ features = struct(
7371
headers_abi3 = True,
7472
precompile = True,
7573
py_info_venv_symlinks = True,
76-
uses_builtin_rules = not config.enable_pystar,
74+
uses_builtin_rules = False,
7775
version = _VERSION_PRIVATE if "$Format" not in _VERSION_PRIVATE else "",
7876
)

python/private/BUILD.bazel

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,6 @@ bzl_library(
194194
srcs = ["full_version.bzl"],
195195
)
196196

197-
bzl_library(
198-
name = "glob_excludes_bzl",
199-
srcs = ["glob_excludes.bzl"],
200-
deps = [":util_bzl"],
201-
)
202-
203197
bzl_library(
204198
name = "internal_config_repo_bzl",
205199
srcs = ["internal_config_repo.bzl"],
@@ -264,7 +258,6 @@ bzl_library(
264258
":pythons_hub_bzl",
265259
":repo_utils_bzl",
266260
":toolchains_repo_bzl",
267-
":util_bzl",
268261
":version_bzl",
269262
"@bazel_features//:features",
270263
],
@@ -440,8 +433,6 @@ bzl_library(
440433
deps = [
441434
":builders_bzl",
442435
":reexports_bzl",
443-
":util_bzl",
444-
"@rules_python_internal//:rules_python_config_bzl",
445436
],
446437
)
447438

@@ -506,7 +497,6 @@ bzl_library(
506497
bzl_library(
507498
name = "py_runtime_info_bzl",
508499
srcs = ["py_runtime_info.bzl"],
509-
deps = [":util_bzl"],
510500
)
511501

512502
bzl_library(
@@ -538,7 +528,6 @@ bzl_library(
538528
":py_runtime_info_bzl",
539529
":reexports_bzl",
540530
":rule_builders_bzl",
541-
":util_bzl",
542531
"@bazel_skylib//lib:dicts",
543532
"@bazel_skylib//lib:paths",
544533
"@bazel_skylib//rules:common_settings",
@@ -688,7 +677,6 @@ bzl_library(
688677
],
689678
deps = [
690679
"@bazel_skylib//lib:types",
691-
"@rules_python_internal//:rules_python_config_bzl",
692680
],
693681
)
694682

python/private/glob_excludes.bzl

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

python/private/hermetic_runtime_repo_setup.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library")
1818
load("//python:py_runtime.bzl", "py_runtime")
1919
load("//python:py_runtime_pair.bzl", "py_runtime_pair")
2020
load("//python/cc:py_cc_toolchain.bzl", "py_cc_toolchain")
21-
load(":glob_excludes.bzl", "glob_excludes")
2221
load(":py_exec_tools_toolchain.bzl", "py_exec_tools_toolchain")
2322
load(":version.bzl", "version")
2423

@@ -82,7 +81,7 @@ def define_hermetic_runtime_toolchain_impl(
8281
"lib/python{major}.{minor}*/**/tests/**".format(**version_dict),
8382
# During pyc creation, temp files named *.pyc.NNN are created
8483
"**/__pycache__/*.pyc.*",
85-
] + glob_excludes.version_dependent_exclusions() + extra_files_glob_exclude,
84+
] + extra_files_glob_exclude,
8685
),
8786
)
8887
cc_import(

python/private/internal_config_repo.bzl

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ load(":repo_utils.bzl", "repo_utils")
2323

2424
_ENABLE_PIPSTAR_ENVVAR_NAME = "RULES_PYTHON_ENABLE_PIPSTAR"
2525
_ENABLE_PIPSTAR_DEFAULT = "0"
26-
_ENABLE_PYSTAR_ENVVAR_NAME = "RULES_PYTHON_ENABLE_PYSTAR"
27-
_ENABLE_PYSTAR_DEFAULT = "1"
2826
_ENABLE_DEPRECATION_WARNINGS_ENVVAR_NAME = "RULES_PYTHON_DEPRECATION_WARNINGS"
2927
_ENABLE_DEPRECATION_WARNINGS_DEFAULT = "0"
3028

3129
_CONFIG_TEMPLATE = """
3230
config = struct(
33-
enable_pystar = {enable_pystar},
31+
enable_pystar = True,
3432
enable_pipstar = {enable_pipstar},
3533
enable_deprecation_warnings = {enable_deprecation_warnings},
3634
BuiltinPyInfo = getattr(getattr(native, "legacy_globals", None), "PyInfo", {builtin_py_info_symbol}),
@@ -88,15 +86,6 @@ _TRANSITION_SETTINGS_DEBUG_TEMPLATE = """
8886
"""
8987

9088
def _internal_config_repo_impl(rctx):
91-
pystar_requested = _bool_from_environ(rctx, _ENABLE_PYSTAR_ENVVAR_NAME, _ENABLE_PYSTAR_DEFAULT)
92-
93-
# Bazel 7+ (dev and later) has native.starlark_doc_extract, and thus the
94-
# py_internal global, which are necessary for the pystar implementation.
95-
if pystar_requested and hasattr(native, "starlark_doc_extract"):
96-
enable_pystar = pystar_requested
97-
else:
98-
enable_pystar = False
99-
10089
if not native.bazel_version or int(native.bazel_version.split(".")[0]) >= 8:
10190
builtin_py_info_symbol = "None"
10291
builtin_py_runtime_info_symbol = "None"
@@ -107,31 +96,19 @@ def _internal_config_repo_impl(rctx):
10796
builtin_py_cc_link_params_provider = "PyCcLinkParamsProvider"
10897

10998
rctx.file("rules_python_config.bzl", _CONFIG_TEMPLATE.format(
110-
enable_pystar = enable_pystar,
11199
enable_pipstar = _bool_from_environ(rctx, _ENABLE_PIPSTAR_ENVVAR_NAME, _ENABLE_PIPSTAR_DEFAULT),
112100
enable_deprecation_warnings = _bool_from_environ(rctx, _ENABLE_DEPRECATION_WARNINGS_ENVVAR_NAME, _ENABLE_DEPRECATION_WARNINGS_DEFAULT),
113101
builtin_py_info_symbol = builtin_py_info_symbol,
114102
builtin_py_runtime_info_symbol = builtin_py_runtime_info_symbol,
115103
builtin_py_cc_link_params_provider = builtin_py_cc_link_params_provider,
116104
))
117105

118-
if enable_pystar:
119-
shim_content = _PY_INTERNAL_SHIM
120-
py_internal_dep = '"@rules_python//tools/build_defs/python/private:py_internal_renamed_bzl"'
121-
else:
122-
shim_content = "py_internal_impl = None\n"
123-
py_internal_dep = ""
124-
125-
# Bazel 5 doesn't support repository visibility, so just use public
126-
# as a stand-in
127-
if native.bazel_version.startswith("5."):
128-
visibility = "//visibility:public"
129-
else:
130-
visibility = "@rules_python//:__subpackages__"
106+
shim_content = _PY_INTERNAL_SHIM
107+
py_internal_dep = '"@rules_python//tools/build_defs/python/private:py_internal_renamed_bzl"'
131108

132109
rctx.file("BUILD", ROOT_BUILD_TEMPLATE.format(
133110
py_internal_dep = py_internal_dep,
134-
visibility = visibility,
111+
visibility = "@rules_python//:__subpackages__",
135112
))
136113
rctx.file("py_internal.bzl", shim_content)
137114

@@ -155,7 +132,7 @@ def _internal_config_repo_impl(rctx):
155132
internal_config_repo = repository_rule(
156133
implementation = _internal_config_repo_impl,
157134
configure = True,
158-
environ = [_ENABLE_PYSTAR_ENVVAR_NAME],
135+
environ = [_ENABLE_PIPSTAR_ENVVAR_NAME],
159136
attrs = {
160137
"transition_setting_generators": attr.string_list_dict(),
161138
"transition_settings": attr.string_list(),

python/private/local_runtime_repo.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def _symlink_first_library(rctx, logger, libraries):
7171
else:
7272
linked = "lib/{}".format(origin.basename)
7373
logger.debug("Symlinking {} to {}".format(origin, linked))
74-
repo_utils.watch(rctx, origin)
74+
rctx.watch(origin)
7575
rctx.symlink(origin, linked)
7676
break
7777

@@ -142,7 +142,7 @@ def _local_runtime_repo_impl(rctx):
142142
# path is an error. Silently skip, since includes are only necessary
143143
# if C extensions are built.
144144
if include_path.exists and include_path.is_dir:
145-
repo_utils.watch_tree(rctx, include_path)
145+
rctx.watch_tree(include_path)
146146
else:
147147
pass
148148

@@ -268,7 +268,7 @@ def _resolve_interpreter_path(rctx):
268268
resolved_path = result.binary
269269
describe_failure = result.describe_failure
270270
else:
271-
repo_utils.watch(rctx, rctx.attr.interpreter_path)
271+
rctx.watch(rctx.attr.interpreter_path)
272272
resolved_path = rctx.path(rctx.attr.interpreter_path)
273273
if not resolved_path.exists:
274274
describe_failure = lambda: "Path not found: {}".format(repr(rctx.attr.interpreter_path))

python/private/py_cc_link_params_info.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
"""Providers for Python rules."""
1515

1616
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
17-
load(":util.bzl", "define_bazel_6_provider")
1817

1918
def _PyCcLinkParamsInfo_init(cc_info):
2019
return {
2120
"cc_info": CcInfo(linking_context = cc_info.linking_context),
2221
}
2322

2423
# buildifier: disable=name-conventions
25-
PyCcLinkParamsInfo, _unused_raw_py_cc_link_params_provider_ctor = define_bazel_6_provider(
24+
PyCcLinkParamsInfo, _unused_raw_py_cc_link_params_provider_ctor = provider(
2625
doc = ("Python-wrapper to forward {obj}`CcInfo.linking_context`. This is to " +
2726
"allow Python targets to propagate C++ linking information, but " +
2827
"without the Python target appearing to be a valid C++ rule dependency"),

0 commit comments

Comments
 (0)