diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index efc1dd7319..ac97ef9b50 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -454,7 +454,7 @@ bzl_library( bzl_library( name = "py_internal_bzl", srcs = ["py_internal.bzl"], - deps = ["@rules_python_internal//:py_internal_bzl"], + deps = ["//tools/build_defs/python/private:py_internal_renamed_bzl"], ) bzl_library( diff --git a/python/private/internal_config_repo.bzl b/python/private/internal_config_repo.bzl index 7c59355c95..5b28d69ac9 100644 --- a/python/private/internal_config_repo.bzl +++ b/python/private/internal_config_repo.bzl @@ -42,13 +42,6 @@ config = struct( ) """ -# The py_internal symbol is only accessible from within @rules_python, so we have to -# load it from there and re-export it so that rules_python can later load it. -_PY_INTERNAL_SHIM = """ -load("@rules_python//tools/build_defs/python/private:py_internal_renamed.bzl", "py_internal_renamed") -py_internal_impl = py_internal_renamed -""" - ROOT_BUILD_TEMPLATE = """ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") @@ -63,12 +56,6 @@ bzl_library( srcs = ["rules_python_config.bzl"] ) -bzl_library( - name = "py_internal_bzl", - srcs = ["py_internal.bzl"], - deps = [{py_internal_dep}], -) - bzl_library( name = "extra_transition_settings_bzl", srcs = ["extra_transition_settings.bzl"], @@ -128,14 +115,9 @@ def _internal_config_repo_impl(rctx): bazel_10_or_later = str(bazel_major_version > 9), )) - shim_content = _PY_INTERNAL_SHIM - py_internal_dep = '"@rules_python//tools/build_defs/python/private:py_internal_renamed_bzl"' - rctx.file("BUILD", ROOT_BUILD_TEMPLATE.format( - py_internal_dep = py_internal_dep, visibility = "@rules_python//:__subpackages__", )) - rctx.file("py_internal.bzl", shim_content) rctx.file( "extra_transition_settings.bzl", diff --git a/python/private/py_internal.bzl b/python/private/py_internal.bzl index 429637253f..000501d26c 100644 --- a/python/private/py_internal.bzl +++ b/python/private/py_internal.bzl @@ -18,9 +18,10 @@ Re-exports the restricted-use py_internal helper under its original name. These may change at any time and are closely coupled to the rule implementation. """ -# The py_internal global is only available in Bazel 7+, so loading of it -# must go through a repo rule with Bazel version detection logic. -load("@rules_python_internal//:py_internal.bzl", "py_internal_impl") +# The native `py_internal` object is only visible to Starlark files under +# `tools/build_defs/python`. To access it from `//python/private`, we use an +# indirection through `//tools/build_defs/python/private/py_internal_renamed.bzl`, +# which re-exports it under a different name. +load("//tools/build_defs/python/private:py_internal_renamed.bzl", "py_internal_renamed") # buildifier: disable=bzl-visibility -# NOTE: This is None prior to Bazel 7, as set by @rules_python_internal -py_internal = py_internal_impl +py_internal = py_internal_renamed diff --git a/tools/build_defs/python/private/BUILD.bazel b/tools/build_defs/python/private/BUILD.bazel index 0a7f308f02..746545640d 100644 --- a/tools/build_defs/python/private/BUILD.bazel +++ b/tools/build_defs/python/private/BUILD.bazel @@ -23,5 +23,5 @@ filegroup( bzl_library( name = "py_internal_renamed_bzl", srcs = ["py_internal_renamed.bzl"], - visibility = ["@rules_python_internal//:__subpackages__"], + visibility = ["//python/private:__pkg__"], )