Skip to content

Vendor a PyPI wheel as a download cache of Bazel where a hub reads the requirements - #2212

Open
Mikola Lysenko (mikolalysenko) wants to merge 11 commits into
bazel-guard/vendored-hub-locksfrom
bazel-vendored/pypi-download-cache
Open

Mikola Lysenko (mikolalysenko) wants to merge 11 commits into
bazel-guard/vendored-hub-locksfrom
bazel-vendored/pypi-download-cache

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Vendored mode now works for a PyPI package whose requirements.txt a rules_python pip.parse hub of a Bazel workspace reads: it commits the patched wheel as a download cache that the Bazel build takes, where the checkout shows that this works (rules_python 2.5.0, Bazel 7 to 9), and declines with the reason everywhere else.

Stacked on #2208, the pull request that makes vendored mode decline such a package: this one's base is that pull request's branch, merged in at its current head. Only the commits after it are this change.

Decisions for the maintainer

  1. socket-patch writes .bazelrc, which it has never done. One pair of lines per patch at the Bazel root: a comment line of socket-patch's own and common --distdir=<directory from the Bazel root>. They are kept the way the .bazelignore lines for Go copies are, by the same code: added at the end, removed with the directory so that the file is byte for byte the one of before, never written through a link, and declined for good by commenting the line out. A .bazelrc left empty is removed, also when it was an empty file of yours, as with .bazelignore.
    The alternative was measured by hand and not built: a block at the end of the root MODULE.bazel that puts a repository over the committed wheel in the place of the hub's (http_file with a relative file: URL and the sha256, rules_python's whl_archive, override_repo). It fails the build on a changed copy even when the patch host is reachable, and it works behind a downloader config that blocks every host. Against it: it names a private rule of rules_python, so it needs a table per release; it needs a bazel_dep on package_metadata; Bazel drops it under --ignore_dev_dependency and when the checkout is not the root module; and it replaces the hub's repository without what the hub passes to it, so a user's own pip.override patch of the wheel is dropped without a message (measured on Bazel 9.3.2).
  2. The line of requirements.txt is the hosted line. That is what makes rules_python build it, and it brings the limits below: pip outside Bazel needs the patch host, Bazel replaces a bad copy from the patch host without saying so, a relock leaves a green unpatched build, and vendor --check is the only thing that holds the committed wheel to the patch.
  3. The gate is narrow. rules_python 2.5.0-rc4 and 2.5.0 only (one commit), read from MODULE.bazel.lock. A checkout without that lock is declined with "build once". Every later rules_python release needs a build and one more entry in the list. An rc file that imports an absolute path and a read-only .bazelrc decline too.
  4. Lockfile discovery reads the vendor ledger in this one case. The line looks like a hosted pin, so discovery reads it as one; where a ledger entry of this form wrote the line, discovery makes it the vendored reference of that entry. Without this, list, rollback, a bare scan and the takeover logic would see a hosted pin beside a vendored entry. Everywhere else discovery still decides from lock files alone.
  5. --allow-vendored-in-bazel keeps its meaning. It says that no build takes the project's packages from the hub, so the path line is written, also where the cache form would be.
  6. Size. About 650 lines of implementation code, above the 300 to 500 estimated for this wiring. The bazel line budget is 2865, the count of this tree.

What the code does today

Where a pip.parse reads a requirements file that vendored mode would rewrite, vendored mode declines the package (vendor_pypi_bazel_hub, exit 1, nothing written): the path line it writes, ./.socket/vendor/pypi/<uuid>/<wheel>, makes rules_python fail the build of everything the hub serves. --allow-vendored-in-bazel lifts that and writes the path line.

What changes

Where it works. scan --mode vendored, get --mode vendored and vendor write three things:

  1. the package's line of requirements.txt exactly as hosted mode writes it, by hosted mode's own rewriter: <name> @ <URL of the wheel on the patch host> --hash=sha256:<hex>;

  2. the patched wheel, fetched once, at .socket/vendor/pypi/<uuid>/ under the file name its URL ends in, with its ledger entry;

  3. in the .bazelrc at the Bazel root:

    # socket-patch: the committed copy of a patched wheel, for Bazel's downloads (to opt out, comment out the next line)
    common --distdir=.socket/vendor/pypi/<uuid>
    

rules_python fetches a wheel that a requirement names by its URL with Bazel's downloader, by the sha256 of the line, and Bazel takes a file of that name and checksum from a --distdir before it asks a host. The path is relative because Bazel reads it from the workspace root and takes %workspace% in this option literally. Each patch gets a line for its own directory: a --distdir is flat and searched by file name, and two patches of one release have wheels of one name.

