//python/private:py_runtime_pair_rule.bzl
Implementation of py_runtime_pair.
- rule py_runtime_pair(name, py2_runtime=None, py3_runtime=None)
A toolchain rule for Python.
This wraps up to two Python runtimes, one for Python 2 and one for Python 3. The rule consuming this toolchain will choose which runtime is appropriate. Either runtime may be omitted, in which case the resulting toolchain will be unusable for building Python code using that version.
Usually the wrapped runtimes are declared using the
py_runtimerule, but any rule returning aPyRuntimeInfoprovider may be used.This rule returns a
ToolchainInfoprovider with fields:py2_runtime:PyRuntimeInfo|None, runtime information for a Python 2 runtime.py3_runtime:PyRuntimeInfo|None. runtime information for a Python 3 runtime.
Example usage:
# In your BUILD file... load("@rules_python//python:py_runtime.bzl", "py_runtime") load("@rules_python//python:py_runtime_pair.bzl", "py_runtime_pair") py_runtime( name = "my_py2_runtime", interpreter_path = "/system/python2", python_version = "PY2", ) py_runtime( name = "my_py3_runtime", interpreter_path = "/system/python3", python_version = "PY3", ) py_runtime_pair( name = "my_py_runtime_pair", py2_runtime = ":my_py2_runtime", 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")
- Attributes:
A unique name for this target.
mandatory
py2_runtime– (label) (default None)The runtime to use for Python 2 targets. Must have
python_versionset toPY2.optional
Required providers:
PyRuntimeInfopy3_runtime– (label) (default None)The runtime to use for Python 3 targets. Must have
python_versionset toPY3.optional
Required providers:
PyRuntimeInfo