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
1 change: 1 addition & 0 deletions .bazelrc.deleted_packages
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ common --deleted_packages=examples/bzlmod/entry_points/tests
common --deleted_packages=examples/bzlmod/libs/my_lib
common --deleted_packages=examples/bzlmod/other_module
common --deleted_packages=examples/bzlmod/other_module/other_module/pkg
common --deleted_packages=examples/bzlmod/other_module/other_module/rule_builder
common --deleted_packages=examples/bzlmod/patches
common --deleted_packages=examples/bzlmod/runfiles
common --deleted_packages=examples/bzlmod/tests
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ BEGIN_UNRELEASED_TEMPLATE
END_UNRELEASED_TEMPLATE
-->

{#v1-9-2}
## [1.9.2] - 2026-07-28

[1.9.2]: https://github.com/bazel-contrib/rules_python/releases/tag/1.9.2

{#v1-9-2-fixed}
### Fixed
* (executables) `py_binary_rule_builder()` / `py_test_rule_builder()` (from
`python/api/executables.bzl`) no longer fail at analysis time with a
visibility error when used to construct a custom rule from an external
module. Fixes
([#3919](https://github.com/bazel-contrib/rules_python/pull/3919)).

{#v1-9-1}
## [1.9.1] - 2026-05-14

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load(":rule.bzl", "custom_py_binary")

# This target's mere existence is the regression test: analyzing it exercises
# the implicit attr defaults (build_data_writer, debugger_if_target_config,
# uncachable_version_file) that py_binary_rule_builder() bundles from
# rules_python's private package, from a rule() call made in this external
# module.
custom_py_binary(
name = "app",
srcs = ["app.py"],
main = "app.py",
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("hello from a rule built via py_binary_rule_builder()")
17 changes: 17 additions & 0 deletions examples/bzlmod/other_module/other_module/rule_builder/rule.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""A minimal custom py_binary built via the executables rule builder API.

Regression coverage for https://github.com/bazel-contrib/rules_python/pull/3919:
py_binary_rule_builder()'s implicit attr defaults (build_data_writer,
debugger_if_target_config, uncachable_version_file) previously had no
visibility outside of rules_python, so any external module (like this one)
constructing a rule via the builder failed at analysis time with a
visibility error.
"""

load("@rules_python//python/api:executables.bzl", "executables")

def _make_rule():
builder = executables.py_binary_rule_builder()
return builder.build()

custom_py_binary = _make_rule()
11 changes: 11 additions & 0 deletions examples/bzlmod/tests/other_module/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@ build_test(
"@our_other_module//other_module/pkg:bin",
],
)

# Regression test for https://github.com/bazel-contrib/rules_python/pull/3919: py_binary_rule_builder()'s implicit
# attr defaults previously had no visibility outside of rules_python, so
# building this target (defined via the builder from an external module)
# failed at analysis time with a visibility error.
build_test(
name = "other_module_rule_builder_build_test",
targets = [
"@our_other_module//other_module/rule_builder:app",
],
)
17 changes: 17 additions & 0 deletions python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ alias(
"@platforms//os:windows": ":build_data_writer.ps1",
"//conditions:default": ":build_data_writer.sh",
}),
# Not actually public. Only public because it's an implicit dependency of
# rules built via py_binary_rule_builder() / py_test_rule_builder().
visibility = ["//visibility:public"],
)

bzl_library(
Expand Down Expand Up @@ -700,6 +703,9 @@ bzl_library(

define_uncachable_version_file(
name = "uncachable_version_file",
# Not actually public. Only public because it's an implicit dependency of
# rules built via py_binary_rule_builder() / py_test_rule_builder().
visibility = ["//visibility:public"],
)

bzl_library(
Expand Down Expand Up @@ -837,6 +843,9 @@ alias(
":is_bazel_config_mode_target": "//python/config_settings:debugger",
"//conditions:default": "//python/private:empty",
}),
# Not actually public. Only public because it's an implicit dependency of
# rules built via py_binary_rule_builder() / py_test_rule_builder().
visibility = ["//visibility:public"],
)

bazel_config_mode(name = "bazel_config_mode")
Expand Down Expand Up @@ -888,8 +897,16 @@ current_interpreter_executable(

py_library(
name = "empty",
# Not actually public. Only public because it's the resolved default of
# debugger_if_target_config, an implicit dependency of rules built via
# py_binary_rule_builder() / py_test_rule_builder().
visibility = ["//visibility:public"],
)

sentinel(
name = "sentinel",
# Not actually public. Only public because it's the resolved default of
# uncachable_version_file, an implicit dependency of rules built via
# py_binary_rule_builder() / py_test_rule_builder().
visibility = ["//visibility:public"],
)
3 changes: 2 additions & 1 deletion python/private/uncachable_version_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ actions depending on this file will always re-run.
implementation = _uncachable_version_file_impl,
)

def define_uncachable_version_file(name):
def define_uncachable_version_file(name, visibility = None):
native.alias(
name = name,
actual = select({
":stamp_detect": ":uncachable_version_file_impl",
"//conditions:default": ":sentinel",
}),
visibility = visibility,
)
uncachable_version_file(name = "uncachable_version_file_impl")