pip_import
pip_import(name, extra_pip_args, python_interpreter, python_interpreter_target, requirements, timeout)
A rule for importing requirements.txt
dependencies into Bazel.
This rule imports a requirements.txt
file and generates a new
requirements.bzl
file. This is used via the WORKSPACE
pattern:
pip_import(
name = "foo",
requirements = ":requirements.txt",
)
load("@foo//:requirements.bzl", "pip_install")
pip_install()
You can then reference imported dependencies from your BUILD
file with:
load("@foo//:requirements.bzl", "requirement")
py_library(
name = "bar",
...
deps = [
"//my/other:dep",
requirement("futures"),
requirement("mock"),
],
)
Or alternatively:
load("@foo//:requirements.bzl", "all_requirements")
py_binary(
name = "baz",
...
deps = [
":foo",
] + all_requirements,
)
Attributes
name |
Name; required
A unique name for this repository. |
extra_pip_args |
List of strings; optional
Extra arguments to pass on to pip. Must not contain spaces. |
python_interpreter |
String; optional
The command to run the Python interpreter used to invoke pip and unpack the wheels. |
python_interpreter_target |
Label; optional
If you are using a custom python interpreter built by another repository rule, use this attribute to specify its BUILD target. This allows pip_import to invoke pip using the same interpreter as your toolchain. If set, takes precedence over python_interpreter. |
requirements |
Label; required
The label of the requirements.txt file. |
timeout |
Integer; optional
Timeout (in seconds) for repository fetch. |
pip3_import
pip3_import(kwargs)
A wrapper around pip_import that uses the python3
system command.
Use this for requirements of PY3 programs.
Parameters
kwargs |
optional. |
pip_repositories
pip_repositories()
Pull in dependencies needed to use the packaging rules.