Skip to content

Latest commit

 

History

History
262 lines (158 loc) · 13.7 KB

rules.md

File metadata and controls

262 lines (158 loc) · 13.7 KB

Public API re-exports

py_binary_rule

py_binary_rule(name, data, deps, env, imports, main, resolutions, srcs)

Run a Python program under Bazel. Most users should use the py_binary macro instead of loading this directly.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
data 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 labels optional []
deps Targets that produce Python code, commonly py_library rules. List of labels optional []
env Environment variables to set when running the binary. Dictionary: String -> String optional {}
imports List of import directories to be added to the PYTHONPATH. List of strings optional []
main Script to execute with the Python interpreter. Label required
resolutions FIXME Dictionary: Label -> String optional {}
srcs Python source files. List of labels optional []

py_library_rule

py_library_rule(name, data, deps, imports, resolutions, srcs, virtual_deps)

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
data 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 labels optional []
deps Targets that produce Python code, commonly py_library rules. List of labels optional []
imports List of import directories to be added to the PYTHONPATH. List of strings optional []
resolutions FIXME Dictionary: Label -> String optional {}
srcs Python source files. List of labels optional []
virtual_deps - List of strings optional []

py_test_rule

py_test_rule(name, data, deps, env, imports, main, resolutions, srcs)

Run a Python program under Bazel. Most users should use the py_test macro instead of loading this directly.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
data 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 labels optional []
deps Targets that produce Python code, commonly py_library rules. List of labels optional []
env Environment variables to set when running the binary. Dictionary: String -> String optional {}
imports List of import directories to be added to the PYTHONPATH. List of strings optional []
main Script to execute with the Python interpreter. Label required
resolutions FIXME Dictionary: Label -> String optional {}
srcs Python source files. List of labels optional []

py_unpacked_wheel_rule

py_unpacked_wheel_rule(name, py_package_name, src)

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
py_package_name - String required
src The Wheel file, as defined by https://packaging.python.org/en/latest/specifications/binary-distribution-format/#binary-distribution-format Label required

py_binary

py_binary(name, srcs, main, imports, kwargs)

Wrapper macro for py_binary_rule, setting a default for imports.

It also creates a virtualenv to constrain the interpreter and packages used at runtime, you can bazel run [name].venv to produce this, then use it in the editor.

PARAMETERS

Name Description Default Value
name Name of the rule. none
srcs Python source files. []
main 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. None
imports List of import paths to add for this binary. ["."]
kwargs additional named parameters to the py_binary_rule. none

py_library

py_library(name, imports, kwargs)

Wrapper macro for the py_library_rule, supporting virtual deps.

PARAMETERS

Name Description Default Value
name Name for this rule. none
imports List of import paths to add for this library. ["."]
kwargs Additional named parameters to py_library_rule. none

py_pytest_main

py_pytest_main(name, py_library, deps, data, testonly, kwargs)

py_pytest_main wraps the template rendering target and the final py_library.

PARAMETERS

Name Description Default Value
name The name of the runable target that updates the test entry file. none
py_library Use this attribute to override the default py_library rule. <unknown object com.google.devtools.build.skydoc.fakebuildapi.FakeStarlarkRuleFunctionsApi$RuleDefinitionIdentifier>
deps A list containing the pytest library target, e.g., @pypi_pytest//:pkg. []
data A list of data dependencies to pass to the py_library target. []
testonly A boolean indicating if the py_library target is testonly. True
kwargs The extra arguments passed to the template rendering target. none

py_test

py_test(name, main, srcs, imports, kwargs)

Identical to py_binary, but produces a target that can be used with bazel test.

PARAMETERS

Name Description Default Value
name

-

none
main

-

None
srcs

-

[]
imports

-

["."]
kwargs

-

none

py_unpacked_wheel

py_unpacked_wheel(name, kwargs)

Wrapper macro for the py_unpacked_wheel_rule, setting a defaults.

PARAMETERS

Name Description Default Value
name Name of this rule. none
kwargs Additional named parameters to py_unpacked_wheel_rule. none

py_venv

py_venv(name, kwargs)

PARAMETERS

Name Description Default Value
name

-

none
kwargs

-

none

resolutions.from_requirements

resolutions.from_requirements(base, requirement_fn)

Returns data representing the resolution for a given set of dependencies

PARAMETERS

Name Description Default Value
base Base set of requirements to turn into resolutions. none
requirement_fn Optional function to transform the Python package name into a requirement label. <function lambda>

RETURNS

A resolution struct for use with virtual deps.

resolutions.empty

resolutions.empty()