//python/private/pypi:pkg_aliases.bzl
pkg_aliases is a macro to generate aliases for selecting the right wheel for the right target platform.
If you see an error where the distribution selection error indicates the config setting names this
page may help to describe the naming convention and relationship between various flags and options
in rules_python and the error message contents.
Definitions:
- minor_version:
Python interpreter minor version that the distributions are compatible with.
- suffix:
Can be either empty or
_<os>_<suffix>, which is usually used to distinguish multiple versions used for different target platforms.- os:
OS identifier that exists in
@platforms//os:<os>.- cpu:
CPU architecture identifier that exists in
@platforms//cpu:<cpu>.- python_tag:
The Python tag as defined by the Python Packaging Authority. E.g.
py2.py3,py3,py311,cp311.- abi_tag:
The ABI tag as defined by the Python Packaging Authority. E.g.
none,abi3,cp311,cp311t.- platform_tag:
The Platform tag as defined by the Python Packaging Authority. E.g.
manylinux_2_17_x86_64.- platform_suffix:
is a derivative of the
platform_tagand is used to implement selection based onlibcorosxversion.
All of the config settings used by this macro are generated by
config_settings, for more detailed documentation on what each config
setting maps to and their precedence, refer to documentation on that page.
The first group of config settings that are as follows:
//_config:is_cp3<minor_version><suffix>is used to select legacypipbasedwhlandsdistwhl_libraryinstances. Whereas other config settings are created whenpip.parse.experimental_index_urlis used.//_config:is_cp3<minor_version>_sdist<suffix>is for wheels built fromsdistinwhl_library.//_config:is_cp3<minor_version>_py_<abi_tag>_any<suffix>for wheels withpy2.py3python_tagvalue.//_config:is_cp3<minor_version>_py3_<abi_tag>_any<suffix>for wheels withpy3python_tagvalue.//_config:is_cp3<minor_version>_<abi_tag>_any<suffix>for any other wheels.//_config:is_cp3<minor_version>_py_<abi_tag>_<platform_suffix>for platform-specific wheels withpy2.py3python_tagvalue.//_config:is_cp3<minor_version>_py3_<abi_tag>_<platform_suffix>for platform-specific wheels withpy3python_tagvalue.//_config:is_cp3<minor_version>_<abi_tag>_<platform_suffix>for any other platform-specific wheels.
Note that wheels with abi3 or none abi_tag values and python_tag values
other than py2.py3 or py3 are compatible with the python version that is
equal or higher than the one denoted in the python_tag. For example: py37
and cp37 wheels are compatible with Python 3.7 and above and in the case of
the target python version being 3.11, rules_python will use
//_config:is_cp311_<abi_tag>_any<suffix> config settings.
For platform-specific wheels, i.e. the ones that have their platform_tag as
something else than any, we treat them as below:
linux_<cpu>tags assume that the targetlibcflavour isglibc, so this is in many ways equivalent to it beingmanylinux, but with an unspecifiedlibcversion.For
osxandlinuxOSes wheel filename will be mapped to multiple config settings:osx_<cpu>andosx_<major_version>_<minor_version>_<cpu>wheremajor_versionandminor_versionare the compatible OSX versions.<many|musl>linux_<cpu>and<many|musl>linux_<major_version>_<minor_version>_<cpu>where the version identifiers are the compatible libc versions.
- get_filename_config_settings(filename, target_platforms, python_version, glibc_versions=None, muslc_versions=None, osx_versions=None, non_whl_prefix='sdist')
Get the filename config settings.
Exposed only for unit tests.
- Args:
filename– the distribution filename (can be a whl or an sdist).target_platforms– list[str], target platforms in “{abi}{os}{cpu}” format.python_version– the python version to generate the config_settings for.glibc_versions– (default None)list[tuple[int, int]], list of versions.
muslc_versions– (default None)list[tuple[int, int]], list of versions.
osx_versions– (default None)list[tuple[int, int]], list of versions.
non_whl_prefix– (default “sdist”)the prefix of the config setting when the whl we don’t have a filename ending with “.whl”.
- Returns:
A tuple:
A list of config settings that are generated by ./pip_config_settings.bzl
The list of default version settings.
- multiplatform_whl_aliases(aliases=[], glibc_versions=[], muslc_versions=[], osx_versions=[])
convert a list of aliases from filename to config_setting ones.
Exposed only for unit tests.
- Args:
aliases– (str|dict[whl_config_setting|str,str]) (default []): The aliases to process. Any aliases that have the filename set will be converted to a dict of config settings to repo names.
glibc_versions– (list[tuple[int,int]]) (default [])list of versions that can be used in this hub repo.
muslc_versions– (list[tuple[int,int]]) (default [])list of versions that can be used in this hub repo.
osx_versions– (list[tuple[int,int]]) (default [])list of versions that can be used in this hub repo.
- Returns:
A dict with of config setting labels to repo names or the repo name itself.
- pkg_aliases(name, actual, group_name=None, extra_aliases=None, **kwargs)
Create aliases for an actual package.
Exposed only to be used from the hub repositories created by
rules_python.- Args:
The name of the package.
actual– (dict[Label|tuple,str] |str)The name of the repo the aliases point to, or a dict of select conditions to repo names for the aliases to point to mapping to repositories. The keys are passed to bazel skylib’s
selects.with_or, so they can be tuples as well.group_name– (str) (default None)The group name that the pkg belongs to.
extra_aliases– (list[str]) (default None)The extra aliases to be created.
kwargs– extra kwargs to pass toget_filename_config_settings.