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
9 changes: 9 additions & 0 deletions python/features.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
)
24 changes: 22 additions & 2 deletions python/private/zipapp/py_zipapp_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion python/zipapp/py_zipapp_binary.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
"""`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")

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`.
"""
Expand Down
11 changes: 10 additions & 1 deletion python/zipapp/py_zipapp_test.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
"""`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")

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`.
"""
Expand Down