@@ -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
8890def _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):
130155internal_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 (),
0 commit comments