//python/private/zipapp:py_zipapp_rule.bzl

Implementation of the zipapp rules.

rule py_zipapp_binary(name, binary, compression='', config_settings={}, executable=True)

Packages a py_binary as a Python zipapp.

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.

Added in version 1.9.0.

Attributes:
  • name(Name)

    A unique name for this target.

    mandatory

  • binary(label)

    A py_binary or py_test (or equivalent) target to package.

    mandatory

    Required providers: [PyExecutableInfo, PyRuntimeInfo]

  • compression(str) (default “”)

    The compression level to use.

    Typically 0 to 9, with higher numbers being to compress more.

    optional

  • config_settings(dict[label, str]) (default {})

    Config settings to change for this target.

    The keys are labels for settings, and the values are strings for the new value to use. Pass Label objects or canonical label strings for the keys to ensure they resolve as expected (canonical labels start with @@ and can be obtained by calling str(Label(...))).

    Most @rules_python//python/config_setting settings can be used here, which allows, for example, making only a certain py_binary use --bootstrap_impl=script.

    Additional or custom config settings can be registered using the add_transition_setting API. This allows, for example, forcing a particular CPU, or defining a custom setting that select() uses elsewhere to pick between pip.parse hubs. See the [How to guide on multiple versions of a library] for a more concrete example.

    Note

    These values are transitioned on, so will affect the analysis graph and the associated memory overhead. The more unique configurations in your overall build, the more memory and (often unnecessary) re-analysis and re-building can occur. See https://bazel.build/extending/config#memory-performance-considerations for more information about risks and considerations.

    optional

  • executable(bool) (default True)

    Whether the output should be an executable zip file.

    optional

rule py_zipapp_test(name, binary, compression='', config_settings={}, executable=True)

Packages a py_test as a Python zipapp.

This target is also a valid test target to run.

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.

Added in version 1.9.0.

Attributes:
  • name(Name)

    A unique name for this target.

    mandatory

  • binary(label)

    A py_binary or py_test (or equivalent) target to package.

    mandatory

    Required providers: [PyExecutableInfo, PyRuntimeInfo]

  • compression(str) (default “”)

    The compression level to use.

    Typically 0 to 9, with higher numbers being to compress more.

    optional

  • config_settings(dict[label, str]) (default {})

    Config settings to change for this target.

    The keys are labels for settings, and the values are strings for the new value to use. Pass Label objects or canonical label strings for the keys to ensure they resolve as expected (canonical labels start with @@ and can be obtained by calling str(Label(...))).

    Most @rules_python//python/config_setting settings can be used here, which allows, for example, making only a certain py_binary use --bootstrap_impl=script.

    Additional or custom config settings can be registered using the add_transition_setting API. This allows, for example, forcing a particular CPU, or defining a custom setting that select() uses elsewhere to pick between pip.parse hubs. See the [How to guide on multiple versions of a library] for a more concrete example.

    Note

    These values are transitioned on, so will affect the analysis graph and the associated memory overhead. The more unique configurations in your overall build, the more memory and (often unnecessary) re-analysis and re-building can occur. See https://bazel.build/extending/config#memory-performance-considerations for more information about risks and considerations.

    optional

  • executable(bool) (default True)

    Whether the output should be an executable zip file.

    optional