Import pip requirements into Bazel.
whl_library_alias(<a href="#whl_library_alias-name">name</a>, <a href="#whl_library_alias-default_version">default_version</a>, <a href="#whl_library_alias-repo_mapping">repo_mapping</a>, <a href="#whl_library_alias-version_map">version_map</a>, <a href="#whl_library_alias-wheel_name">wheel_name</a>)
ATTRIBUTES
compile_pip_requirements(<a href="#compile_pip_requirements-name">name</a>, <a href="#compile_pip_requirements-extra_args">extra_args</a>, <a href="#compile_pip_requirements-extra_deps">extra_deps</a>, <a href="#compile_pip_requirements-generate_hashes">generate_hashes</a>, <a href="#compile_pip_requirements-py_binary">py_binary</a>, <a href="#compile_pip_requirements-py_test">py_test</a>, <a href="#compile_pip_requirements-requirements_in">requirements_in</a>, <a href="#compile_pip_requirements-requirements_txt">requirements_txt</a>, <a href="#compile_pip_requirements-requirements_darwin">requirements_darwin</a>, <a href="#compile_pip_requirements-requirements_linux">requirements_linux</a>, <a href="#compile_pip_requirements-requirements_windows">requirements_windows</a>, <a href="#compile_pip_requirements-visibility">visibility</a>, <a href="#compile_pip_requirements-tags">tags</a>, <a href="#compile_pip_requirements-kwargs">kwargs</a>)
Generates targets for managing pip dependencies with pip-compile.
By default this rules generates a filegroup named “[name]” which can be included in the data of some other compile_pip_requirements rule that references these requirements (e.g. with -r ../other/requirements.txt).
It also generates two targets for running pip-compile:
bazel test [name]_testbazel run [name].updateIf you are using a version control system, the requirements.txt generated by this rule should be checked into it to ensure that all developers/users have the same dependency versions.
PARAMETERS
multi_pip_parse(<a href="#multi_pip_parse-name">name</a>, <a href="#multi_pip_parse-default_version">default_version</a>, <a href="#multi_pip_parse-python_versions">python_versions</a>, <a href="#multi_pip_parse-python_interpreter_target">python_interpreter_target</a>, <a href="#multi_pip_parse-requirements_lock">requirements_lock</a>, <a href="#multi_pip_parse-kwargs">kwargs</a>)
NOT INTENDED FOR DIRECT USE!
This is intended to be used by the multi_pip_parse implementation in the template of the multi_toolchain_aliases repository rule.
PARAMETERS
RETURNS
The internal implementation of multi_pip_parse repository rule.
package_annotation(<a href="#package_annotation-additive_build_content">additive_build_content</a>, <a href="#package_annotation-copy_files">copy_files</a>, <a href="#package_annotation-copy_executables">copy_executables</a>, <a href="#package_annotation-data">data</a>, <a href="#package_annotation-data_exclude_glob">data_exclude_glob</a>, <a href="#package_annotation-srcs_exclude_glob">srcs_exclude_glob</a>)
Annotations to apply to the BUILD file content from package generated from a pip_repository rule.
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| additive_build_content | Raw text to add to the generated BUILD file of a package. | None |
| copy_files | A mapping of src and out files for @bazel_skylib//rules:copy_file.bzl | {} |
| copy_executables | A mapping of src and out files for @bazel_skylib//rules:copy_file.bzl. Targets generated here will also be flagged as executable. | {} |
| data | A list of labels to add as data dependencies to the generated py_library target. | [] |
| data_exclude_glob | A list of exclude glob patterns to add as data to the generated py_library target. | [] |
| srcs_exclude_glob | A list of labels to add as srcs to the generated py_library target. | [] |
RETURNS
str: A json encoded string of the provided content.
pip_install(<a href="#pip_install-requirements">requirements</a>, <a href="#pip_install-name">name</a>, <a href="#pip_install-kwargs">kwargs</a>)
Accepts a locked/compiled requirements file and installs the dependencies listed within.
load("@rules_python//python:pip.bzl", "pip_install") pip_install( name = "pip_deps", requirements = ":requirements.txt", ) load("@pip_deps//:requirements.bzl", "install_deps") install_deps()
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| requirements | A ‘requirements.txt’ pip requirements file. | None |
| name | A unique name for the created external repository (default ‘pip’). | “pip” |
| kwargs | Additional arguments to the pip_repository repository rule. | none |
pip_parse(<a href="#pip_parse-requirements">requirements</a>, <a href="#pip_parse-requirements_lock">requirements_lock</a>, <a href="#pip_parse-name">name</a>, <a href="#pip_parse-kwargs">kwargs</a>)
Accepts a locked/compiled requirements file and installs the dependencies listed within.
Those dependencies become available in a generated requirements.bzl file. You can instead check this requirements.bzl file into your repo, see the “vendoring” section below.
This macro wraps the pip_repository rule that invokes pip. In your WORKSPACE file:
load("@rules_python//python:pip.bzl", "pip_parse") pip_parse( name = "pip_deps", requirements_lock = ":requirements.txt", ) load("@pip_deps//:requirements.bzl", "install_deps") install_deps()
You can then reference installed dependencies from a BUILD file with:
load("@pip_deps//:requirements.bzl", "requirement") py_library( name = "bar", ... deps = [ "//my/other:dep", requirement("requests"), requirement("numpy"), ], )
In addition to the requirement macro, which is used to access the generated py_library target generated from a package's wheel, The generated requirements.bzl file contains functionality for exposing entry points as py_binary targets as well.
load("@pip_deps//:requirements.bzl", "entry_point") alias( name = "pip-compile", actual = entry_point( pkg = "pip-tools", script = "pip-compile", ), )
Note that for packages whose name and script are the same, only the name of the package is needed when calling the entry_point macro.
load("@pip_deps//:requirements.bzl", "entry_point") alias( name = "flake8", actual = entry_point("flake8"), )
In some cases you may not want to generate the requirements.bzl file as a repository rule while Bazel is fetching dependencies. For example, if you produce a reusable Bazel module such as a ruleset, you may want to include the requirements.bzl file rather than make your users install the WORKSPACE setup to generate it. See https://github.com/bazelbuild/rules_python/issues/608
This is the same workflow as Gazelle, which creates go_repository rules with update-repos
To do this, use the “write to source file” pattern documented in https://blog.aspect.dev/bazel-can-write-to-the-source-folder to put a copy of the generated requirements.bzl into your project. Then load the requirements.bzl file directly rather than from the generated repository. See the example in rules_python/examples/pip_parse_vendored.
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| requirements | Deprecated. See requirements_lock. | None |
| requirements_lock | A fully resolved ‘requirements.txt’ pip requirement file containing the transitive set of your dependencies. If this file is passed instead of ‘requirements’ no resolve will take place and pip_repository will create individual repositories for each of your dependencies so that wheels are fetched/built only for the targets specified by ‘build/run/test’. Note that if your lockfile is platform-dependent, you can use the requirements_[platform] attributes. | None |
| name | The name of the generated repository. The generated repositories containing each requirement will be of the form <name>_<requirement-name>. | “pip_parsed_deps” |
| kwargs | Additional arguments to the pip_repository repository rule. | none |