Skip to content

Commit ee42fbd

Browse files
committed
revert the cleanup to debug the integration tests
1 parent fc4b246 commit ee42fbd

43 files changed

Lines changed: 404 additions & 99 deletions

Some content is hidden

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

docs/BUILD.bazel

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
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
1819
load("//python/uv:lock.bzl", "lock") # buildifier: disable=bzl-visibility
1920
load("//sphinxdocs:readthedocs.bzl", "readthedocs_install")
2021
load("//sphinxdocs:sphinx.bzl", "sphinx_build_binary", "sphinx_docs")
@@ -106,8 +107,6 @@ sphinx_stardocs(
106107
"//python/cc:py_cc_toolchain_bzl",
107108
"//python/cc:py_cc_toolchain_info_bzl",
108109
"//python/entry_points:py_console_script_binary_bzl",
109-
"//python/extensions:pip_bzl",
110-
"//python/extensions:python_bzl",
111110
"//python/local_toolchains:repos_bzl",
112111
"//python/private:attr_builders_bzl",
113112
"//python/private:builders_util_bzl",
@@ -128,7 +127,13 @@ sphinx_stardocs(
128127
"//python/uv:uv_bzl",
129128
"//python/uv:uv_toolchain_bzl",
130129
"//python/uv:uv_toolchain_info_bzl",
131-
],
130+
] + ([
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 []) + ([
134+
# This depends on @pythons_hub, which is only created under bzlmod,
135+
"//python/extensions:pip_bzl",
136+
] if IS_BAZEL_7_OR_HIGHER and BZLMOD_ENABLED else []),
132137
prefix = "api/rules_python/",
133138
tags = ["docs"],
134139
target_compatible_with = _TARGET_COMPATIBLE_WITH,

examples/bzlmod/other_module/MODULE.bazel

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ 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-
local_path_override(
9-
module_name = "rules_python",
10-
path = "../../..",
11-
)
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+
# )
1222

1323
PYTHON_NAME_39 = "python_3_9"
1424

python/BUILD.bazel

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ bzl_library(
201201
bzl_library(
202202
name = "py_runtime_pair_bzl",
203203
srcs = ["py_runtime_pair.bzl"],
204-
deps = ["//python/private:py_runtime_pair_macro_bzl"],
204+
deps = [
205+
"//python/private:bazel_tools_bzl",
206+
"//python/private:py_runtime_pair_macro_bzl",
207+
"//python/private:util_bzl",
208+
],
205209
)
206210

207211
bzl_library(

python/private/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ bzl_library(
7171
":enum_bzl",
7272
":flags_bzl",
7373
":py_info_bzl",
74+
":py_internal_bzl",
7475
":reexports_bzl",
7576
":rules_cc_srcs_bzl",
7677
"@bazel_skylib//rules:common_settings",
@@ -341,6 +342,7 @@ bzl_library(
341342
srcs = ["py_cc_link_params_info.bzl"],
342343
deps = [
343344
":rules_cc_srcs_bzl",
345+
":util_bzl",
344346
],
345347
)
346348

@@ -438,6 +440,7 @@ bzl_library(
438440
deps = [
439441
":builders_bzl",
440442
":reexports_bzl",
443+
":util_bzl",
441444
"@rules_python_internal//:rules_python_config_bzl",
442445
],
443446
)
@@ -503,6 +506,7 @@ bzl_library(
503506
bzl_library(
504507
name = "py_runtime_info_bzl",
505508
srcs = ["py_runtime_info.bzl"],
509+
deps = [":util_bzl"],
506510
)
507511

508512
bzl_library(

python/private/envsubst.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def envsubst(template_string, varnames, getenv):
2222
listed in the `varnames` list in the environment defined by the
2323
`getenv` function. Typically called with `getenv = rctx.getenv`
2424
(if it is available) or `getenv = rctx.os.environ.get` (on e.g.
25-
Bazel 7, which don't have `rctx.getenv` yet).
25+
Bazel 6 or Bazel 7, which don't have `rctx.getenv` yet).
2626
2727
Limitations: Unlike the shell, we don't support `${VARNAME}` and
2828
`${VARNAME:-default}` in the default expression for a different

python/private/internal_config_repo.bzl

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ 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"
2628
_ENABLE_DEPRECATION_WARNINGS_ENVVAR_NAME = "RULES_PYTHON_DEPRECATION_WARNINGS"
2729
_ENABLE_DEPRECATION_WARNINGS_DEFAULT = "0"
2830

@@ -86,6 +88,15 @@ _TRANSITION_SETTINGS_DEBUG_TEMPLATE = """
8688
"""
8789

8890
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+
89100
if not native.bazel_version or int(native.bazel_version.split(".")[0]) >= 8:
90101
builtin_py_info_symbol = "None"
91102
builtin_py_runtime_info_symbol = "None"
@@ -96,19 +107,33 @@ def _internal_config_repo_impl(rctx):
96107
builtin_py_cc_link_params_provider = "PyCcLinkParamsProvider"
97108

98109
rctx.file("rules_python_config.bzl", _CONFIG_TEMPLATE.format(
99-
enable_pystar = True,
110+
enable_pystar = enable_pystar,
100111
enable_pipstar = _bool_from_environ(rctx, _ENABLE_PIPSTAR_ENVVAR_NAME, _ENABLE_PIPSTAR_DEFAULT),
101112
enable_deprecation_warnings = _bool_from_environ(rctx, _ENABLE_DEPRECATION_WARNINGS_ENVVAR_NAME, _ENABLE_DEPRECATION_WARNINGS_DEFAULT),
102113
builtin_py_info_symbol = builtin_py_info_symbol,
103114
builtin_py_runtime_info_symbol = builtin_py_runtime_info_symbol,
104115
builtin_py_cc_link_params_provider = builtin_py_cc_link_params_provider,
105116
))
106117

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__"
131+
107132
rctx.file("BUILD", ROOT_BUILD_TEMPLATE.format(
108-
py_internal_dep = '"@rules_python//tools/build_defs/python/private:py_internal_renamed_bzl"',
109-
visibility = "@rules_python//:__subpackages__",
133+
py_internal_dep = py_internal_dep,
134+
visibility = visibility,
110135
))
111-
rctx.file("py_internal.bzl", _PY_INTERNAL_SHIM)
136+
rctx.file("py_internal.bzl", shim_content)
112137

113138
rctx.file(
114139
"extra_transition_settings.bzl",
@@ -130,7 +155,7 @@ def _internal_config_repo_impl(rctx):
130155
internal_config_repo = repository_rule(
131156
implementation = _internal_config_repo_impl,
132157
configure = True,
133-
environ = [_ENABLE_PIPSTAR_ENVVAR_NAME],
158+
environ = [_ENABLE_PYSTAR_ENVVAR_NAME],
134159
attrs = {
135160
"transition_setting_generators": attr.string_list_dict(),
136161
"transition_settings": attr.string_list(),

python/private/interpreter.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ interpreter_binary = rule(
7272
mandatory = True,
7373
),
7474
"_bash_runfiles": attr.label(
75-
default = "@rules_shell//shell/runfiles",
75+
default = "@bazel_tools//tools/bash/runfiles",
7676
),
7777
"_template": attr.label(
7878
default = "//python/private:interpreter_tmpl.sh",

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-
rctx.watch(origin)
74+
repo_utils.watch(rctx, 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-
rctx.watch_tree(include_path)
145+
repo_utils.watch_tree(rctx, 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-
rctx.watch(rctx.attr.interpreter_path)
271+
repo_utils.watch(rctx, 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
"""Providers for Python rules."""
1515

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

1819
def _PyCcLinkParamsInfo_init(cc_info):
1920
return {
2021
"cc_info": CcInfo(linking_context = cc_info.linking_context),
2122
}
2223

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

python/private/py_info.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
load("@rules_python_internal//:rules_python_config.bzl", "config")
1717
load(":builders.bzl", "builders")
1818
load(":reexports.bzl", "BuiltinPyInfo")
19+
load(":util.bzl", "define_bazel_6_provider")
1920

2021
def _VenvSymlinkKind_typedef():
2122
"""An enum of types of venv directories.
@@ -159,7 +160,7 @@ def _PyInfo_init(
159160
"venv_symlinks": venv_symlinks,
160161
}
161162

162-
PyInfo, _unused_raw_py_info_ctor = provider(
163+
PyInfo, _unused_raw_py_info_ctor = define_bazel_6_provider(
163164
doc = """Encapsulates information provided by the Python rules.
164165
165166
Instead of creating this object directly, use {obj}`PyInfoBuilder` and

0 commit comments

Comments
 (0)