The form is written only where all of this can be read from the checkout:

  • the project pins in requirements.txt alone, with hashes, and the package's requirement is one exact pin (no extras, marker, option, comment or indent);
  • a pip.parse names that file by requirements_lock and names no other file of the project; every call of the hub is written out and runs, nothing of the module files is in doubt, and no WORKSPACE file defines repositories;
  • MODULE.bazel.lock says that Bazel selected rules_python 2.5.0-rc4 or 2.5.0, read the way the release of rules_jvm_external is read (one function now serves both; the messages of the Maven lane are unchanged);
  • the checkout names Bazel 7, 8 or 9, or names none and has a lock of version 13 to 28;
  • no rc file of the checkout names a downloader config, --repository_disable_download or a remote downloader, all of them can be read, and none imports an absolute path: that file is outside the checkout, it is not read, and it is where the settings of a site's mirror usually are;
  • .bazelrc is no symbolic link and not read-only, and the project's path holds nothing an rc line reads otherwise.

Where it declines. Everywhere else, with vendor_pypi_bazel_hub as before, nothing written and no wheel fetched. Where a pip.parse was read with certainty, the message now ends with the condition that failed. The question is asked again where the lock is about to be written, because a run that takes a hosted pin over first puts the registry's pin back; if that pin is one the form is not written for, the run declines under the same code and the hosted pin stays.

A hub that names a file which only brings the project's requirements.txt in with -r is declined: no build through such a file is shown to take a committed wheel. That holds for every call of the hub, whichever is written first. A requirement that names the package by a URL of the user's own is declined before anything is fetched (no scan finds a package in such a line; get for the release does).

A package that already is a download cache keeps passing while requirements.txt holds the line as the run wrote it. A line that has been changed since (a comment after it, its hash moved to a line of its own) declines the package before anything is fetched, and the committed wheel and its .bazelrc line stay: put the line back, or run socket-patch vendor --revert and vendor again.

Two refusals only the download can show: the URL the patch service served the wheel from is not one hosted mode would pin for this patch, or what it serves is not a wheel for every platform (-none-any.whl), which is the one kind the form was built with. Such a run fails as apply_failed with an error that starts vendor_pypi_bazel_hub:, as a wiring failure of every vendored backend is reported, and a wheel that an earlier run committed stays where it is.

The other commands. list shows a vendored package. vex attests it as vendored and not_affected. vendor --check verifies the committed wheel against the patch and that the line is still there. vendor --revert, rollback and remove restore requirements.txt and .bazelrc byte for byte and delete the directory, with no host. A later run writes nothing. A hosted scan takes the package over. A newer patch replaces line, wheel and pair.

Where nothing changes. Outside a Bazel workspace; in a workspace whose hubs read none of the project's files; for a package already vendored by a path; for RubyGems; in hosted and agent mode. A binary of the base and one of this change were run side by side over 80 command sequences in such places, and over 16 in a project already vendored by a path: every exit code, every byte of output and every file is the same, with the time stamps of the run (vendoredAt) set aside.

Limits

  • pip outside Bazel reads the same line and asks the patch host. It does not take the committed copy.
  • With the patch host unreachable, a changed or missing copy fails the build. With the host reachable, Bazel passes over such a copy without a message and downloads the pinned wheel: never other bytes, but it never says the copy is wrong. Run socket-patch vendor --check in CI.
  • A relock (pip-compile, a version bump) writes the registry's pin back over the line. The build is then green and unpatched, and the copy and its .bazelrc line stay behind without effect. socket-patch vendor --check fails on that, and the next scan pins the package again; that scan asks the patch service for the wheel once more, also where the committed copy is intact.
  • A machine whose repository cache already holds the wheel does not read the copy at all.
  • A downloader config that blocks the patch host fails the build although the copy is committed, which is why the form is declined where an rc file of the checkout names one or imports a file from outside the checkout. A config that the checkout does not show is not seen: one given on the command line, in an rc file of the home directory or of the machine, or in a file that a try-import names and this checkout does not have.
  • A --lockfile_mode=error build fails right after the command on Bazel 8.5 and later, until a build has updated MODULE.bazel.lock, as in hosted mode.
  • A .bazelrc that cannot be written when the command gets to it (it became read-only since, or the root directory takes no new file) is the warning bazelrc_not_updated, which names the line to add; without the line the build downloads the wheel from the patch host.
  • vendor --check does not look at the .bazelrc line.

