Skip to content

Commit 786ee48

Browse files
authored
internal(pystar): Only respect RULES_PYTHON_ENABLE_PYSTAR env var for Bazel 7+ (#1698)
Respecting it for earlier versions was only done for testing purposes. The implementation requires the `py_internal` object, which only exists on Bazel 7 and higher. Work towards #1069
1 parent 8fcc783 commit 786ee48

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

python/private/internal_config_repo.bzl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ such as globals available to Bazel versions, or propagating user environment
1818
settings for rules to later use.
1919
"""
2020

21-
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED")
22-
2321
_ENABLE_PYSTAR_ENVVAR_NAME = "RULES_PYTHON_ENABLE_PYSTAR"
2422
_ENABLE_PYSTAR_DEFAULT = "0"
2523

@@ -58,18 +56,20 @@ bzl_library(
5856
"""
5957

6058
def _internal_config_repo_impl(rctx):
61-
enable_pystar = _bool_from_environ(rctx, _ENABLE_PYSTAR_ENVVAR_NAME, _ENABLE_PYSTAR_DEFAULT)
59+
pystar_requested = _bool_from_environ(rctx, _ENABLE_PYSTAR_ENVVAR_NAME, _ENABLE_PYSTAR_DEFAULT)
60+
61+
# Bazel 7+ (dev and later) has native.starlark_doc_extract, and thus the
62+
# py_internal global, which are necessary for the pystar implementation.
63+
if pystar_requested and hasattr(native, "starlark_doc_extract"):
64+
enable_pystar = pystar_requested
65+
else:
66+
enable_pystar = False
67+
6268
rctx.file("rules_python_config.bzl", _CONFIG_TEMPLATE.format(
6369
enable_pystar = enable_pystar,
6470
))
6571

66-
if enable_pystar or (
67-
# Bazel 7+ (dev and later) has native.starlark_doc_extract, and thus the py_internal global
68-
hasattr(native, "starlark_doc_extract") and
69-
# The logic to allow the symbol doesn't work properly under bzlmod,
70-
# even if the symbol is otherwise functional.
71-
not BZLMOD_ENABLED
72-
):
72+
if enable_pystar:
7373
shim_content = _PY_INTERNAL_SHIM
7474
py_internal_dep = '"@rules_python//tools/build_defs/python/private:py_internal_renamed_bzl"'
7575
else:

0 commit comments

Comments
 (0)