Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
18 changes: 0 additions & 18 deletions python/private/internal_config_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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"],
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 6 additions & 5 deletions python/private/py_internal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tools/build_defs/python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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__"],
)