Contents

Lines
Implementation +1056 / -140, 621 of them code
Unit tests in src +480 / -4
Real-Bazel and hermetic flows (e2e_bazel_build/pypi.rs, harness.rs) +722 / -43
Docs (docs/ecosystems.md, CLI_CONTRACT.md) +167 / -11
Workflow path filters +4 / -1

Two new files hold most of it: bazel/distdir.rs (the .bazelrc lines and what the workspace must show) and vendor/pypi_distdir.rs (the line, the gate, the wiring, the claim in discovery). bazel/ignore.rs now lends its line editor to both files, and bazel/maven.rs its reading of a ruleset's release. The first commit is tests only: the same flow with every file written by hand, which passes on the product code of the base.

What it proves, and where

  • Real Bazel 9.3.2, 8.8.2 and 7.7.2 (macOS), the three pypi:: flows as the workflow runs them. In a checkout whose .bazelrc already has a --distdir line of its own, the command writes the three files of the by-hand flow byte for byte; vendor --check passes and names a changed byte; with the patch host stopped, a new output base with no copy in the repository cache fails on one changed byte and builds the patched package from the copy as committed, from a sub-directory too; vendor --revert with the host stopped restores every file and the unpatched build; a checkout without Bazel's lock is declined and builds unpatched.
  • Real Bazel 9.3.2, the first commit alone. With hosted mode's pin, the wheel copied into the checkout and the --distdir line written by hand, on the product code of the base: the same failed and patched builds.
  • Without Bazel, through the binary. The whole life of a cached wheel, a line changed since it was written, a newer patch, a project below the Bazel root, a run that fails after its fetch over a committed wheel, one checkout per condition of the gate (each declined with its reason and nothing fetched), and the takeover of a hosted pin the form is not written for. Held against a binary of the base, the five new flows fail and the other 55 tests of the target pass.
  • By hand, before this change, on Bazel 9.3.2, 8.8.2 and 7.7.2 with rules_python 2.5.0-rc4: the wiring itself, the silent replacement with the host up, and the failure behind a downloader config.

