//python/private/pypi:whl_archive.bzl
- repo rule whl_archive(name, requirement, annotation=None, auth_patterns={}, config_load='', dep_template='', enable_implicit_namespace_pkgs=False, envsubst=[], filename='', group_deps=[], group_name='', index_url='', integrity='', netrc='', pip_data_exclude=[], sha256='', urls=[], whl_file=None, whl_patches={})
Download and extracts a single wheel based into a bazel repo based on the requirement string passed in.
Does not depend on any python.
- Attributes:
A unique name for this repository.
mandatory
requirement– (str)Python requirement string describing the package to make available, if ‘urls’ or ‘whl_file’ is given, then this only needs to include foo[any_extras] as a bare minimum.
mandatory
annotation– (label) (default None)Optional json encoded file containing annotation to apply to the extracted wheel. See
package_annotationoptional
auth_patterns– (dict[str,str]) (default {})An optional dict mapping host names to custom authorization patterns.
If a URL’s host name is present in this dict the value will be used as a pattern when generating the authorization header for the http request. This enables the use of custom authorization schemes used in a lot of common cloud storage providers.
The pattern currently supports 2 tokens:
<login>and<password>, which are replaced with their equivalent value in the netrc file for the same host name. After formatting, the result is set as the value for theAuthorizationfield of the HTTP request.Example attribute and netrc for a http download to an oauth2 enabled API using a bearer token:
auth_patterns = { "storage.cloudprovider.com": "Bearer <password>" }netrc:
machine storage.cloudprovider.com password RANDOM-TOKENThe final HTTP request would have the following header:
Authorization: Bearer RANDOM-TOKEN
optional
config_load– (str) (default “”)The load location for configuration for pipstar.
optional
dep_template– (str) (default “”)The dep template to use for referencing the dependencies. It should have
{name}and{target}tokens that will be replaced with the normalized distribution name and the target that we need respectively.For example if your whl depends on
numpyand your Python package repo is namedpipso that you would normally do@pip//numpy, then this should be:@pip//{name}.optional
enable_implicit_namespace_pkgs– (bool) (default False)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=Falseor the global Bazel option--incompatible_default_to_explicit_init_pyto prevent__init__.pybeing automatically generated in every directory.This option is required to support some packages which cannot handle the conversion to pkg-util style.
optional
envsubst– (list[str]) (default [])A list of environment variables to substitute (e.g.
["PIP_INDEX_URL", "PIP_RETRIES"]). The corresponding variables are expanded inextra_pip_argsusing the syntax$VARNAMEor${VARNAME}(expanding to empty string if unset) or${VARNAME:-default}(expanding to default if the variable is unset or empty in the environment). Note: On Bazel 6 and Bazel 7.0 changes to the variables named here do not cause packages to be re-fetched. Don’t fetch different things based on the value of these variables.optional
Download the whl file to this filename. Only used when the
urlsis passed. If not specified, will be auto-detected from theurls.optional
group_deps– (list[str]) (default [])List of dependencies to skip in order to break the cycles within a dependency group.
optional
group_name– (str) (default “”)Name of the group, if any.
optional
index_url– (str) (default “”)The index_url that the package will be downloaded from.
optional
integrity– (str) (default “”)The expected checksum of the downloaded whl in Subresource Integrity format (e.g.
sha256-...orsha512-...). Only used whenurlsis passed. Ifsha256is also set, it takes precedence over this attribute.Added in version 2.3.0.
optional
Location of the .netrc file to use for authentication
optional
pip_data_exclude– (list[str]) (default [])Additional data exclusion parameters to add to the pip packages BUILD file.
optional
The sha256 of the downloaded whl. Only used when the
urlsis passed.optional
urls– (list[str]) (default [])The list of urls of the whl to be downloaded using bazel downloader. Using this attr makes
extra_pip_argsanddownload_onlyignored.optional
whl_file– (label) (default None)The whl file that should be used instead of downloading or building the whl.
optional
whl_patches– (dict[label,str]) (default {})A label-keyed-string dict with patch files as keys and json-strings as values.
The keys are labels to the patch file to apply.
The values describe what to apply the patch to and how to apply it. It is encoded as
json.encode(struct([whls], patch_strip]), wherewhlsis alist[str] of wheel filenames, andpatch_stripis a number.So it will look something like this:
"//path/to/package:my.patch": json.encode(struct( whls = ["something-2.7.1-py3-none-any.whl"], patch_strip = 1, )),
The patch is applied within the scope of the .whl file. I.e. you should create the patch from the same place you unziped the wheel.
This is to maintain flexibility and correct bzlmod extension interface until we have a better way to define whl_library and move whl patching to a separate place. INTERNAL USE ONLY.
optional
- Envvars:
RULES_PYTHON_REPO_DEBUG