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 |
c-api-removed |
Python 3.15+: a C or C++ source calls a function that Python 3.15 removed, such as PyWeakref_GetObject or Py_GetPrefix, outside any version check |
free-threading-limited-api |
free-threaded 3.13t or 3.14t: the build enables the limited C API (py_limited_api in setup.cfg or setup.py, or Py_LIMITED_API defined in a source file or define_macros), which these builds reject |
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. When such a package has compiled wheels, just none for
the target (say, wheels up to cp313 but not cp315 or cp314t), it is reported as a
no-wheel-for-python warning, since the build is probably unexpected and needs a
compiler; the fix names the first newer release with a matching wheel.
New Python versions and free-threaded builds
Pass --python 3.15 to check a new Python before its wheels are out, and
--python 3.14t (or cp314t) for the free-threaded build. Wheel matching follows the
interpreter: abi3 wheels don't install on free-threaded 3.13t and 3.14t, and on 3.15t
only abi3t wheels (PEP 803) do.
Two checks read the C sources of packages that would be built:
c-api-removedlooks for calls to the functions listed under "Removed C APIs" in What's New in Python 3.15. With GCC 14+ or Clang 16+ the build fails with an implicit declaration error; older compilers build a module that fails on import. Calls are skipped when they sit inside an#ifonPY_VERSION_HEX,PY_MINOR_VERSION,Py_LIMITED_API,PYPY_VERSIONor a Cython switch (or a macro defined from one of those), when the package defines the name itself (a compat header), and undertests/,docs/andexamples/. Comments and strings are ignored.free-threading-limited-apiflags builds that turn on the limited API for 3.13t or 3.14t. CPython 3.13 and 3.14 stop the compile with#error "The limited API is not currently supported in the free-threaded build", and setuptools refusespy_limited_apithere. Settings behind aPy_GIL_DISABLEDcheck are not reported.
For example, pygame==2.6.1 on 3.15 (it calls PyWeakref_GetObject in
src_c/surface.c) and pycryptodome==3.19.0 on 3.14t (py-limited-api = cp35 in
setup.cfg); --verify confirms both.
Git, path and URL dependencies
Dependencies that installers fetch directly are always built from source, so canibuild checks them with the same rules:
- git (
source = { git = ... }inuv.lock,vcsinpylock.toml,name @ git+https://...@revor-e git+...in requirements): fetched withgit fetch --depth 1at the locked commit (or the branch or tag the requirement names), with hooks disabled and no submodules, then read like an sdist. Checkouts of a pinned commit are cached. When the requirement names a branch or tag, or nothing, the report says which commit was checked. - path (
directory,pathand non-rooteditablesources,./dir,file:URLs): the local directory or archive is read in place, relative to the lockfile. - URL (
source = { url = ... },archiveinpylock.toml,name @ https://...): sdists are downloaded and read; a wheel URL is only checked against the target's tags.
Findings for these show where the code came from, and --verify builds them from the same
reference (name @ git+URL@commit), so a git build needs access to that git host.
Forcing or forbidding source builds
Some projects build certain packages from source on purpose, or forbid source builds entirely. canibuild reads those settings and checks accordingly:
| Setting | Where canibuild reads it | Effect |
|---|---|---|
| no-binary | [tool.uv] no-binary = true / no-binary-package = [...] (pyproject.toml or uv.toml next to uv.lock); [tool.uv.pip] no-binary = [...]; --no-binary lines in requirements files; --no-binary PKGS on the command line |
Wheels are ignored for those packages, so their sdists are inspected even when a wheel exists. |
| no-build | [tool.uv] no-build / no-build-package; [tool.uv.pip] no-build and only-binary; --only-binary lines in requirements files; --no-build PKGS on the command line |
A package with no matching wheel is an error (no-build), with the first newer release that has a wheel as the fix. |
PKGS is a comma-separated list of names or :all:; requirements files also accept
:none:, and later lines override earlier ones as in pip. A package named explicitly in
one setting beats :all: in the other. The report shows the settings in effect and where
they came from:
$ canibuild examples/broken/requirements.txt --python 3.12 --no-build :all:
canibuild: examples/broken/requirements.txt for CPython 3.12 on linux-x86_64
2 packages checked, 0 build from source, 1 will fail, 0 may fail
build settings: no-build: :all: (from --no-build)
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. For a missing build requirement such as torch, it builds once more
with the requirement added through uv's extra-build-dependencies, and shows the next error
if the build still fails (for flash-attn that is CUDA_HOME not being set).
$ 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 (the detail names both), 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]
[--no-binary PKGS] [--no-build PKGS]
[--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,3.15, or3.14tfor a free-threaded build. 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.--no-binary,--no-build: force or forbid source builds (see above); added to the settings found in the project's files.--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.4.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
# no-binary: ":all:" # build these from source even when a wheel exists
# no-build: numpy # these must install from a wheel
# 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.4.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
- Versions from other indexes (such as
torch==2.1.2+cu121) and non-git version control (Mercurial, Subversion, Bazaar) are listed as not checked. Private git repositories work only ifgitcan reach them without a prompt. - 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. The C checks only cover the removed 3.15 functions and the limited-API conflict; other free-threading problems (thread safety,Py_mod_gil) and C files over 512 KiB are not inspected. - 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.4.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.4.0.tar.gz | 102.8 kB | Without provenance | Details for canibuild-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| canibuild-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for canibuild-0.4.0-py3-none-any.whl |
Total release size: 161.9 kB
Release files / canibuild-0.4.0.tar.gz
| Download URL | canibuild-0.4.0.tar.gz |
|---|---|
| Size | 102.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4882ba8f88634ce2c26d23bcfb61fc7c572ba43f85ca93dd883d8e34514197d1
|
|
BLAKE2b-256 checksum How to use checksums |
f18ee9ba0ac4231e6a15779cc1067bbd42634db319bff5538952fd90e98fd182
|
| 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.4.0-py3-none-any.whl
| Download URL | canibuild-0.4.0-py3-none-any.whl |
|---|---|
| Size | 59.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3f2cfef951c7ed578de8644ab4c9d0af299f7deeaaf96a0fb65d700f3dfe763c
|
|
BLAKE2b-256 checksum How to use checksums |
024ce5794364d6547c61ba18beb7665c8d8abee82919bb4989db690b9f510bdf
|
| 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.4.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.