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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ END_UNRELEASED_TEMPLATE

{#v0-0-0-changed}
### Changed
* **DEPRECATED: implicit zipapp support**
* Implicit zipapp output of `py_binary`/`py_test` has been deprecated and
replaced by separate {obj}`py_zipapp_binary` and {obj}`py_zipapp_test`
rules. See
[#3567](https://github.com/bazel-contrib/rules_python/issues/3567)
for a detailed migration guide.
* (toolchains) stop exposing config settings in python toolchain alias repos.
Please consider depending on the flags defined in
`//python/config_setting/...` and the `@platforms` package instead.
* (binaries/tests) The `PYTHONBREAKPOINT` environment variable is automatically inherited
* (binaries/tests) The {obj}`stamp` attribute now transitions the Bazel builtin
{obj}`--stamp` flag.
Expand Down
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,
)
15 changes: 15 additions & 0 deletions python/private/py_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,21 @@ def _create_executable(
# When --build_python_zip is enabled, then the zip file becomes
# one of the default outputs.
if build_zip_enabled:
# buildifier: disable=print
print(
"""
======================================================================
WARNING: Target: {}
The `--build_python_zip` flag and implicit zipapp output of `py_binary`
and `py_test` is deprecated and will be removed in a future release.
Switch to `py_zipapp_binary` or `py_zipapp_test`. For migration
instructions and guide, see:

https://github.com/bazel-contrib/rules_python/issues/3567
======================================================================
""".rstrip().format(ctx.label),
)

extra_default_outputs.append(zip_file)

# The logic here is a bit convoluted. Essentially, there are 3 types of
Expand Down
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