canibuild
Find the dependencies in your lockfile that will fail to build from source, before you
run pip install, uv sync or poetry install. For each one, canibuild tells you why
and gives you the one-line fix for your tool.
setuptools 82 removed pkg_resources. Every sdist whose setup.py still imports it now
fails in a fresh isolated build with ModuleNotFoundError: No module named 'pkg_resources',
and pinning setuptools in your own environment doesn't help, because the build gets its
own, newest setuptools. canibuild reads your lockfile, works out which packages have no
wheel for your Python and platform, opens their sdists without running them, and reports
what will break.
$ pip install canibuild
$ canibuild uv.lock
Example
This is the uv.lock of a public project (geosp/mcp-bible
at 904dc66), whose uv sync broke on flatdict 4.0.1:
$ canibuild check uv.lock --python 3.12 --platform linux-x86_64
canibuild: uv.lock for CPython 3.12 on linux-x86_64
81 packages checked, 1 builds from source, 1 will fail, 0 may fail
SEVERITY PACKAGE VERSION RULE PROBLEM
ERROR flatdict 4.0.1 pkg-resources setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1
flatdict 4.0.1: setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1
at setup.py:1: import pkg_resources
fix (any): Upgrade flatdict to 4.1.0, the first newer release with a wheel for this target
uv lock --upgrade-package 'flatdict>=4.1.0'
fix (uv): Constrain setuptools in flatdict's build (pyproject.toml)
[tool.uv.extra-build-dependencies]
flatdict = ["setuptools<82"]
fix (uv): Or constrain it for every build (pyproject.toml)
[tool.uv]
build-constraint-dependencies = ["setuptools<82"]
Not checked: 1 (mcp-weather: git source, not checked)
The run took under a second with a warm cache. It exits with status 1, so it can gate CI.
For a requirements.txt that pins openai-whisper==20231117, which has no wheels at all:
$ canibuild requirements.txt --python 3.12 --platform linux-x86_64
...
openai-whisper 20231117: setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1
at setup.py:5: import pkg_resources
fix (any): Upgrade openai-whisper to 20250625, the first newer release whose sdist has none of these problems
openai-whisper>=20250625 # in requirements
fix (uv pip): Pass a build constraints file
echo 'setuptools<82' > build-constraints.txt
uv pip install -b build-constraints.txt -r requirements.txt
fix (pip): Pass a build constraints file (pip 25.3+)
echo 'setuptools<82' > build-constraints.txt
pip install --build-constraint build-constraints.txt -r requirements.txt
fix (pip): pip older than 25.3: use PIP_CONSTRAINT (ignored for builds since pip 26.2)
echo 'setuptools<82' > build-constraints.txt
PIP_CONSTRAINT=build-constraints.txt pip install -r requirements.txt
Builds from source with no known problem: deepspeed 0.20.2 (compiles native code), langid 1.1.6, textgrid 1.6.1
What it checks
canibuild only looks at packages that will be built from source: those with no wheel
matching the target interpreter and platform. For each of them it downloads the sdist
(cached), reads pyproject.toml, setup.py, setup.cfg and the local modules setup.py
imports, and parses them with ast. It never runs code from a package.
| Rule | Fails when |
|---|---|
pkg-resources |
setup.py (or a local module it imports) imports pkg_resources and the build would get setuptools 82 or newer |
build-tool-needs-pkg-resources |
setup_requires or build-system.requires pins setuptools-scm older than 6.3 or pbr older than 7.0, which import pkg_resources themselves |
setuptools-easy-install, setuptools-test-command, setuptools-dep-util, setuptools-use-2to3 |
setup.py uses a setuptools API that was removed (in 80.3, 72, 70 and 58) and the build gets a newer setuptools |
numpy-distutils |
setup.py imports numpy.distutils, which doesn't exist on Python 3.12+ or with NumPy 2 |
distutils |
setup.py imports distutils on Python 3.12+ and setuptools isn't in the build |
missing-build-requires |
setup.py imports a module at top level (such as torch or numpy) that the sdist doesn't declare in build-system.requires, so the isolated build can't import it |
no-installable-file |
there is no wheel for the target and no sdist |
An import inside a try: ... except ImportError is ignored. An import inside a function
is reported as a warning, since it fails only if that code runs during the build.
Packages that build from source with no known problem are listed as such, with a note
when they compile native code.
The setuptools version a build would get is worked out from the sdist's own
build-system.requires (or pip's and uv's default of setuptools>=40.8.0 when it has
none) and the setuptools releases on PyPI, so a package that already caps
setuptools<82 isn't flagged.
Fixes
Every finding comes with fixes for the tool that matches your lockfile (uv.lock gets
uv, pylock.toml and requirements files get pip and uv pip). Pass --tool to choose
(uv, uv-pip, pip, poetry or all).
| Tool | Fix for a build that needs setuptools<82 |
|---|---|
| uv | [tool.uv.extra-build-dependencies] pkg = ["setuptools<82"], or [tool.uv] build-constraint-dependencies = ["setuptools<82"] |
| uv pip | uv pip install -b build-constraints.txt ... |
| pip 25.3+ | pip install --build-constraint build-constraints.txt ... (or PIP_BUILD_CONSTRAINT) |
| pip older than 25.3 | PIP_CONSTRAINT=build-constraints.txt pip install ... (pip 26.2 stopped applying this to builds) |
| Poetry 2.3+ | [tool.poetry.build-constraints] pkg = { setuptools = "<82" }, then poetry lock |
Each of these was checked against flatdict==4.0.1 with uv 0.13, pip 26.3 and 25.1, and
Poetry 2.5: the install fails without the fix and succeeds with it. When a newer release
of the package has a wheel for your target, or an sdist without the problem, canibuild
suggests upgrading to the oldest such release first.
Note that uv's own hint for this error suggests adding pkg_resources to
extra-build-dependencies. That can't work: pkg_resources isn't a package on PyPI.
Confirming a prediction with a real build
The checks above are static. --verify goes one step further: for every package with an
error or warning, it builds that sdist in a throwaway environment with uv
(uv pip install --no-deps --no-binary PKG, from PyPI only, isolated from your uv config),
and records whether the build really fails the way canibuild said. When the finding has a
build constraint such as setuptools<82, it builds once more with that constraint to show
whether the fix works.
$ canibuild examples/broken/requirements.txt --python 3.12 --verify --tool uv-pip
canibuild: building flatdict 4.0.1 to verify...
canibuild: examples/broken/requirements.txt for CPython 3.12 on linux-x86_64
2 packages checked, 1 builds from source, 1 will fail, 0 may fail, 1 confirmed by a real build
SEVERITY PACKAGE VERSION RULE PROBLEM
ERROR flatdict 4.0.1 pkg-resources setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1
flatdict 4.0.1: setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1
at setup.py:1: import pkg_resources
verified: confirmed (ModuleNotFoundError: No module named 'pkg_resources')
with setuptools<82 in the build: builds
fix (any): Upgrade flatdict to 4.1.0, the first newer release with a wheel for this target
flatdict>=4.1.0 # in requirements
fix (uv pip): Pass a build constraints file
echo 'setuptools<82' > build-constraints.txt
uv pip install -b build-constraints.txt -r requirements.txt
Each finding gets one of these results:
| Result | Meaning |
|---|---|
confirmed |
The build failed with the error the finding predicts. |
fails-differently |
The build failed, but not with that error. The last error line is shown. |
refuted |
The build succeeded. The finding no longer counts toward --fail-on. |
timeout |
No result within --verify-timeout seconds (default 900). |
skipped |
uv isn't installed, the target platform isn't this machine, or uv couldn't create an environment for the target Python. |
Builds run one at a time, so --verify takes as long as the flagged builds do; large
native packages can take minutes. uv may download the target Python if it isn't installed.
Missing-file and not-checked findings are not built.
Tested on real lockfiles
canibuild was run on 13 lockfiles from public repositories (5 uv.lock, 8 requirements
files). Then every sdist those lockfiles would build was actually built, in a fresh
environment with uv pip install --no-deps, to see which builds really fail.
- 26 packages would build from source (23 distinct package versions).
- 10 of them really fail:
flatdict4.0.1 (2 lockfiles),openai-whisper20231117 (2) and 20240930 (2),salib1.3.12 andmmcv2.2.0 importpkg_resources;flash-attn2.8.3.post2 importstorchwithout declaring it;faiss-cpu1.7.4 has no wheel for Python 3.12 and no sdist. - canibuild reported all 10 with the right cause, and none of the 16 that built fine.
- With the suggested
setuptools<82build constraint, all five distinctpkg_resourcesfailures build.jproperties2.1.2 built from source (itssetup_requirespins setuptools-scm 3.x) is caught bybuild-tool-needs-pkg-resources, fails for real, and builds with the same constraint.
Running the same lockfiles with --verify confirmed all 9 build failures it could build
(faiss-cpu has nothing to build), and the setuptools<82 constraint made all 8
pkg_resources cases build.
The lockfiles, their commits and the per-package results are in
docs/validation.md.
Usage
canibuild [check] LOCKFILE... [--python X.Y] [--platform P] [--format text|json]
[--fail-on error|warning|never] [--tool TOOL] [--jobs N]
[--verify] [--verify-timeout SECONDS] [--json-report PATH]
[--cache-dir DIR] [--no-cache] [-v]
LOCKFILE: one or more ofuv.lock,pylock.toml(orpylock.NAME.toml), or a requirements file. Requirements files may include other files with-r. Unpinned requirements are checked at the newest release that matches and supports the target Python.--python: the target Python, such as3.12. Defaults to the running interpreter, or to the oldest version auv.lockorpylock.tomlallows when the running one is outside itsrequires-python.--platform:linux-x86_64,linux-aarch64,musllinux-x86_64,musllinux-aarch64,macos-arm64,macos-x86_64,windows-amd64,windows-arm64,windows-x86, or a raw platform tag such asmanylinux_2_28_x86_64. Defaults to the current machine.--format json: machine-readable output with every finding and fix (a list when you pass several lockfiles).--json-report PATH: also write the JSON report, always as a list, while printing text.--verify,--verify-timeout: build flagged sdists to confirm the findings (see above).--fail-on: exit with 1 on errors (the default), on warnings too, or never. With several lockfiles, the run fails if any of them does. Usage errors and unreadable lockfiles exit with 2.
Downloaded sdists are cached in the user cache directory (~/.cache/canibuild on Linux,
or $CANIBUILD_CACHE_DIR).
GitHub Action
- uses: actions/checkout@v4
- uses: driftwright/canibuild@v0.2.0
with:
lockfiles: uv.lock # default: every uv.lock, pylock*.toml, requirements*.txt
python: "3.12" # default: as for --python below
# platform: linux-x86_64 # default: the runner
# fail-on: error # error, warning or never
# tool: uv # tools to show fixes for
# verify: "true" # build flagged sdists to confirm the findings
The action installs uv, runs canibuild with the code of the tag you pinned (or the PyPI
release given in version), prints the report, adds it to the job summary, and fails the
step when something will fail to build. The JSON report's path is in the report output.
Check several targets with a matrix over python and platform; verify only builds
when platform is the runner's own.
pre-commit
repos:
- repo: https://github.com/driftwright/canibuild
rev: v0.2.0
hooks:
- id: canibuild
# args: [--python, "3.12"]
The hook runs when uv.lock, a pylock*.toml or a requirements*.txt changes, and needs
network access to PyPI.
Limits
- Only packages from PyPI are checked. Git, path and URL dependencies, and versions from
other indexes (such as
torch==2.1.2+cu121), are listed as not checked. - The checks are static. A
setup.pythat fails for a reason not in the table above, or that needs a compiler or system library you don't have, isn't caught. - Requirements files are not resolved: only the packages they list are checked, not their
dependencies. Use a lockfile (
uv.lock,pylock.toml, orpip-compileoutput) for the full tree.
License
MIT
Metadata
Release files for canibuild 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| canibuild-0.2.0.tar.gz | 71.8 kB | Without provenance | Details for canibuild-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| canibuild-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for canibuild-0.2.0-py3-none-any.whl |
Total release size: 112.4 kB
Release files / canibuild-0.2.0.tar.gz
| Download URL | canibuild-0.2.0.tar.gz |
|---|---|
| Size | 71.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27a447f7e1d7f90a7688f3fcfce48da6689e5141f75919bc525f85bf5899fb04
|
|
BLAKE2b-256 checksum How to use checksums |
a702b1f7a99822be9b472f777fb9f4086eb1521528af57e017135ff968041112
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / canibuild-0.2.0-py3-none-any.whl
| Download URL | canibuild-0.2.0-py3-none-any.whl |
|---|---|
| Size | 40.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c49d7fe910ae470c3e8048c18d9e515ad1a3a9facc07dbd26abdfad48eb5d9d1
|
|
BLAKE2b-256 checksum How to use checksums |
d498e0e4c5d300d313e564b4a4c75aa4a2a34b225b0d1cc2c68deeb12afda473
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for canibuild 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.