Documentation Index
Fetch the complete documentation index at: https://docs.aspect.build/llms.txt
Use this file to discover all available pages before exploring further.
Documentation for @aspect_rules_py@v1.8.4 — View source
Choosing the Python version
Thepython_version attribute must refer to a python toolchain version
which has been registered in the WORKSPACE or MODULE.bazel file.
When using WORKSPACE, this may look like this:
Rule: py_pex_binary
Build a pex executable from a py_binary
Kind: Executable rule
Attributes
A unique name for this target.
A py_binary target
Environment variables to set when running the pex binary.
Whether to inherit the
sys.path (aka PYTHONPATH) of the environment that the binary runs in.Use false to not inherit sys.path; use fallback to inherit sys.path after packaged
dependencies; and use prefer to inherit sys.path before packaged dependencies.Python interpreter versions this PEX binary is compatible with. A list of semver strings.
The placeholder strings
{major}, {minor}, {patch} can be used for gathering version
information from the hermetic python toolchain.Rule: py_binary_rule
Run a Python program under Bazel. Most users should use the py_binary macro instead of loading this directly.
Kind: Executable rule
Attributes
A unique name for this target.
Environment variables to set when running the binary.
Script to execute with the Python interpreter.Must be a label pointing to a
.py source file.
If such a label is provided, it will be honored.If no label is provided AND there is only one srcs file, that srcs file will be used.If there are more than one srcs, a file matching {name}.py is searched for.
This is for historical compatibility with the Bazel native py_binary and rules_python.
Relying on this behavior is STRONGLY discouraged, may produce warnings and may
be deprecated in the future.The name of the Python virtual environment within which deps should be resolved.Part of the aspect_rules_py//uv system, has no effect in rules_python’s pip.
Whether to build this target and its transitive deps for a specific python version.
The action that should be taken when a symlink collision is encountered when creating the venv.
A collision can occur when multiple packages providing the same file are installed into the venv. The possible values are:
- “error”: When conflicting symlinks are found, an error is reported and venv creation halts.
- “warning”: When conflicting symlinks are found, an warning is reported, however venv creation continues.
- “ignore”: When conflicting symlinks are found, no message is reported and venv creation continues.
Additional options to pass to the Python interpreter in addition to -B and -I passed by rules_py
Python source files.
Targets that produce Python code, commonly
py_library rules.Runtime dependencies of the program.The transitive closure of the
data dependencies will be available in the .runfiles
folder for this binary/test. The program may optionally use the Runfiles lookup library to
locate the data files, see https://pypi.org/project/bazel-runfiles/.List of import directories to be added to the PYTHONPATH.
Satisfy a virtual_dep with a mapping from external package name to the label of an installed package that provides it.
See virtual_deps.
Rule: py_test_rule
Run a Python program under Bazel. Most users should use the py_test macro instead of loading this directly.
Kind: Test rule
Attributes
A unique name for this target.
Environment variables to set when running the binary.
Script to execute with the Python interpreter.Must be a label pointing to a
.py source file.
If such a label is provided, it will be honored.If no label is provided AND there is only one srcs file, that srcs file will be used.If there are more than one srcs, a file matching {name}.py is searched for.
This is for historical compatibility with the Bazel native py_binary and rules_python.
Relying on this behavior is STRONGLY discouraged, may produce warnings and may
be deprecated in the future.The name of the Python virtual environment within which deps should be resolved.Part of the aspect_rules_py//uv system, has no effect in rules_python’s pip.
Whether to build this target and its transitive deps for a specific python version.
The action that should be taken when a symlink collision is encountered when creating the venv.
A collision can occur when multiple packages providing the same file are installed into the venv. The possible values are:
- “error”: When conflicting symlinks are found, an error is reported and venv creation halts.
- “warning”: When conflicting symlinks are found, an warning is reported, however venv creation continues.
- “ignore”: When conflicting symlinks are found, no message is reported and venv creation continues.
Additional options to pass to the Python interpreter in addition to -B and -I passed by rules_py
Python source files.
Targets that produce Python code, commonly
py_library rules.Runtime dependencies of the program.The transitive closure of the
data dependencies will be available in the .runfiles
folder for this binary/test. The program may optionally use the Runfiles lookup library to
locate the data files, see https://pypi.org/project/bazel-runfiles/.List of import directories to be added to the PYTHONPATH.
Satisfy a virtual_dep with a mapping from external package name to the label of an installed package that provides it.
See virtual_deps.
Specifies additional environment variables to inherit from the external environment when the test is executed by bazel test.
Rule: py_library
Attributes
A unique name for this target.
Python source files.
Targets that produce Python code, commonly
py_library rules.Runtime dependencies of the program.The transitive closure of the
data dependencies will be available in the .runfiles
folder for this binary/test. The program may optionally use the Runfiles lookup library to
locate the data files, see https://pypi.org/project/bazel-runfiles/.List of import directories to be added to the PYTHONPATH.
Satisfy a virtual_dep with a mapping from external package name to the label of an installed package that provides it.
See virtual_deps.
Rule: py_unpacked_wheel
Attributes
A unique name for this target.
The Wheel file, as defined by https://packaging.python.org/en/latest/specifications/binary-distribution-format/#binary-distribution-format
Function: py_pytest_main
py_pytest_main wraps the template rendering target and the final py_library.
Parameters
The name of the runable target that updates the test entry file.
Use this attribute to override the default py_library rule.
A list containing the pytest library target, e.g., @pypi_pytest//:pkg.
A list of data dependencies to pass to the py_library target.
A boolean indicating if the py_library target is testonly.
The extra arguments passed to the template rendering target.
Function: py_venv
Build a Python virtual environment and produce a script to link it into the build directory.
Parameters
Function: py_venv_link
Build a Python virtual environment and produce a script to link it into the build directory.
Parameters
Function: py_image_layer
Produce a separate tar output for each layer of a python app
Requires awk to be installed on the host machine/rbe runner.
For better performance, it is recommended to split the output of a py_binary into multiple layers.
This can be done by grouping files into layers based on their path by using the layer_groups attribute.
The matching order for layer groups is as follows:
layer_groupsare checked first.- If no match is found for
layer_groups, thedefault layer groupsare checked. - Any remaining files are placed into the default layer.
Parameters
base name for targets
a py_binary target
Path to where the layers should be rooted. If not specified, the layers will be rooted at the workspace root.
Additional layer groups to create. They are used to group files into layers based on their path. In the form of:
{"<name>": "regex_to_match_against_file_paths"}Compression algorithm to use. Default is gzip. See: https://github.com/bazel-contrib/bazel-lib/blob/main/docs/tar.md#tar_rule-compress
Additional arguments to pass to the tar rule. Default is
[]. See: https://github.com/bazel-contrib/bazel-lib/blob/main/docs/tar.md#tar_rule-argsWhether to compute unused inputs. Default is 1. See: https://github.com/bazel-contrib/bazel-lib/blob/main/docs/tar.md#tar_rule-compute_unused_inputs
The platform to use for the transition. Default is None. See: https://github.com/bazel-contrib/bazel-lib/blob/main/docs/transitions.md#platform_transition_binary-target_platform
An owner uid for the uncompressed files. See mtree_mutate: https://github.com/bazel-contrib/bazel-lib/blob/main/docs/tar.md#mutating-the-tar-contents
A group uid for the uncompressed files. See mtree_mutate: https://github.com/bazel-contrib/bazel-lib/blob/main/docs/tar.md#mutating-the-tar-contents
attribute that apply to all targets expanded by the macro
Function: resolutions.empty
Function: resolutions.from_requirements
Parameters
Function: py_binary
Wrapper macro for py_binary_rule.
Creates a py_venv target to constrain the interpreter and packages used at runtime.
Users can bazel run [name].venv to create this virtualenv, then use it in the editor or other tools.
Parameters
Name of the rule.
Python source files.
Entry point.
Like rules_python, this is treated as a suffix of a file that should appear among the srcs.
If absent, then
[name].py is tried. As a final fallback, if the srcs has a single file,
that is used as the main.additional named parameters to
py_binary_rule.Function: py_test
Identical to py_binary, but produces a target that can be used with bazel test.
Parameters
Name of the rule.
Python source files.
Entry point.
Like rules_python, this is treated as a suffix of a file that should appear among the srcs.
If absent, then
[name].py is tried. As a final fallback, if the srcs has a single file,
that is used as the main.If set, generate a py_pytest_main script and use it as the main.
The deps should include the pytest package (as well as the coverage package if desired).
additional named parameters to
py_binary_rule.
