//python:repositories.bzl
This file contains macros to be called during WORKSPACE evaluation.
- is_standalone_interpreter(rctx, python_interpreter_path, logger=None)
Query a python interpreter target for whether or not it’s a rules_rust provided toolchain
- Args:
rctx– (repository_ctx)The repository rule’s context object.
python_interpreter_path– (path)A path representing the interpreter.
logger– (default None)Optional logger to use for operations.
- Returns:
boolWhether or not the target is from a rules_python generated toolchain.
- py_repositories()
Runtime dependencies that users must install.
This function should be loaded and called in the user’s
WORKSPACE. Withbzlmodenabled, this function is not needed sinceMODULE.bazelhandles transitive deps.
- python_register_multi_toolchains(name, python_versions, default_version=None, minor_mapping=None, **kwargs)
Convenience macro for registering multiple Python toolchains.
- Args:
base name for each name in
python_register_toolchainscall.python_versions– (list[str])the Python versions.
default_version– (str) (default None)the default Python version. If not set, the first version in python_versions is used.
minor_mapping– (dict[str,str]) (default None)mapping between
X.YtoX.Y.Zformat. Defaults to the value in//python:versions.bzl.kwargs– passed to eachpython_register_toolchainscall.
- python_register_toolchains(name, python_version, register_toolchains=True, register_coverage_tool=False, set_python_version_constraint=False, tool_versions=None, minor_mapping=None, **kwargs)
Convenience macro for users which does typical setup.
With
bzlmodenabled, this function is not needed sincerules_pythonis handling everything. In order to override the default behaviour from the root module one can see the docs for thepythonextension.Create a repository for each built-in platform like “python_3_8_linux_amd64” - this repository is lazily fetched when Python is needed for that platform.
Create a repository exposing toolchains for each platform like “python_platforms”.
Register a toolchain pointing at each platform.
Users can avoid this macro and do these steps themselves, if they want more control.
- Args:
base name for all created repos, e.g. “python_3_8”.
python_version– (str)the Python version.
register_toolchains– (bool) (default True)Whether or not to register the downloaded toolchains.
register_coverage_tool– (bool) (default False)Whether or not to register the downloaded coverage tool to the toolchains.
set_python_version_constraint– (bool) (default False)When set to
True,target_compatible_withfor the toolchains will include a version constraint.tool_versions– (dict) (default None)contains a mapping of version with SHASUM and platform info. If not supplied, the defaults in python/versions.bzl will be used.
minor_mapping– (dict[str,str]) (default None)contains a mapping from
X.YtoX.Y.Zversion.kwargs– passed to eachpython_repositorycall.
- Returns:
On bzlmod this returns the loaded platform labels. Otherwise None.
- repo rule python_repository(name, platform, python_version, release_filename, repo_mapping, sha256, auth_patterns={}, coverage_tool='', distutils=None, distutils_content='', ignore_root_user_error=False, netrc='', patch_strip=1, patches=[], strip_prefix='', url='', urls=[])
Fetches the external tools needed for the Python toolchain.
- Attributes:
A unique name for this repository.
mandatory
The platform name for the Python interpreter tarball.
mandatory
python_version– (str)The Python version.
mandatory
release_filename– (str)The filename of the interpreter to be downloaded
mandatory
repo_mapping– (dict[str,str])In
WORKSPACEcontext only: 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).This attribute is not supported in
MODULE.bazelcontext (when invoking a repository rule inside a module extension’s implementation function).optional
The SHA256 integrity hash for the Python interpreter tarball.
mandatory
auth_patterns– (dict[str,str]) (default {})Override mapping of hostnames to authorization patterns; mirrors the eponymous attribute from http_archive
optional
coverage_tool– (str) (default “”)This is a target to use for collecting code coverage information from
py_binaryandpy_testtargets.The target is accepted as a string by the python_repository and evaluated within the context of the toolchain repository.
For more information see
py_runtime.coverage_tool.optional
distutils– (label) (default None)A distutils.cfg file to be included in the Python installation. Either distutils or distutils_content can be specified, but not both.
optional
distutils_content– (str) (default “”)A distutils.cfg file content to be included in the Python installation. Either distutils or distutils_content can be specified, but not both.
optional
ignore_root_user_error– (bool) (default False)Whether the check for root should be ignored or not. This causes cache misses with .pyc files.
optional
.netrc file to use for authentication; mirrors the eponymous attribute from http_archive
optional
patch_strip– (int) (default 1)Same as the –strip argument of Unix patch.
Note
In the future the default value will be set to
0, to mimic the well known function defaults (e.g.single_version_overrideforMODULE.bazelfiles.Added in version 0.36.0.
optional
patches– (list[label]) (default [])A list of patch files to apply to the unpacked interpreter
optional
strip_prefix– (str) (default “”)A directory prefix to strip from the extracted files.
optional
The URL of the interpreter to download. Exactly one of url and urls must be set.
optional
urls– (list[str]) (default [])The URL of the interpreter to download. Exactly one of url and urls must be set.
optional
- Envvars:
RULES_PYTHON_REPO_DEBUG