Add something like this to your WORKSPACE file:
git_repository(
name = "io_bazel_rules_pex",
remote = "https://github.com/benley/bazel_rules_pex.git",
tag = "0.3.0",
)
load("@io_bazel_rules_pex//pex:pex_rules.bzl", "pex_repositories")
pex_repositories()
In a BUILD file where you want to use these rules, or in your
tools/build_rules/prelude_bazel
file if you want them present repo-wide, add:
load(
"@io_bazel_rules_pex//pex:pex_rules.bzl",
"pex_binary",
"pex_library",
"pex_test",
"pex_pytest",
)
Lastly, make sure that tools/build_rules/BUILD
exists, even if it is empty,
so that Bazel can find your prelude_bazel
file.
pex_pytest(name, srcs, deps, eggs, data, args, flaky, local, size, timeout, tags)
A variant of pex_test that uses py.test to run one or more sets of tests.
This produces two things:
- A pex_binary (
<name>_runner
) containing all your code and its dependencies, plus py.test, and the entrypoint set to the py.test runner. - A small shell script to launch the
<name>_runner
executable with each of thesrcs
enumerated as commandline arguments. This is the actual test entrypoint for bazel.
Almost all of the attributes that can be used with pex_test work identically
here, including those not specifically mentioned in this docstring.
Exceptions are main
and entrypoint
, which cannot be used with this macro.
name |
A unique name for this rule. |
srcs |
List of files containing tests that should be run. |
deps |
|
eggs |
|
data |
|
args |
|
flaky |
|
local |
|
size |
|
timeout |
|
tags |
|
pex_repositories()
Rules to be invoked from WORKSPACE for remote dependencies.
pex_binary(name, deps, data, srcs, disable_cache, eggs, entrypoint, interpreter, main, no_index, pex_use_wheels, pex_verbosity, repos, req_files, reqs, zip_safe)
Build a deployable pex executable.
name |
A unique name for this rule. |
deps |
Python module dependencies.
|
data |
Files to include as resources in the final pex binary. Putting other rules here will cause the outputs of those rules to be embedded in this one. Files will be included as-is. Paths in the archive will be relative to the workspace root. |
srcs |
|
disable_cache |
Disable caching in the pex tool entirely. Default: False |
eggs |
|
entrypoint |
Name of a python module to use as the entrypoint. e.g. If unspecified, the |
interpreter |
Path to the python interpreter the pex should to use in its shebang line. |
main |
File to use as the entrypoint. If unspecified, the first file from the |
no_index |
If True, don't use pypi to resolve dependencies for |
pex_use_wheels |
|
pex_verbosity |
|
repos |
Additional repository labels (filegroups of wheel/egg files) to look for requirements. |
req_files |
Add requirements from the given requirements files. Must be provided as labels. This feature will reduce build determinism! It tells pex to resolve all the transitive python dependencies and fetch them from pypi. It is recommended that you use |
reqs |
External requirements to retrieve from pypi, in This feature will reduce build determinism! It tells pex to resolve all the transitive python dependencies and fetch them from pypi. It is recommended that you use |
zip_safe |
|
pex_library(name, deps, data, srcs, disable_cache, eggs, no_index, repos, req_files, reqs)
name |
A unique name for this rule. |
deps |
Python module dependencies.
|
data |
Files to include as resources in the final pex binary. Putting other rules here will cause the outputs of those rules to be embedded in this one. Files will be included as-is. Paths in the archive will be relative to the workspace root. |
srcs |
|
disable_cache |
Disable caching in the pex tool entirely. Default: False |
eggs |
|
no_index |
If True, don't use pypi to resolve dependencies for |
repos |
Additional repository labels (filegroups of wheel/egg files) to look for requirements. |
req_files |
Add requirements from the given requirements files. Must be provided as labels. This feature will reduce build determinism! It tells pex to resolve all the transitive python dependencies and fetch them from pypi. It is recommended that you use |
reqs |
External requirements to retrieve from pypi, in This feature will reduce build determinism! It tells pex to resolve all the transitive python dependencies and fetch them from pypi. It is recommended that you use |
pex_test(name, deps, data, srcs, disable_cache, eggs, entrypoint, interpreter, main, no_index, pex_use_wheels, pex_verbosity, repos, req_files, reqs, zip_safe)
name |
A unique name for this rule. |
deps |
Python module dependencies.
|
data |
Files to include as resources in the final pex binary. Putting other rules here will cause the outputs of those rules to be embedded in this one. Files will be included as-is. Paths in the archive will be relative to the workspace root. |
srcs |
|
disable_cache |
Disable caching in the pex tool entirely. Default: False |
eggs |
|
entrypoint |
Name of a python module to use as the entrypoint. e.g. If unspecified, the |
interpreter |
Path to the python interpreter the pex should to use in its shebang line. |
main |
File to use as the entrypoint. If unspecified, the first file from the |
no_index |
If True, don't use pypi to resolve dependencies for |
pex_use_wheels |
|
pex_verbosity |
|
repos |
Additional repository labels (filegroups of wheel/egg files) to look for requirements. |
req_files |
Add requirements from the given requirements files. Must be provided as labels. This feature will reduce build determinism! It tells pex to resolve all the transitive python dependencies and fetch them from pypi. It is recommended that you use |
reqs |
External requirements to retrieve from pypi, in This feature will reduce build determinism! It tells pex to resolve all the transitive python dependencies and fetch them from pypi. It is recommended that you use |
zip_safe |
|