fix(py): rebuild the bindings when their version or Rust changes - #1481
Merged
Merged
Conversation
`make worktree-setup` runs `uv sync`, and on a clean `main` it replaced a current 2.2.1 install of the bindings with a cached 2.1.1 build. The version is dynamic: maturin reads it from the crate's `Cargo.toml`, which inherits it from the workspace root. The extension also compiles the root and ast crates, one directory up. uv's default cache key watches only `pyproject.toml` and `setup.*`, so neither a version bump nor a Rust change ever invalidated the cached build. `[tool.uv].cache-keys` now lists what the build actually reads: the manifests, the lockfile and the Rust sources, following the template uv itself generates for a maturin project but pointed at this workspace member's parent directory. Setting the key replaces the default, so `pyproject.toml` is listed again. Verified on this checkout: - on `main`, `uv sync` downgraded 2.2.1 to 2.1.1; with the fix it rebuilds to 2.2.1 - a second sync with nothing changed is a no-op, so the keys do not force a rebuild on every run - touching `../src/lib.rs` or `../big-code-analysis-ast/src/lib.rs` rebuilds (`Built big-code-analysis`, extension mtime advances), so the parent-directory paths are honoured - with the fix stashed, the same touch does not rebuild, so the keys are what cause it `uv lock --check` is unaffected. `make pre-commit` never saw the stale build, because `py-test` runs `maturin develop` before testing. Also corrects the comment beside `dynamic = ["version"]`, which pointed at a `[tool.maturin].version` key that does not exist.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
make worktree-setuprunsuv sync, and on a cleanmainit replaced acurrent 2.2.1 install of the Python bindings with a cached 2.1.1 build.
Cause
The bindings' version is dynamic: maturin reads it from the crate's
Cargo.toml, which inherits it from the workspace root(
version.workspace = true). The extension also compiles the root and astcrates, one directory up. uv's default cache key watches only
pyproject.toml/setup.*inside the project directory, so neither aversion bump nor a Rust change ever invalidated its cached build.
Fix
[tool.uv].cache-keysinbig-code-analysis-py/pyproject.tomlnow listswhat the build actually reads: the manifests, the root
Cargo.lock, andthe Rust sources. It follows the template
uv init --build-backend maturingenerates, pointed at this workspace member's parent directory. Setting the
key replaces uv's default, so
pyproject.tomlis listed again.The comment beside
dynamic = ["version"]pointed at a[tool.maturin].versionkey that doesn't exist; it now says where theversion really comes from.
Verified
uv synconmain(reproduction)uv syncwith the fix../src/lib.rsBuilt big-code-analysis, extension mtime advanced)../big-code-analysis-ast/src/lib.rsuv lock --check--lockedstill holdsmake pre-commitBCA_GATE: passImpact
Contributor environment only; nothing shipped changes. The effect was
smaller than "stale code": the compiled extension that happened to be in
the source tree was current, and only the installed package metadata
reported 2.1.1.
make pre-commitand CI were never affected, becausepy-testrebuilds withmaturin developbefore testing. But a venv syncedby
worktree-setupcould not be trusted to match the tree, and a Rust-onlychange would never have been rebuilt by uv at all.
Not covered: the vendored
tree-sitter-*grammar crates. A grammarregeneration changes C sources those crates compile, which these keys do
not watch;
uv sync --reinstall-package big-code-analysisrebuilds whenthat matters.