//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:
Returns:

bool Whether or not the target is from a rules_python generated toolchain.

py_repositories(transition_settings=[])

Runtime dependencies that users must install.

This function should be loaded and called in the user’sWORKSPACE.Withbzlmod enabled, this function is not needed sinceMODULE.bazel handles transitive deps.

Args:
  • transition_settings(default[])

    A list of labels that terminal rules transition onby default.

python_register_multi_toolchains(name,python_versions,default_version=None,minor_mapping=None,**kwargs)

Convenience macro for registering multiple Python toolchains.

Args:
python_register_toolchains(name,python_version,register_toolchains=True,register_coverage_tool=False,set_python_version_constraint=False,tool_versions=None,platforms={'aarch64-apple-darwin':struct(arch='aarch64',compatible_with=['@platforms//os:macos','@platforms//cpu:aarch64'],flag_values={},os_name='osx',target_settings=['@@//python/config_settings:_is_py_freethreaded_no']),'aarch64-apple-darwin-freethreaded':struct(arch='aarch64',compatible_with=['@platforms//os:macos','@platforms//cpu:aarch64'],flag_values={},os_name='osx',target_settings=['@@//python/config_settings:_is_py_freethreaded_yes']),'aarch64-pc-windows-msvc':struct(arch='aarch64',compatible_with=['@platforms//os:windows','@platforms//cpu:aarch64'],flag_values={},os_name='windows',target_settings=['@@//python/config_settings:_is_py_freethreaded_no']),'aarch64-pc-windows-msvc-freethreaded':struct(arch='aarch64',compatible_with=['@platforms//os:windows','@platforms//cpu:aarch64'],flag_values={},os_name='windows',target_settings=['@@//python/config_settings:_is_py_freethreaded_yes']),'aarch64-unknown-linux-gnu':struct(arch='aarch64',compatible_with=['@platforms//os:linux','@platforms//cpu:aarch64'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_no','@@//python/config_settings:_is_py_linux_libc_glibc']),'aarch64-unknown-linux-gnu-freethreaded':struct(arch='aarch64',compatible_with=['@platforms//os:linux','@platforms//cpu:aarch64'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_yes','@@//python/config_settings:_is_py_linux_libc_glibc']),'armv7-unknown-linux-gnu':struct(arch='arm',compatible_with=['@platforms//os:linux','@platforms//cpu:armv7'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_no','@@//python/config_settings:_is_py_linux_libc_glibc']),'armv7-unknown-linux-gnu-freethreaded':struct(arch='arm',compatible_with=['@platforms//os:linux','@platforms//cpu:armv7'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_yes','@@//python/config_settings:_is_py_linux_libc_glibc']),'i386-unknown-linux-gnu':struct(arch='x86_32',compatible_with=['@platforms//os:linux','@platforms//cpu:i386'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_no','@@//python/config_settings:_is_py_linux_libc_glibc']),'i386-unknown-linux-gnu-freethreaded':struct(arch='x86_32',compatible_with=['@platforms//os:linux','@platforms//cpu:i386'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_yes','@@//python/config_settings:_is_py_linux_libc_glibc']),'ppc64le-unknown-linux-gnu':struct(arch='ppc',compatible_with=['@platforms//os:linux','@platforms//cpu:ppc'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_no','@@//python/config_settings:_is_py_linux_libc_glibc']),'ppc64le-unknown-linux-gnu-freethreaded':struct(arch='ppc',compatible_with=['@platforms//os:linux','@platforms//cpu:ppc'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_yes','@@//python/config_settings:_is_py_linux_libc_glibc']),'riscv64-unknown-linux-gnu':struct(arch='riscv64',compatible_with=['@platforms//os:linux','@platforms//cpu:riscv64'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_no','@@//python/config_settings:_is_py_linux_libc_glibc']),'riscv64-unknown-linux-gnu-freethreaded':struct(arch='riscv64',compatible_with=['@platforms//os:linux','@platforms//cpu:riscv64'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_yes','@@//python/config_settings:_is_py_linux_libc_glibc']),'s390x-unknown-linux-gnu':struct(arch='s390x',compatible_with=['@platforms//os:linux','@platforms//cpu:s390x'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_no','@@//python/config_settings:_is_py_linux_libc_glibc']),'s390x-unknown-linux-gnu-freethreaded':struct(arch='s390x',compatible_with=['@platforms//os:linux','@platforms//cpu:s390x'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_yes','@@//python/config_settings:_is_py_linux_libc_glibc']),'x86_64-apple-darwin':struct(arch='x86_64',compatible_with=['@platforms//os:macos','@platforms//cpu:x86_64'],flag_values={},os_name='osx',target_settings=['@@//python/config_settings:_is_py_freethreaded_no']),'x86_64-apple-darwin-freethreaded':struct(arch='x86_64',compatible_with=['@platforms//os:macos','@platforms//cpu:x86_64'],flag_values={},os_name='osx',target_settings=['@@//python/config_settings:_is_py_freethreaded_yes']),'x86_64-pc-windows-msvc':struct(arch='x86_64',compatible_with=['@platforms//os:windows','@platforms//cpu:x86_64'],flag_values={},os_name='windows',target_settings=['@@//python/config_settings:_is_py_freethreaded_no']),'x86_64-pc-windows-msvc-freethreaded':struct(arch='x86_64',compatible_with=['@platforms//os:windows','@platforms//cpu:x86_64'],flag_values={},os_name='windows',target_settings=['@@//python/config_settings:_is_py_freethreaded_yes']),'x86_64-unknown-linux-gnu':struct(arch='x86_64',compatible_with=['@platforms//os:linux','@platforms//cpu:x86_64'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_no','@@//python/config_settings:_is_py_linux_libc_glibc']),'x86_64-unknown-linux-gnu-freethreaded':struct(arch='x86_64',compatible_with=['@platforms//os:linux','@platforms//cpu:x86_64'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_yes','@@//python/config_settings:_is_py_linux_libc_glibc']),'x86_64-unknown-linux-musl':struct(arch='x86_64',compatible_with=['@platforms//os:linux','@platforms//cpu:x86_64'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_no','@@//python/config_settings:_is_py_linux_libc_musl']),'x86_64-unknown-linux-musl-freethreaded':struct(arch='x86_64',compatible_with=['@platforms//os:linux','@platforms//cpu:x86_64'],flag_values={},os_name='linux',target_settings=['@@//python/config_settings:_is_py_freethreaded_yes','@@//python/config_settings:_is_py_linux_libc_musl'])},minor_mapping=None,**kwargs)

Convenience macro for users which does typical setup.

Withbzlmod enabled, this function is not needed sincerules_python ishandling everything. In order to override the default behaviour from theroot module one can see the docs for thepython extension.

  • 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 morecontrol.

Args:
  • name(str)

    base name for all created repos, e.g. “python_3_8”.

  • python_version(str)

    the Python version.

  • register_toolchains(bool)(defaultTrue)

    Whether or not to register the downloaded toolchains.

  • register_coverage_tool(bool)(defaultFalse)

    Whether or not to register thedownloaded coverage tool to the toolchains.

  • set_python_version_constraint(bool)(defaultFalse)

    When set toTrue,target_compatible_with for the toolchains will include a versionconstraint.

  • tool_versions(dict)(defaultNone)

    contains a mapping of version with SHASUMand platform info. If not supplied, the defaults inpython/versions.bzl will be used.

  • platforms(dict[str,struct])(default{“aarch64-apple-darwin”: struct(arch = “aarch64”, compatible_with = [“@platforms//os:macos”, “@platforms//cpu:aarch64”], flag_values = {}, os_name = “osx”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_no”]), “aarch64-apple-darwin-freethreaded”: struct(arch = “aarch64”, compatible_with = [“@platforms//os:macos”, “@platforms//cpu:aarch64”], flag_values = {}, os_name = “osx”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_yes”]), “aarch64-pc-windows-msvc”: struct(arch = “aarch64”, compatible_with = [“@platforms//os:windows”, “@platforms//cpu:aarch64”], flag_values = {}, os_name = “windows”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_no”]), “aarch64-pc-windows-msvc-freethreaded”: struct(arch = “aarch64”, compatible_with = [“@platforms//os:windows”, “@platforms//cpu:aarch64”], flag_values = {}, os_name = “windows”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_yes”]), “aarch64-unknown-linux-gnu”: struct(arch = “aarch64”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:aarch64”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_no”, “@@//python/config_settings:_is_py_linux_libc_glibc”]), “aarch64-unknown-linux-gnu-freethreaded”: struct(arch = “aarch64”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:aarch64”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_yes”, “@@//python/config_settings:_is_py_linux_libc_glibc”]), “armv7-unknown-linux-gnu”: struct(arch = “arm”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:armv7”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_no”, “@@//python/config_settings:_is_py_linux_libc_glibc”]), “armv7-unknown-linux-gnu-freethreaded”: struct(arch = “arm”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:armv7”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_yes”, “@@//python/config_settings:_is_py_linux_libc_glibc”]), “i386-unknown-linux-gnu”: struct(arch = “x86_32”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:i386”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_no”, “@@//python/config_settings:_is_py_linux_libc_glibc”]), “i386-unknown-linux-gnu-freethreaded”: struct(arch = “x86_32”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:i386”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_yes”, “@@//python/config_settings:_is_py_linux_libc_glibc”]), “ppc64le-unknown-linux-gnu”: struct(arch = “ppc”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:ppc”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_no”, “@@//python/config_settings:_is_py_linux_libc_glibc”]), “ppc64le-unknown-linux-gnu-freethreaded”: struct(arch = “ppc”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:ppc”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_yes”, “@@//python/config_settings:_is_py_linux_libc_glibc”]), “riscv64-unknown-linux-gnu”: struct(arch = “riscv64”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:riscv64”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_no”, “@@//python/config_settings:_is_py_linux_libc_glibc”]), “riscv64-unknown-linux-gnu-freethreaded”: struct(arch = “riscv64”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:riscv64”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_yes”, “@@//python/config_settings:_is_py_linux_libc_glibc”]), “s390x-unknown-linux-gnu”: struct(arch = “s390x”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:s390x”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_no”, “@@//python/config_settings:_is_py_linux_libc_glibc”]), “s390x-unknown-linux-gnu-freethreaded”: struct(arch = “s390x”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:s390x”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_yes”, “@@//python/config_settings:_is_py_linux_libc_glibc”]), “x86_64-apple-darwin”: struct(arch = “x86_64”, compatible_with = [“@platforms//os:macos”, “@platforms//cpu:x86_64”], flag_values = {}, os_name = “osx”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_no”]), “x86_64-apple-darwin-freethreaded”: struct(arch = “x86_64”, compatible_with = [“@platforms//os:macos”, “@platforms//cpu:x86_64”], flag_values = {}, os_name = “osx”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_yes”]), “x86_64-pc-windows-msvc”: struct(arch = “x86_64”, compatible_with = [“@platforms//os:windows”, “@platforms//cpu:x86_64”], flag_values = {}, os_name = “windows”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_no”]), “x86_64-pc-windows-msvc-freethreaded”: struct(arch = “x86_64”, compatible_with = [“@platforms//os:windows”, “@platforms//cpu:x86_64”], flag_values = {}, os_name = “windows”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_yes”]), “x86_64-unknown-linux-gnu”: struct(arch = “x86_64”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:x86_64”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_no”, “@@//python/config_settings:_is_py_linux_libc_glibc”]), “x86_64-unknown-linux-gnu-freethreaded”: struct(arch = “x86_64”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:x86_64”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_yes”, “@@//python/config_settings:_is_py_linux_libc_glibc”]), “x86_64-unknown-linux-musl”: struct(arch = “x86_64”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:x86_64”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_no”, “@@//python/config_settings:_is_py_linux_libc_musl”]), “x86_64-unknown-linux-musl-freethreaded”: struct(arch = “x86_64”, compatible_with = [“@platforms//os:linux”, “@platforms//cpu:x86_64”], flag_values = {}, os_name = “linux”, target_settings = [“@@//python/config_settings:_is_py_freethreaded_yes”, “@@//python/config_settings:_is_py_linux_libc_musl”])})

    platforms to create toolchainrepositories for. Keys are platform names, and values are platform_infostructs. Note that only a subset is created, depending on what’savailable intool_versions.

  • minor_mapping(dict[str,str])(defaultNone)

    contains a mapping fromX.Y toX.Y.Zversion.

  • kwargs – passed to eachpython_repository call.

Returns:

On workspace, returns None.

On bzlmod, returns adict[str,platform_info], which is thesubset ofplatforms that it created repositories for.

reporulepython_repository(name,platform,python_version,release_filename,repo_mapping,sha256,auth_patterns={},coverage_tool='',distutils=None,distutils_content='',ignore_root_user_error=True,netrc='',patch_strip=1,patches=[],strip_prefix='',url='',urls=[])

Fetches the external tools needed for the Python toolchain.

Attributes:
  • name(Name)

    A unique name for this repository.

    mandatory

  • platform(str)

    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])

    InWORKSPACE context 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 isnot supported inMODULE.bazel context (when invoking a repository rule inside a module extension’s implementation function).

    optional

  • sha256(str)

    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 frompy_binaryandpy_test targets.

    The target is accepted as a string by the python_repository and evaluated withinthe context of the toolchain repository.

    For more information seepy_runtime.coverage_tool.

    optional

  • distutils(label)(defaultNone)

    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)(defaultTrue)

    Noop, will be removed in the next major release

    optional

  • netrc(str)(default“”)

    .netrc file to use for authentication; mirrors the eponymous attribute from http_archive

    optional

  • patch_strip(int)(default1)

    Same as the –strip argument of Unix patch.

    Note

    In the future the default value will be set to0, to mimic the well knownfunction defaults (e.g.single_version_override forMODULE.bazel files.

    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

  • url(str)(default“”)

    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