Skip to content

whl_library: reproducible wheel fetching via ctx.download (hash-pinned) — enable repo_metadata(reproducible=True), Remote Asset API and RRCC eligibility #4315

Open

Description

@carlochessamp

Context

whl_library (and the pip hub repos it generates) fetch wheels by shelling out to pip subprocesses (pip download/pip install --download). This makes repository materialization structurally non-reproducible: the repo rule cannot declare repo_metadata(reproducible=True), and the actual downloads never flow through bazel's downloader (ctx.download).

This has two costly consequences for large repos with many wheels:

  1. Bazel 9.3's remote repo contents cache (--experimental_remote_repo_contents_cache, RRCC) cannot serve pip hub repos — it only caches fetches of reproducible repositories. Every clean checkout / cold CI machine re-downloads the entire resolved wheel set from scratch. (For us: ~750 wheels, re-fetched on every cold machine, every day.)
  2. The Remote Asset API downloader (--remote_downloader / FetchBlob with checksum.sri qualifiers) never sees wheel fetches, so they cannot be deduplicated fleet-wide through a Remote Asset service / CAS.

Why this is feasible

The wheel URLs+hashes are already fully resolved and hash-pinned at generation time (lockfile / requirements with --hash= / the module extension's lock file records). A mode that performs the artifact fetch itself via ctx.download(url, sha256=...) would:

  • make the repo reproducible (deterministic inputs → deterministic outputs),
  • allow repo_metadata(reproducible=True),
  • route downloads through bazel's downloader (URL rewriting/proxies, --remote_downloader FetchBlob, downloader retries), and
  • make wheels eligible for the RRCC remote repo contents cache.

Pip subprocesses would then only be needed for the parts that genuinely require pip (sdist builds from source, metadata extraction), or could be kept behind a flag for compatibility.

Evidence / motivation

From a JFrog data-transfer investigation on our monorepo CI (Bazel 9.3, ~750 pinned wheels per materialization):

  • wheel fetches that go through the downloader are hash-pinned and could be cache-served; today every cold CI machine refetches them (~1–2 GB/day just of downloader-mode wheels, plus the pip-subprocess part which bypasses any mirror/cache entirely and goes straight to files.pythonhosted.org — flaky under load, ReadTimeouts).
  • With --experimental_remote_downloader, every ctx.download in the build becomes a single FetchBlob(uris, checksum.sri) served from the fleet CAS — except wheels, which stay per-machine.
  • We verified the wire format end-to-end (bazel http_header:/http_header_url: qualifiers ↔ bb-remote-asset's http fetcher) — everything is in place except the fetch not originating from ctx.download.

Ask

An opt-in mode for whl_library (or the pip hub/module extension) to fetch pre-resolved, hash-pinned wheels with ctx.download and declare repo_metadata(reproducible=True) — e.g. pip.parse(..., download_mode = "ctx_download") or similar. Happy to contribute/help test if there's interest.

Refs: #2640 (credential helper injection into pip — related plumbing, different problem).

Activity

  1. aignas commented on Oct 23, 2026

    @aignas
    Collaborator

    Thank you for the issue.

    I am not sure which rules_python version you are using, but we already have this implemented on the latest released versions.

    whl_library (and the pip hub repos it generates) fetch wheels by shelling out to pip subprocesses (pip download/pip install --download). This makes repository materialization structurally non-reproducible: the repo rule cannot declare repo_metadata(reproducible=True), and the actual downloads never flow through bazel's downloader (ctx.download).

    This is not always true - i.e. we use pip only for sdist building and only if urls and integrity is not passed. Please update the issue with better information:

    • rules_python version used.
    • bzlmod or not.
    • a small reproduction.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    need: reproNeeds a minimal reproduction

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions