rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

exp: multi-arch whl_library in bzlmod

Open aignas opened this issue 2 years ago • 1 comments

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.

aignas avatar Dec 18 '23 08:12 aignas

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.

aignas avatar Dec 18 '23 14:12 aignas

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.

aignas avatar Feb 29 '24 06:02 aignas

Some notes on the implementation of how this could be done reasonably cleanly.

  1. The pip.parse tag class can create the following repos: pip hub, pip spoke repos, whl http_file repos 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 by http_file repos.
  2. The whl hub repo is loaded by rules_python so that we can very easily pass around the whl label references when constructing the pip spoke repos.
  3. Ideally the whl hub repo is set as a default in a configurable attribute.
  4. The whl repos 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:

  1. Have a pypi.index tag 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.
  2. The pip.parse then uses the hub repo created by pypi.index tag class. It could have an attribute index_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",
)

aignas avatar Mar 04 '24 08:03 aignas

Will re-implement this in separate PRs.

aignas avatar Mar 10 '24 11:03 aignas