exp: multi-arch whl_library in bzlmod
This is a reasonably polished POC to support bazel downloader to fetch wheels and to setup multi-platform whl targets which would allow us to almost correctly setup the dependency tree.
In general usecase this yield great performance improvements whilst running the tests as the fetching of the wheels is much faster.
Ideas for improvements:
- [x] Setup auth for the wheel fetching.
- [x] Test with a private registry.
- [ ] Add support for wheels located on the local file system.
- [x] Make the whl metadata fetching optional.
I've split out #1626, #1627, #1628 for easier review in the future, the rest of the changes are either new files or bzlmod/pip.bzl related changes.
Given the latest developments and https://discuss.python.org/t/lock-files-again-but-this-time-w-sdists/46593, this is paused for some time.
Some notes on the implementation of how this could be done reasonably cleanly.
- The
pip.parsetag class can create the following repos: pip hub, pip spoke repos, whlhttp_filerepos and whl hub repo. The whl hub repo is common for all pip hub repos and the pip spoke repos use the whl files downloaded byhttp_filerepos. - The
whl hub repois loaded byrules_pythonso that we can very easily pass around thewhllabel references when constructing the pip spoke repos. - Ideally the
whl hub repois set as a default in a configurable attribute. - The
whlrepos are setup in the same way as #1744 is done, but for multiple platforms.
If we would need to somehow split the whl hub and pip hub generation, then we would need to do as follows:
- Have a
pypi.indextag class that can parse the lock files and generate the necessary URL and label references to the subset of the PyPI world that we need to include. It would generate a single hub repo with many spokes. Isolated mode of using the extension would still work. - The
pip.parsethen uses the hub repo created bypypi.indextag class. It could have an attributeindex_hub = attr.label()where we could set it to "@pypi_index//:BUILD.bazelafter doinguse_repo(pypi_index, pypi_index = "repo_from_extension")`.
In the second option the user would use it as:
pypi = use_extension("@rules_python//python/extensions/pypi.bzl", "pypi")
# The following can be called multiple times
pypi.index_requirements(
index_url = "foo",
extra_index_urls = ["bar"],
srcs = [
"//:my_requirements.txt",
],
)
use_repo(pypi, "pypi_index")
pip = use_extension("@rules_python//python/extensions/pip.bzl", "pip")
pip.index(index="@pypi_index//:packages.json") # contains the package and the labels to the metadata files for each package.
# Use stuff as previously.
pip.parse(
hub_repo = "pip",
src = "//:my_requirements.txt",
)
Will re-implement this in separate PRs.