Core rules for building Python projects.
current_py_toolchain(<a href="#current_py_toolchain-name">name</a>)
This rule exists so that the current python toolchain can be used in the `toolchains` attribute of other rules, such as genrule. It allows exposing a python toolchain after toolchain resolution has happened, to a rule which expects a concrete implementation of a toolchain, rather than a toolchain_type which could be resolved to that toolchain.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required |
py_import(<a href="#py_import-name">name</a>, <a href="#py_import-deps">deps</a>, <a href="#py_import-srcs">srcs</a>)
This rule allows the use of Python packages as dependencies.
It imports the given `.egg` file(s), which might be checked in source files, fetched externally as with `http_file`, or produced as outputs of other rules. It may be used like a `py_library`, in the `deps` of other Python rules. This is similar to [java_import](https://docs.bazel.build/versions/master/be/java.html#java_import).
ATTRIBUTES
py_binary(<a href="#py_binary-attrs">attrs</a>)
See the Bazel core py_binary documentation.
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| attrs | Rule attributes | none |
py_library(<a href="#py_library-attrs">attrs</a>)
See the Bazel core py_library documentation.
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| attrs | Rule attributes | none |
py_runtime(<a href="#py_runtime-attrs">attrs</a>)
See the Bazel core py_runtime documentation.
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| attrs | Rule attributes | none |
py_runtime_pair(<a href="#py_runtime_pair-name">name</a>, <a href="#py_runtime_pair-py2_runtime">py2_runtime</a>, <a href="#py_runtime_pair-py3_runtime">py3_runtime</a>, <a href="#py_runtime_pair-attrs">attrs</a>)
A toolchain rule for Python.
This used to wrap up to two Python runtimes, one for Python 2 and one for Python 3. However, Python 2 is no longer supported, so it now only wraps a single Python 3 runtime.
Usually the wrapped runtimes are declared using the py_runtime rule, but any rule returning a PyRuntimeInfo provider may be used.
This rule returns a platform_common.ToolchainInfo provider with the following schema:
platform_common.ToolchainInfo( py2_runtime = None, py3_runtime = <PyRuntimeInfo or None>, )
Example usage:
# In your BUILD file... load("@rules_python//python:defs.bzl", "py_runtime_pair") py_runtime( name = "my_py3_runtime", interpreter_path = "/system/python3", python_version = "PY3", ) py_runtime_pair( name = "my_py_runtime_pair", py3_runtime = ":my_py3_runtime", ) toolchain( name = "my_toolchain", target_compatible_with = <...>, toolchain = ":my_py_runtime_pair", toolchain_type = "@rules_python//python:toolchain_type", )
# In your WORKSPACE... register_toolchains("//my_pkg:my_toolchain")
PARAMETERS
py_test(<a href="#py_test-attrs">attrs</a>)
See the Bazel core py_test documentation.
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| attrs | Rule attributes | none |
find_requirements(<a href="#find_requirements-name">name</a>)
The aspect definition. Can be invoked on the command line as
bazel build //pkg:my_py_binary_target --aspects=@rules_python//python:defs.bzl%find_requirements --output_groups=pyversioninfo
ASPECT ATTRIBUTES
| Name | Type |
|---|---|
| deps | String |
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required |