Not covered

  • At the head of this pull request the three pypi:: flows ran on real Bazel 9.3.2 only (they pass, and the two vendored ones fail against a binary of the base's product code, as they must); 8.8.2 and 7.7.2 ran one revision earlier and run in CI. The whole core unit suite was not rerun after the review's commit; the unit tests of the changed modules and the hermetic targets were.
  • get --mode vendored, vendor for a manifest record and the eject of a hosted pin write the form through the same backend; they were run by the side-by-side comparison, not by a test of this repository.
  • A project below the Bazel root: a test without Bazel in this repository; built by hand on Bazel 9.3.2 and 7.7.2.
  • A checkout whose rc file imports an absolute path that names a downloader config was not built on Bazel: the decline rests on the measured failure behind such a config.
  • A wheel with a platform tag and a source distribution are declined, not built. A second Python version in the hub, requirements_by_platform (declined), rules_python releases other than 2.5.0, Linux outside CI, Windows, remote execution.

Code review

Nine findings on the first revision; five are fixed in the last commit, four are not.

Fixed, each with a test that fails without the fix:

  • A URL of the user's own for the package was taken for a hosted pin, so get <purl> --mode vendored fetched the wheel and failed only at the line. It is declined before the fetch now.
  • A second hub that reaches requirements.txt through -r was judged only when its call came first. Every call is asked now.
  • The form was written for a source distribution or a wheel of one platform, which no build has run. Only a -none-any.whl gets it.
  • The .bazelrc line was kept for a project moved to a path with a blank, which would have put a second word on every Bazel command. Such a project gets no line.
  • The ledger was parsed afresh on each ask. The read-only asks share one parse.

Not fixed:

  • After a relock the next vendored scan needs the patch service, where the path form re-wires a committed wheel offline. The line holds the URL of a grant, and a run takes it from the grant; re-using the URL of an earlier grant was not built or measured. It is in the limits.
  • Discovery reads the vendor ledger to tell this line from a hosted pin (decision 4), and only for a checkout on disk. A reader that is handed the files alone sees a hosted pin; if it moves the line to a newer patch, the old wheel, its ledger entry and its .bazelrc line stay behind until vendor --check or the next vendored run finds them. The build is not broken by that: Bazel takes the wheel the line names from the patch host. A marker in the line itself would remove the dependence and changes what the line is; that is the maintainer's call.
  • The gate is asked up to three times per package in one run, each time reading the module files and Bazel's lock. Time only; the second ask is what tells a package already vendored by a path from one that gets this form.
  • About twenty lines that report an unwritable file exist in both line editors. Left for a change of its own.

The branch of the pull request this is stacked on gained a commit during the review (a hub file that brings the project's in with -r is declined there); it is merged in, and the download cache follows it.


Generated by Claude Code

Tests only. Vendored mode declines a PyPI package where a rules_python
`pip.parse` reads the project's `requirements.txt`: the path line it
would write breaks the build of everything the hub serves
(pypi::vendored_pip_parse, unchanged). This adds the flow of a form that
rules_python does build from a committed wheel, with every file of it
written by hand, to show what Bazel makes of those files before any
product code writes them.

pypi::vendored_download_cache, in the fixture of the hosted flow
(rules_python 2.5.0-rc4, `pip.parse(requirements_lock =
"//:requirements.txt")`, a hashed `requirements.txt`), in a checkout
whose `.bazelrc` already has a `--distdir` line of the user's own:

- `scan --mode hosted --yes` pins the package as it does today: the line
  becomes `spvictim @ <URL of the wheel on the patch host>
  --hash=sha256:<hex>`.
- By hand, the patched wheel is copied to
  `.socket/vendor/pypi/<uuid>/<the file name its URL ends in>`, and the
  `.bazelrc` of the fixture gets two lines at its end: a comment, and
  `common --distdir=.socket/vendor/pypi/<uuid>`.
- Nothing has fetched the wheel at that point: the patch host has no
  request for it, and Bazel's repository cache has no entry of its
  sha256. The patch host is then stopped. The index stays up, because the
  hub asks it about the other packages of the lock.
- In a new output base, with one byte of the committed copy changed, the
  build fails: Bazel passes over a copy whose sha256 is not the pin's and
  asks the patch host, which refuses the connection.
- In another new output base, with the copy as committed, `bazel build`
  and `bazel run //:consumer` print the patched marker. The repository
  cache holds the wheel afterwards, and Bazel changed no file of the
  checkout but its own lock (from 8.5 on, as after a hosted scan).

rules_python fetches a wheel that a requirement names by its URL with
Bazel's own downloader, by the sha256 of the line, and Bazel looks in
each `--distdir` for a file of the download's name and checksum before it
asks a host. The path is relative on purpose: Bazel reads it from the
workspace root, and takes `%workspace%` in this option literally.

It passes on Bazel 9.3.2 with the product code as it is.

For the flow, the harness gets a stand-in on a listener of its own that a
flow can stop (`StandIn::alone`, `StandIn::stop`: the listeners of
`StandIn::start` come from a pool and go on answering), and a check of
Bazel's repository cache (`Cell::cached`). The stand-ins of the PyPI
flows can now put the Socket API and the patch host on such a server,
apart from the index (`Vendoring::apart`); `Vendoring::new` serves all of
them from one server, as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…e requirements

Where a rules_python `pip.parse` reads the project's `requirements.txt`,
vendored mode declined the package (`vendor_pypi_bazel_hub`): the path
line it writes breaks the build of everything the hub serves. It now
writes another form there, wherever the checkout shows that Bazel builds
it, and declines as before everywhere else, with the condition that
failed at the end of the message.

What is written. The flow of the previous commit showed, with every file
written by hand, that Bazel builds a committed wheel when three things
are in the checkout. `scan --mode vendored`, `get --mode vendored` and
`vendor` now write them:

1. the package's line of `requirements.txt` exactly as hosted mode
   writes it, by hosted mode's own rewriter:
   `<name> @ <URL of the wheel on the patch host> --hash=sha256:<hex>`;
2. the patched wheel, fetched once, at `.socket/vendor/pypi/<uuid>/`
   under the file name its URL ends in, with what vendored mode keeps
   beside every wheel and its ledger entry;
3. in the `.bazelrc` at the Bazel root, under a comment line of
   socket-patch's own, `common --distdir=<that directory, from the Bazel
   root>`.

rules_python fetches a wheel that a requirement names by its URL with
Bazel's downloader, by the sha256 of the line, and Bazel takes a file of
the download's name and checksum from a `--distdir` before it asks a
host. Measured by hand with rules_python 2.5.0-rc4 on Bazel 9.3.2, 8.8.2
and 7.7.2: a fresh clone builds the patched package with the patch host
stopped, a new output base and no copy of the wheel in the repository
cache, also from a sub-directory and beside a `--distdir` of the user's
own. Bazel reads a relative path from the workspace root and takes
`%workspace%` in this option literally, so the path is relative.

One line per patch directory, not one directory for all patches: a
`--distdir` is flat and searched by file name, two patches of one
release have wheels of one name, and the uuid directory is the unit
that vendored mode writes, checks, sweeps and removes.

This is the first time socket-patch edits `.bazelrc`. The lines are kept
as the `.bazelignore` lines for Go copies are, by the same code:
`bazel::ignore` now takes the file, the comment and what counts as
already there (`Kept`, `update`), and `bazel::distdir::sync` uses it. A
pair is added at the end of the file for the directory of each such
wheel, taken away once the directory is gone, which leaves the file of
before byte for byte, never written through a link, and declined for
good by a user who comments the line out. A `.bazelrc` left empty is
removed, also one that was an empty file of the user's, as with
`.bazelignore`. `commands::sync_bazelignore`, which every command that
can write or remove a copy already calls once, brings both files in
line; a file that cannot be written when the command gets to it is the
warning `bazelrc_not_updated`, which names the line to add.

When it is written (`vendor::pypi_distdir::gate`,
`bazel::distdir::ready`, `bazel::built::alone`). Each condition is read
from the checkout, no Bazel is run, and each failure declines:

- the project pins in `requirements.txt` alone, in pip's hash-checking
  mode, and the package's requirement is one exact pin with its hashes,
  which hosted mode's rewriter turns into the plain line above (extras,
  a marker, an option, a comment or an indent decline);
- a `pip.parse` names that file by `requirements_lock` and names no
  other file of the project; every call of the hub is a statement of its
  own and written out, nothing of the module files is in doubt, and no
  `WORKSPACE` file defines repositories;
- Bazel selected rules_python 2.5.0-rc4 or 2.5.0 (one commit), read as
  the Maven lane reads its ruleset's release: the one `source.json` that
  `MODULE.bazel.lock` records, against what `MODULE.bazel` asks for
  (`bazel::maven::asked` now takes the module, and the reading itself
  is one function for both lanes, `bazel::maven::known_release`, with
  the Maven lane's messages as they were). Releases before it fetch a
  wheel through other code, which no build here has run;
- the checkout names Bazel 7, 8 or 9, or names none and has a lock of
  version 13 to 28, which 7.5.0 to 9.3.2 write;
- no rc file of the checkout names a downloader config,
  `--repository_disable_download` or a remote downloader, all of them
  can be read, and none imports an absolute path: Bazel refuses a
  download that such a config blocks before it looks in a `--distdir`
  (measured), and a file outside the checkout, where a site keeps the
  settings of its mirror, is not read (`bazel::rc::mentions` reports
  such an import to a caller that asks for it; the Maven lane does not);
- `.bazelrc` is no symbolic link and not read-only, and the project's
  path from the Bazel root holds nothing an rc line reads otherwise.

The same question is asked twice: by `vendor::bazel_hub::refusals`,
before anything is fetched, and by the backend where it is about to
write (`bazel_hub::download_cache`), because a run that takes a hosted
pin over is let through to put the registry's pin back and that pin may
be one the form is not written for. The run then declines and the
hosted pin stays.

A package that already is a download cache passes while
`requirements.txt` holds the line as the run wrote it. A line that has
been changed since (a comment after it, its hash moved to a line of its
own) declines the package before anything is fetched: a run over it
would fetch the wheel, find that it cannot write the line, and sweep
the directory, which is the committed one. For the failures that only
the fetch can show (the URL the patch service gave is none hosted mode
would pin), a wheel that an earlier run committed stays where it is.

With `--allow-vendored-in-bazel` the path line is written, here too: the
switch says that no build takes the project's packages from the hub.

How the other commands see it. The ledger entry is an ordinary one of
the requirements flavor whose record holds the URL line in the place of
the path line, so the revert of that flavor restores the pin
(`pypi_requirements` accepts that line as the entry's own). Lockfile
discovery reads the line as a hosted pin; where a ledger entry of this
form wrote it, `pypi_distdir::claim` makes it the vendored reference of
that entry. So `list` shows a vendored package, `vendor --check`
verifies the committed wheel and that the line is still there, a bare
`scan` stays in vendored mode, a later run writes nothing,
`vendor --revert`, `rollback` and `remove` restore `requirements.txt`
and `.bazelrc` byte for byte and delete the directory, a hosted scan
takes the package over, and a newer patch replaces line, wheel and
pair. `vex` attests the package as vendored and not affected: the hub
builds that wheel by the sha256 of the line, as it builds a hosted pin,
so the judgement that a hub builds nothing from a vendored PyPI copy
passes over it.

What it does not do, which the run says in a warning
(`vendor_pypi_bazel_download_cache`) and the docs repeat: pip outside
Bazel reads the same line and asks the patch host; with the host
reachable Bazel passes over a changed or missing copy without a message
and downloads the pinned wheel (never other bytes); `vendor --check` is
what holds the committed wheel to the patch. A `--lockfile_mode=error`
build fails right after the command on Bazel 8.5 and later until a
build has updated `MODULE.bazel.lock`, as in hosted mode. A relock
writes the registry's pin back: the build is then green and unpatched
until the next scan, and `vendor --check` fails meanwhile. A downloader
config that the checkout does not show (the command line, an rc file of
the home directory, a `try-import` of a file the checkout does not
have) is not seen.

Nothing changes outside a Bazel workspace, in a workspace whose hubs
read none of the project's files, for RubyGems, for hosted and agent
mode, or for a package already vendored by a path.

Tests:

- pypi::vendored_download_cache (real Bazel) now has the command write
  the files: they are the three of the hand-written flow, byte for byte;
  with the patch host stopped a new output base fails on one changed
  byte, which `vendor --check` names, and builds the patched marker
  from the copy as committed, from a sub-directory too; `vendor
  --revert` restores every file and the unpatched build.
  pypi::vendored_pip_parse keeps the refusal on real Bazel, in a
  checkout without Bazel's lock, and the switch's path line after it.
  The three `pypi::` flows pass on Bazel 9.3.2, 8.8.2 and 7.7.2 (macOS)
  at this commit; with the product code of the previous commit the two
  vendored ones fail on 9.3.2.
- Hermetic flows through the binary: the whole life of a cached wheel
  (in-sync runs, check, list, vex, a line changed since, the three
  undos, the hosted takeover and back, a commented-out line); a newer
  patch; a project below the Bazel root; a run that fails after its
  fetch over a committed wheel; and one checkout per condition of the
  gate, each declined with its reason, dry run included, with no wheel
  fetched.
- Unit tests of `bazel::distdir` (the lines, and each condition of
  `ready`) and of `vendor::pypi_distdir` (the line, the record, the
  shapes that are not written).

Docs: docs/ecosystems.md has the new section "Bazel workspaces: PyPI
vendored mode as a download cache"; in "Bazel workspaces: what is
supported" the vendored cell of PyPI is "Supported with rules_python
2.5.0", with its entry among the known problems. CLI_CONTRACT.md has
the two new codes and the changed rows. The `bazel` group of
scripts/loc-budget.json follows the code.

Not covered: a wheel with a platform tag, a second Python version in
the hub, `requirements_by_platform` (declined), rules_python releases
other than 2.5.0, Windows, and remote execution.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The branch this change is stacked on gained one commit: a hub that names a
requirements file which brings the project's own in with `-r` is declined,
and a doubt has the second file read as well.

Two conflicts. In bazel/built.rs both sides added a function after `reads`
(`alone` here, `includes_one` there): both are kept. The `bazel` line
budget is the count of the merged tree, 2851.

One thing follows for the download cache. A hub file that only brings the
project's requirements in with `-r` is none the run writes, and no build
through it is shown to take a committed wheel. So such a file does not
count as naming the project's file: the package is declined as on the
base, and the download cache is not asked about. The test of the include
holds that.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…hown to work

A review of the download cache found four cases in which vendored mode let
a package through, or wrote a line, that no build has been run for.

- A requirement that names the package by a URL of the user's own. The
  check before the download took every `name @ <url>` line for a pin that
  hosted mode made, so `get <purl> --mode vendored` fetched the wheel and
  failed only when it came to write the line. Only a URL that names a patch
  id is a hosted pin now; any other is declined before anything is fetched.
  (No scan finds a package in such a line, which is why it took `get`.)
- A second hub that reaches the file through `-r`. The check that the hub
  reads `requirements.txt` and no other file passed over a call that names
  none of the project's files, so `all.txt` with `-r requirements.txt` was
  judged only when its call came first. Every call of the hub is now asked
  whether its file brings one of the project's in.
- A source distribution or a wheel of one platform. The line was written
  for whatever the patch service serves. The form was built with a wheel
  for every platform (`-none-any.whl`) alone, so anything else now fails
  after its download, as the other refusal that only the download can show
  does, writes no line and keeps a wheel an earlier run committed.
- A project moved to a path with a blank. The lines of `.bazelrc` are kept
  for every ledger entry of the form on every command, without the check of
  the path that the first write makes: a blank in the line would be a second
  word on every Bazel command of the workspace. Such a project gets no line.

The read-only asks of the ledger use the shared parse, which is keyed on the
ledger's bytes. The `bazel` line budget is 2865.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 24, 2026 02:34
@cursor

cursor Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches vendored PyPI wiring, Bazel workspace detection, and .bazelrc mutation in builds that use rules_python; mis-gating or rc sync failures could block patches or leave builds fetching from the patch host.

Overview
Adds a Bazel download-cache vendoring path for PyPI when rules_python pip.parse reads the project’s requirements.txt, instead of only refusing (vendor_pypi_bazel_hub) or requiring --allow-vendored-in-bazel for a local wheel path.

Where the workspace gate passes, vendored mode now writes: a hosted-style requirements.txt pin (name @ patch URL + --hash), the wheel under .socket/vendor/pypi/<uuid>/, and common --distdir=… lines in root .bazelrc (via new bazel/distdir + vendor/pypi_distdir). Post-command sync keeps .bazelrc in step with committed wheels, parallel to Go’s .bazelignore. bazel/built::alone and stricter hub refusals encode when this form is allowed vs when decline messages include why.

CLI/contract: new advisory vendor_pypi_bazel_download_cache and bazelrc_not_updated; vex treats download-cache pins like hosted for “affected” semantics; discovery claims ledger-backed URL lines as vendored. Tests/docs/CI: expanded Bazel e2e (vendored_download_cache, gate matrix), workflow path for pypi_distdir.rs, loc budget bump for bazel/.

Reviewed by Cursor Bugbot for commit c6aa228. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c6aa228. Configure here.

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 24, 2026
`bazel::distdir::sync` reports the file it changed as a person reads a
path, without the `\\?\` prefix that a canonical path carries on Windows,
as the `.bazelignore` writer does. One unit test compared that report
with the root's own path joined with the file name, which keeps the
prefix, so it failed on Windows and nowhere else:

    left: Some("C:\\...\\.bazelrc")
   right: Some("\\\\?\\C:\\...\\.bazelrc")

The test now takes the prefix off its expectation with the same helper.
Tests only.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The writability probe in the PyPI download cache's `ready` opened
`.bazelrc` for appending with a plain open(2). A FIFO at that path
blocks that open until a reader comes, so `vendor` and `scan --mode
vendored` could hang instead of declining the package. A directory
there passed the probe and only failed later in the line editor.

Decline any `.bazelrc` that exists and is not a regular file, and open
the probe with O_NONBLOCK on Unix so a FIFO swapped in after the check
fails fast with ENXIO. The test covers a FIFO and a directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeSL5vqqQC2MRoR5khg
Assisted-by: Claude Code:claude-opus-5-5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Found a fresh-checkout gap in the vendored wheel gate.

The wheel of a download cache already has a git-ignored guard, but the
.bazelrc line that points Bazel at it did not. An untracked .bazelrc that
git ignores passes the gate, the local build takes the wheel, and a fresh
checkout has no --distdir line, so it downloads from the patch host. The
gate now asks git (without --no-index, so a tracked file passes) and
declines with the ignoring rule.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. Where a rules_python pip.parse hub reads the project's requirements.txt, vendored mode no longer just declines: it writes hosted mode's URL pin, commits the patched wheel under .socket/vendor/pypi/<uuid>/, and adds a common --distdir= line to the root .bazelrc so Bazel takes the committed copy. It only does this where the checkout shows it works (rules_python 2.5.0, Bazel 7 to 9, hashed single pin, no downloader config, a .bazelrc that is writable and, since 3a8f1bd, not git-ignored). Everywhere else it declines as #2208 does.

Risk: medium. It is the first time socket-patch writes .bazelrc, and it changes what lockfile discovery reports for this one line shape. The gate is narrow and the 80-sequence side-by-side in the description shows no change outside it, but the .bazelrc edit reaches every Bazel command in the user's repo.

Look here

Verified. I read the diff against the base branch (bazel-guard/vendored-hub-locks), focusing on the two new modules and the last commit. CHANGELOG.md is untouched. git check-ignore runs without --no-index, so a tracked .bazelrc passes, and its unit test covers ignored, untracked and tracked. I ran cargo test -p socket-patch-core --lib -- bazel:: vendor::pypi locally: 682 passed. CI on 3a8f1bd: ci-ok and clippy are green, with no failing check. All review threads are resolved. Approved by Wenxin-Jiang at b9141ea; that approval still stands.

Changes I made. None.

Open questions


Generated by Claude Code

…ndored/pypi-download-cache

This brings main in, through the two merges of the declines' branch. Six
files conflicted. bazel/ignore.rs keeps main's pairs for the crates a hub
builds and its `sync(project, go, cargo)`, and this branch's split of the
edit from the file it is made in (`Kept`, `update`), which
bazel/distdir.rs uses for `.bazelrc`: `edited` takes main's entries and no
`add`, `Kept::comment` makes the comment line from what an entry is about,
and `update` hands back what the file held and holds, so that `sync` still
says whose lines changed. `sync_bazelignore` of the CLI syncs both files
and tells a person of each as its side did. bazel/mod.rs lists the modules
of both sides, and CLI_CONTRACT.md and docs/ecosystems.md keep the rows of
both. The `bazel` cap of scripts/loc-budget.json is the count of the
merged tree, 4120.

Outside the conflicts, the `DepOverride` that vendor/pypi_distdir.rs builds
names the `npm_registry_url` main added to that type.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…gnore line

`cargo::vendored_from_cargo_with_config` comments out the line the scan
wrote in `.bazelignore` and expects `bazel cquery //...` and
`bazel query 'deps(//...)'` to fail on a repository that the main
repository does not see. It looked for the hub's repository
(`@crates__...`) alone. The build file that cargo-bazel writes into the
committed copy names `@platforms` as well, and Bazel reports the first one
it meets: on a Linux runner with Bazel 9.3.2 the query named `@platforms`
and the flow failed on its own check.

The flow now takes either name for that failure. Test only: nothing the
command does changes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The check of the commands that fail once the ignore line is commented out
now reads the name out of Bazel's message and takes it only when the
message is about the main repository's view: `platforms`, or a repository
of the crate hub. The same words about another repository's view, or
about another name, are a different failure and no longer pass for the
expected one. A test without Bazel holds the check to the two messages
that were seen and to three it must not take.

The module docs, the comment at the call and the section on the build
file in a vendored crate said the commands end on the dependency's
repository alone. They now name `platforms` as well, which is what a
user who comments the line out can see.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ndored/pypi-download-cache

This brings main in, through the merge of the declines' branch. Six files
conflicted.

bazel/ignore.rs keeps main's fourth kind of copy, the Maven jars of a hub,
in this branch's shape: the pairs of `.bazelignore` are still edited
through `Kept` and `update`, as the `.bazelrc` lines of bazel/distdir.rs
are. `sync_bazelignore` of the CLI syncs `.bazelignore` for Go, Cargo and
Maven and `.bazelrc` for PyPI, and tells a person of each file as before.
bazel/maven.rs keeps this branch's `known_release`, and after a known
release main's rule that no option about downloads stands against a
vendored entry.

The test harness has one of each helper that both sides wrote: main's
`StandIn::start`, whose listener is now the stand-in's own (this branch's
`alone` is gone, and its one caller uses `start`), main's `stop` and
main's `Cell::cached`. This branch's `bazel_below` stays.

CLI_CONTRACT.md keeps this branch's two rows and main's `.bazelignore`
row. The `bazel` cap of scripts/loc-budget.json is the count of the
merged tree, 4304.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: updated review brief (new commits since 3a8f1bd)

What changed. Since the last brief, the head moved from 3a8f1bd to 362885e. That's two merges from the base branch (bazel-guard/vendored-hub-locks) plus two non-merge commits, ae085da and 21f3b69. Those two commits make the same change as #2227 (same git patch-id as #2227's e990ab1 and 17352ac, which have their own brief). They are test-only. The vendored Cargo real-Bazel flow now accepts @platforms as well as the crate hub's repository as the unseen repository named in Bazel's error. docs/ecosystems.md says so too. The command's behavior is unchanged.

Risk: medium, unchanged from the earlier brief. The new commits add no risk to user installs.

Verified. I compared the two commits' patch-ids against #2227 and they match. CI on 362885e: ci-ok and clippy are green and no check failed. Both review threads are resolved. Wenxin-Jiang's approval still stands.

Changes I made. None.

Open questions. None new. Auto-merge is still off on purpose because this PR is stacked on #2208 (agent:needs-human). Once #2208 lands, retarget this PR to main.


Generated by Claude Code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Re-reviewed the commits since the last approval; no major findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants