diff --git a/CHANGELOG.md b/CHANGELOG.md index d71b6e65b2..15118f53e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. 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/py_executable.bzl b/python/private/py_executable.bzl index 9f1113d9f6..45a18abb05 100644 --- a/python/private/py_executable.bzl +++ b/python/private/py_executable.bzl @@ -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 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..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") @@ -6,6 +12,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..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") @@ -6,6 +12,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`. """