From d54dc2243a20f5333318f5a3fcbca7bdf50e6db2 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 6 Feb 2026 20:21:18 -0800 Subject: [PATCH 1/2] feat(zipapp): Add python_zip_file output group for better compatibility --- python/features.bzl | 9 +++++++++ python/private/zipapp/py_zipapp_rule.bzl | 24 ++++++++++++++++++++++-- python/zipapp/py_zipapp_binary.bzl | 3 +++ python/zipapp/py_zipapp_test.bzl | 3 +++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/python/features.bzl b/python/features.bzl index 291de33d1a..4cc9436677 100644 --- a/python/features.bzl +++ b/python/features.bzl @@ -63,6 +63,14 @@ def _features_typedef(): optional trailing `-rcN`. For unreleased versions, it is an empty string. :::{versionadded} 0.38.0 :::: + + ::::{field} zipapp_rules + :type: bool + + Whether the rules_python version has the `py_zipapp_*` rules + + :::{versionadded} VERSION_NEXT_FEATURE + :::: """ features = struct( @@ -73,4 +81,5 @@ features = struct( py_info_venv_symlinks = True, uses_builtin_rules = False, version = _VERSION_PRIVATE if "$Format" not in _VERSION_PRIVATE else "", + zipapp_rules = True, ) diff --git a/python/private/zipapp/py_zipapp_rule.bzl b/python/private/zipapp/py_zipapp_rule.bzl index a0f0df943f..e97e1a4171 100644 --- a/python/private/zipapp/py_zipapp_rule.bzl +++ b/python/private/zipapp/py_zipapp_rule.bzl @@ -218,6 +218,9 @@ def _py_zipapp_executable_impl(ctx): runfiles = ctx.runfiles(files = default_outputs), executable = executable, ), + OutputGroupInfo( + python_zip_file = depset([zip_file]), + ), ] def _transition_zipapp_impl(settings, attr): @@ -325,10 +328,25 @@ Whether the output should be an executable zip file. _TOOLCHAINS = [EXEC_TOOLS_TOOLCHAIN_TYPE] + ([LAUNCHER_MAKER_TOOLCHAIN_TYPE] if rp_config.bazel_9_or_later else []) +_COMMON_RULE_DOC = """ + +Output groups: + +* `python_zip_file`: (*deprecated*) The plain, non-self-executable zipapp zipfile. + *This output group is deprecated and retained for compatibility with + the previous implicit zipapp functionality. Set `executable=False` + and use the default output of the target instead.* + +:::{versionadded} VERSION_NEXT_FEATURE +::: +""".lstrip() + py_zipapp_binary = rule( doc = """ Packages a `py_binary` as a Python zipapp. -""", + +{} +""".format(_COMMON_RULE_DOC), implementation = _py_zipapp_executable_impl, attrs = _ATTRS, # NOTE: While this is marked executable, it is conditionally executable @@ -343,7 +361,9 @@ py_zipapp_test = rule( Packages a `py_test` as a Python zipapp. This target is also a valid test target to run. -""", + +{} +""".format(_COMMON_RULE_DOC), implementation = _py_zipapp_executable_impl, attrs = _ATTRS, # NOTE: While this is marked as a test, it is conditionally executable diff --git a/python/zipapp/py_zipapp_binary.bzl b/python/zipapp/py_zipapp_binary.bzl index 4c40786200..38eefcc9c9 100644 --- a/python/zipapp/py_zipapp_binary.bzl +++ b/python/zipapp/py_zipapp_binary.bzl @@ -6,6 +6,9 @@ load("//python/private/zipapp:py_zipapp_rule.bzl", _py_zipapp_binary_rule = "py_ def py_zipapp_binary(**kwargs): """Builds a Python zipapp from a py_binary/py_test target. + :::{versionadded} VERSION_NEXT_FEATURE + ::: + Args: **kwargs: Args passed onto {rule}`py_zipapp_binary`. """ diff --git a/python/zipapp/py_zipapp_test.bzl b/python/zipapp/py_zipapp_test.bzl index bc113ad4ed..9bc7b86313 100644 --- a/python/zipapp/py_zipapp_test.bzl +++ b/python/zipapp/py_zipapp_test.bzl @@ -6,6 +6,9 @@ load("//python/private/zipapp:py_zipapp_rule.bzl", _py_zipapp_test = "py_zipapp_ def py_zipapp_test(**kwargs): """Builds a Python zipapp from a py_binary/py_test target. + :::{versionadded} VERSION_NEXT_FEATURE + ::: + Args: **kwargs: Args passed onto {rule}`py_zipapp_test`. """ From fa2da1bd45eab71254d12498974e7ab20cdd611e Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sat, 7 Feb 2026 09:34:56 -0800 Subject: [PATCH 2/2] mention features in rule doc --- python/zipapp/py_zipapp_binary.bzl | 8 +++++++- python/zipapp/py_zipapp_test.bzl | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/python/zipapp/py_zipapp_binary.bzl b/python/zipapp/py_zipapp_binary.bzl index 38eefcc9c9..ba7652c6d4 100644 --- a/python/zipapp/py_zipapp_binary.bzl +++ b/python/zipapp/py_zipapp_binary.bzl @@ -1,4 +1,10 @@ -"""`py_zipapp_binary` macro.""" +"""`py_zipapp_binary` macro. + +:::{seealso} + +{obj}`features.zipapp_rules` to detect if this rule is available. +::: +""" load("//python/private:util.bzl", "add_tag") load("//python/private/zipapp:py_zipapp_rule.bzl", _py_zipapp_binary_rule = "py_zipapp_binary") diff --git a/python/zipapp/py_zipapp_test.bzl b/python/zipapp/py_zipapp_test.bzl index 9bc7b86313..fa197701a9 100644 --- a/python/zipapp/py_zipapp_test.bzl +++ b/python/zipapp/py_zipapp_test.bzl @@ -1,4 +1,10 @@ -"""`py_zipapp_test` macro.""" +"""`py_zipapp_test` macro. + +:::{seealso} + +{obj}`features.zipapp_rules` to detect if this rule is available. +::: +""" load("//python/private:util.bzl", "add_tag") load("//python/private/zipapp:py_zipapp_rule.bzl", _py_zipapp_test = "py_zipapp_test")