Repository navigation
feat(pnpr): resolve Python projects through the install accelerator - #14613
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughChangesPython resolution through pnpr
Estimated code review effort: 5 (Critical) | ~120 minutes Merge Risk: ⚪ Minimal · up to Python dependency resolution can now use pnpr while retaining local fallback and client-side wheel verification. No concrete merge-blocking risk remains in the supplied evidence. Sequence Diagram(s)sequenceDiagram
participant pnpm
participant PnprClient
participant pnpr
participant PyPIIndex
participant PythonResolver
pnpm->>PnprClient: check PyPI capability
PnprClient->>pnpr: POST Python resolve request
pnpr->>PyPIIndex: fetch project pages and metadata
PyPIIndex-->>pnpr: return candidates and metadata
pnpr->>PythonResolver: resolve Python requirements
PythonResolver-->>pnpr: return lockfile
pnpr-->>PnprClient: return terminal lockfile frame
PnprClient-->>pnpm: return validated lockfile
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoResolve Python dependencies through pnpr
AI Description
Diagram
High-Level Assessment
Files changed (37)
|
Confidence Score: 5/5The PR appears safe to merge; the latest change closes the remaining stale-cache case without introducing a new actionable issue. All previous findings are resolved, dismissed with a correct concession, or manually resolved, and the changes since the previous review correctly bind fallback metadata to the required SHA-256 wheel digest. Reviews (7): Last reviewed commit: "docs(pnpr): say what the Python resolver..." | Re-trigger Greptile |
Code Review by Qodo
1.
|
PR Code Suggestions ✨Latest suggestions up to 221a53e Warning
Previous suggestions✅ Suggestions up to commit ee1f583
Suggestions up to commit 3013392
✅ Suggestions up to commit 4833b6d
✅ Suggestions up to commit 4b5c674
✅ Suggestions up to commit e94bc5c
✅ Suggestions up to commit 4933980
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Code review by qodo was updated up to the latest commit e94bc5c |
|
Code review by qodo was updated up to the latest commit 4b5c674 |
Resolution lived inside the CLI, where it could only run beside an interpreter: the pubgrub provider read a `Registry` that downloads wheels and asks `host.py` what they require. A registry server resolving on a client's behalf can do neither, so the rules move to `pnpm-python-resolver` and the fetching stays with whoever can do it. The crate owns what resolution decides: which wheel of a version a target installs, how a requirement's markers and extras constrain a solution, what a wheel's `METADATA` says, and what the resulting `pylock.toml` records. `step` runs one pubgrub pass and either solves the project or names the one distribution or wheel it still needs, which is the shape the CLI's loop already had — the provider raised the same two requests as errors for the caller to satisfy. The CLI keeps everything that needs the interpreter: probing it, reading a downloaded wheel through `host.py`, ingesting wheels into the store, and building the environment. Its `Registry` now records each wheel twice over: the interpreter's full report for installing it, and the subset resolution reads. Related to #14599. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0144Yvv9aAbx93cWtenkzVwG
|
Code review by qodo was updated up to the latest commit 4833b6d |
`POST /-/pnpr/v0/resolve` now reads `"ecosystem": "pypi"` beside npm and Cargo. The body carries the project's requirements and the interpreter they are for; the answer is the `pylock.toml` document the client writes. Python is where a server-side resolve earns the most. Resolving a requirement reads a distribution's `METADATA`, which lives inside a wheel, so a client resolving alone downloads whole wheels for versions it then rejects. pnpr reads the metadata file an index publishes beside each wheel (PEP 658, either spelling of the field), falls back to the wheel itself only for an index that publishes none, and keeps what it read for every client that follows. No interpreter runs on the server: the marker environment and the wheel tags travel in the request as the client's own, and wheels are matched against them by the shared resolver crate. Reads are bounded and scoped as the Cargo path's are — the index origin must be on the route allowlist, each read is classified by the project it is for so an upstream's per-project rules decide the credential and the cache namespace, a cold read is fetched once across concurrent resolves, and per-resolve caps bound the distributions, the metadata reads, each response, and the bytes one request holds. The route hook that binds a package name into a fetch is shared with the Cargo path now, and names what it carries: the ecosystem's canonical spelling of a package's name, never a version of one. Related to #14599. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0144Yvv9aAbx93cWtenkzVwG
`pnpm install` sends a Python project's requirements and its interpreter to the server configured in `pnprServer`, and writes the `pylock.toml` that comes back. What it saves is the download resolution otherwise needs: reading what a distribution requires means reading a wheel's `METADATA`, so a client resolving alone downloads whole wheels for versions it then rejects. The answer is checked, not taken. The lockfile has to record the inputs this install asked about, the wheels it names are downloaded and checked against the digests the index published, and the project is re-solved against the metadata of what actually arrived — the path a lockfile written by an earlier install already takes. A server that answers with someone else's project, or with a package the requirements do not reach, fails the install rather than installing anything. Asking a server which ecosystems it resolves is now one memo for both Cargo and Python, keyed by server and ecosystem, so a workspace with roots of both kinds asks once for each rather than once per root. Related to #14599. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0144Yvv9aAbx93cWtenkzVwG
Resolution decides which versions a client installs, so a metadata document that is not the one the index vouched for must not reach the solver. A metadata file published with digests is checked against them, and a wheel read for its metadata is checked against the digest the project page carries. An index that publishes no SHA-256 for a file leaves nothing to check here. The client checks every wheel it downloads regardless, so this is the server declining to resolve against bytes it can already tell are wrong, not the only thing standing between a project and a bad wheel. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0144Yvv9aAbx93cWtenkzVwG
The README's accelerator section named npm and Cargo. It now says what Python resolution saves a client, which is the reason to point a Python project at a pnpr server at all. Also settles two style rules on the new tests: a derive list in the resolver crate's declared order, and the trailing commas the macro rule asks for. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0144Yvv9aAbx93cWtenkzVwG
Review fixes for the Python resolve path. A document was cached as soon as it arrived, so a project page that is not one, or metadata that describes another distribution, was served to every resolve that followed for the whole TTL. Both are now parsed and checked first and cached only if they hold up. What is kept for a wheel is the metadata document rather than the wheel, so an index that publishes no metadata file costs one download per version ever, not one per resolve. Metadata is checked against the candidate it was read for: a document naming another distribution or version is refused, as the client's own read of the downloaded wheel already refuses it. A wheel's `METADATA` read past the size cap was cut short rather than refused, and a document cut short still names its distribution — the requirements after the cut would simply not exist. It is refused now. An index URL's query survives every read. An index that carries a token there was losing it when a project page was addressed, and the metadata file beside a wheel was addressed by appending to the whole URL rather than to its path. A request's requirements and wheel tags are capped: every tag is compared against every wheel filename, so an unbounded list is work a caller hands the server. The wheel-read cap drops to 64 MiB, well above an ordinary wheel. Client-side, a returned lockfile has to agree with the project's own `requires-python` as well as its inputs, or the next install would consider what was just written stale. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0144Yvv9aAbx93cWtenkzVwG
Two assertions in the Python resolver's unit tests wrapped onto several lines when they were reformatted, which the macro rule wants a trailing comma for. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0144Yvv9aAbx93cWtenkzVwG
A cache entry held its document as bytes, which JSON writes as an array of decimal numbers: several times the document on disk and in memory for every read. Both cached documents — a Simple API page and a `METADATA` file — are text, and are stored as text now. A wheel is not cached at all; what a wheel is read for is the metadata document inside it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0144Yvv9aAbx93cWtenkzVwG
A cached metadata document was answered without asking what the index says about it now. The digests come from the project page a resolve just read, and a page entry can expire while the metadata entry outlives it — the metadata is written when some resolve first needs that version, not when the page was read — so a file republished under the same URL could be answered from what was cached for the old one. A cache hit is checked against the digests in hand. Client-side, the check that a server answered this install's question is its own function now, with the test to match: the previous one asserted a property of its fixture rather than the behaviour. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0144Yvv9aAbx93cWtenkzVwG
The doc enumerated what the check compares, which the function's parameters already say. What is left is why the check exists: a lockfile that answers another question would be written, read back as stale by the next install, and fail a frozen one outright. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0144Yvv9aAbx93cWtenkzVwG
4833b6d to
3013392
Compare
…in for `server_lockfile` says what the doc comment above it said, so the comment goes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0144Yvv9aAbx93cWtenkzVwG
|
Code review by qodo was updated up to the latest commit 3013392 |
|
Code review by qodo was updated up to the latest commit ee1f583 |
Summary
/-/pnpr/v0/resolvenow reads"ecosystem": "pypi"beside npm and Cargo, so apnpm installwithpnprServerset resolves its Python dependencies server-side. This is the second half of the accelerator item in #14599; the Cargo half landed in #14607.Python is where a server-side resolve earns the most. Reading what a distribution requires means reading a wheel's
METADATA, which lives inside the wheel, so a client resolving alone downloads whole wheels for versions it then rejects. pnpr reads the metadata file the index publishes beside each wheel (PEP 658, either field spelling), falls back to the wheel itself only for an index that publishes none, and keeps what it read for every client that follows.The resolver moved out of the CLI. It lived in
pnpm/crates/cli/src/python/, where it could only run beside an interpreter: the pubgrub provider read a registry that downloads wheels and asks the bundledhost.pywhat they require. A registry server can do neither.pnpm-python-resolvernow owns what resolution decides — which wheel of a version a target installs, how a requirement's markers and extras constrain a solution, what a wheel'sMETADATAsays, whatpylock.tomlrecords — and every fetch stays with whoever can do it.stepruns one pubgrub pass and either solves the project or names the one distribution or wheel it still needs, which is the shape the CLI's loop already had. The CLI keeps everything interpreter-shaped: probing it, reading a downloaded wheel throughhost.py, ingesting wheels into the store, building the environment.No interpreter runs on the server. The marker environment and the wheel tags travel in the request as the client's own, and pnpr matches wheels against them without running any Python. The lockfile records both, as it already did, so it is only ever reused for the interpreter it was resolved for.
The client verifies rather than trusts. A returned lockfile has to record the inputs this install asked about; its wheels are downloaded and checked against the digests the index published; and the project is re-solved against the metadata of the wheels that actually arrived. That is the same path an existing
pylock.tomlalready takes, so a server answering with someone else's project, or with a package the requirements do not reach, fails the install rather than installing anything. Server-side, a metadata file or wheel that does not match the digest the index published is refused before it reaches the solver.Boundaries match the Cargo path. The index origin must be on the route allowlist; every read is classified by the project it is for, so an upstream's per-project rules decide the credential and the cache namespace; a cold read is fetched once across concurrent resolves; and per-resolve caps bound the distributions, the metadata reads, each response, and the bytes one request holds. A server that does not advertise
pypileaves the client resolving locally, and--offlineskips the server entirely.Not in this PR. The lockfile that comes back names the index's own wheel URLs rather than URLs routed through pnpr, so a private index still has to be reachable by the client with its own credentials — the same shape the Cargo path has, and worth solving for both at once. Nothing here changes how a Python environment is built: the client downloads and installs exactly as before.
Squash Commit Body
Checklist
already linked to it solves it.
are implemented in every affected version.
pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Written by an agent (Claude Code, claude-opus-5).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
New Features
Documentation