Out of items documented below only package_annotation annotation is available for general usage. Any other APIs are subject to change.
A rule for bzlmod mulitple pip repository creation. PRIVATE USE ONLY.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this repository. | Name | required | |
| default_version | This is the default python version in the format of X.Y.Z. This should match what is setup by the ‘python’ extension using the ‘is_default = True’ setting. | String | required | |
| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | |
| repo_name | The apparent name of the repo. This is needed because in bzlmod, the name attribute becomes the canonical name. | String | required | |
| whl_map | The wheel map where values are python versions | Dictionary: String -> List of strings | required |
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_repository( name = "foo", requirements = ":requirements.txt", )
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("requests"), requirement("numpy"), ], )
Or alternatively:
load("@foo//:requirements.bzl", "all_requirements") py_binary( name = "baz", ... deps = [ ":foo", ] + all_requirements, )
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this repository. | Name | required | |
| annotations | Optional annotations to apply to packages | Dictionary: String -> String | optional | {} |
| download_only | Whether to use “pip download” instead of “pip wheel”. Disables building wheels from source, but allows use of --platform, --python-version, --implementation, and --abi in --extra_pip_args to download wheels for a different platform from the host platform. | Boolean | optional | False |
| enable_implicit_namespace_pkgs | If true, disables conversion of native namespace packages into pkg-util style namespace packages. When set all py_binary and py_test targets must specify either legacy_create_init=False or the global Bazel option --incompatible_default_to_explicit_init_py to prevent __init__.py being automatically generated in every directory.This option is required to support some packages which cannot handle the conversion to pkg-util style. | Boolean | optional | False |
| environment | Environment variables to set in the pip subprocess. Can be used to set common variables such as http_proxy, https_proxy and no_proxy Note that pip is run with “--isolated” on the CLI so PIP_<VAR>_<NAME> style env vars are ignored, but env vars that control requests and urllib3 can be passed. | Dictionary: String -> String | optional | {} |
| extra_pip_args | Extra arguments to pass on to pip. Must not contain spaces. | List of strings | optional | [] |
| incompatible_generate_aliases | Allow generating aliases ‘@pip//’ -> ‘@pip_//:pkg’. | Boolean | optional | False |
| isolated | Whether or not to pass the --isolated flag to the underlying pip command. Alternatively, the RULES_PYTHON_PIP_ISOLATED environment variable can be used to control this flag. | Boolean | optional | True |
| pip_data_exclude | Additional data exclusion parameters to add to the pip packages BUILD file. | List of strings | optional | [] |
| python_interpreter | The python interpreter to use. This can either be an absolute path or the name of a binary found on the host's PATH environment variable. If no value is set python3 is defaulted for Unix systems and python.exe for Windows. | String | optional | "" |
| python_interpreter_target | If you are using a custom python interpreter built by another repository rule, use this attribute to specify its BUILD target. This allows pip_repository to invoke pip using the same interpreter as your toolchain. If set, takes precedence over python_interpreter. An example value: “@python3_x86_64-unknown-linux-gnu//:python”. | Label | optional | None |
| quiet | If True, suppress printing stdout and stderr output to the terminal. | Boolean | optional | True |
| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | |
| repo_prefix | Prefix for the generated packages will be of the form @<prefix><sanitized-package-name>//... | String | optional | "" |
| requirements_darwin | Override the requirements_lock attribute when the host platform is Mac OS | Label | optional | None |
| requirements_linux | Override the requirements_lock attribute when the host platform is Linux | Label | optional | 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’. | Label | optional | None |
| requirements_windows | Override the requirements_lock attribute when the host platform is Windows | Label | optional | None |
| timeout | Timeout (in seconds) on the rule's execution duration. | Integer | optional | 600 |
Download and extracts a single wheel based into a bazel repo based on the requirement string passed in. Instantiated from pip_repository and inherits config options from there.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this repository. | Name | required | |
| annotation | Optional json encoded file containing annotation to apply to the extracted wheel. See package_annotation | Label | optional | None |
| download_only | Whether to use “pip download” instead of “pip wheel”. Disables building wheels from source, but allows use of --platform, --python-version, --implementation, and --abi in --extra_pip_args to download wheels for a different platform from the host platform. | Boolean | optional | False |
| enable_implicit_namespace_pkgs | If true, disables conversion of native namespace packages into pkg-util style namespace packages. When set all py_binary and py_test targets must specify either legacy_create_init=False or the global Bazel option --incompatible_default_to_explicit_init_py to prevent __init__.py being automatically generated in every directory.This option is required to support some packages which cannot handle the conversion to pkg-util style. | Boolean | optional | False |
| environment | Environment variables to set in the pip subprocess. Can be used to set common variables such as http_proxy, https_proxy and no_proxy Note that pip is run with “--isolated” on the CLI so PIP_<VAR>_<NAME> style env vars are ignored, but env vars that control requests and urllib3 can be passed. | Dictionary: String -> String | optional | {} |
| extra_pip_args | Extra arguments to pass on to pip. Must not contain spaces. | List of strings | optional | [] |
| isolated | Whether or not to pass the --isolated flag to the underlying pip command. Alternatively, the RULES_PYTHON_PIP_ISOLATED environment variable can be used to control this flag. | Boolean | optional | True |
| pip_data_exclude | Additional data exclusion parameters to add to the pip packages BUILD file. | List of strings | optional | [] |
| python_interpreter | The python interpreter to use. This can either be an absolute path or the name of a binary found on the host's PATH environment variable. If no value is set python3 is defaulted for Unix systems and python.exe for Windows. | String | optional | "" |
| python_interpreter_target | If you are using a custom python interpreter built by another repository rule, use this attribute to specify its BUILD target. This allows pip_repository to invoke pip using the same interpreter as your toolchain. If set, takes precedence over python_interpreter. An example value: “@python3_x86_64-unknown-linux-gnu//:python”. | Label | optional | None |
| quiet | If True, suppress printing stdout and stderr output to the terminal. | Boolean | optional | True |
| repo | Pointer to parent repo name. Used to make these rules rerun if the parent repo changes. | String | required | |
| repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). | Dictionary: String -> String | required | |
| repo_prefix | Prefix for the generated packages will be of the form @<prefix><sanitized-package-name>//... | String | optional | "" |
| requirement | Python requirement string describing the package to make available | String | required | |
| timeout | Timeout (in seconds) on the rule's execution duration. | Integer | optional | 600 |
Get the preferred label for a locked requirements file based on platform.
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| ctx | repository or module context | none |
| attr | attributes for the repo rule or tag extension | none |
RETURNS
Label
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.
Determine whether or not to pass the pip --isolated flag to the pip invocation.
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| ctx | repository or module context | none |
| attr | attributes for the repo rule or tag extension | none |
RETURNS
True if --isolated should be passed