canibuild 0.1.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. canibuild-0.3.0/.github/workflows/integrations.yml +118 -0
  2. canibuild-0.3.0/.pre-commit-hooks.yaml +8 -0
  3. canibuild-0.3.0/CHANGELOG.md +46 -0
  4. {canibuild-0.1.0 → canibuild-0.3.0}/PKG-INFO +145 -10
  5. {canibuild-0.1.0 → canibuild-0.3.0}/README.md +144 -9
  6. canibuild-0.3.0/action/run.sh +51 -0
  7. canibuild-0.3.0/action.yml +68 -0
  8. {canibuild-0.1.0 → canibuild-0.3.0}/docs/validation.md +40 -0
  9. canibuild-0.3.0/examples/broken/requirements.txt +2 -0
  10. canibuild-0.3.0/examples/clean/pyproject.toml +8 -0
  11. canibuild-0.3.0/examples/clean/uv.lock +217 -0
  12. canibuild-0.3.0/examples/git/requirements.txt +1 -0
  13. {canibuild-0.1.0 → canibuild-0.3.0}/src/canibuild/__init__.py +1 -1
  14. {canibuild-0.1.0 → canibuild-0.3.0}/src/canibuild/check.py +276 -17
  15. canibuild-0.3.0/src/canibuild/cli.py +266 -0
  16. {canibuild-0.1.0 → canibuild-0.3.0}/src/canibuild/fixes.py +9 -0
  17. {canibuild-0.1.0 → canibuild-0.3.0}/src/canibuild/lockfiles.py +348 -5
  18. canibuild-0.3.0/src/canibuild/model.py +235 -0
  19. {canibuild-0.1.0 → canibuild-0.3.0}/src/canibuild/pypi.py +4 -0
  20. {canibuild-0.1.0 → canibuild-0.3.0}/src/canibuild/report.py +37 -2
  21. {canibuild-0.1.0 → canibuild-0.3.0}/src/canibuild/sdist.py +104 -30
  22. canibuild-0.3.0/src/canibuild/sources.py +254 -0
  23. canibuild-0.3.0/src/canibuild/verify.py +336 -0
  24. canibuild-0.3.0/tests/fixtures/uv-direct-sources.pyproject.toml +12 -0
  25. canibuild-0.3.0/tests/fixtures/uv-direct-sources.uv.lock +54 -0
  26. {canibuild-0.1.0 → canibuild-0.3.0}/tests/test_check.py +350 -9
  27. {canibuild-0.1.0 → canibuild-0.3.0}/tests/test_cli.py +165 -1
  28. {canibuild-0.1.0 → canibuild-0.3.0}/tests/test_fixes.py +24 -0
  29. {canibuild-0.1.0 → canibuild-0.3.0}/tests/test_lockfiles.py +195 -2
  30. canibuild-0.3.0/tests/test_model.py +84 -0
  31. canibuild-0.3.0/tests/test_report.py +161 -0
  32. {canibuild-0.1.0 → canibuild-0.3.0}/tests/test_sdist.py +31 -1
  33. canibuild-0.3.0/tests/test_sources.py +96 -0
  34. canibuild-0.3.0/tests/test_verify.py +334 -0
  35. canibuild-0.1.0/CHANGELOG.md +0 -16
  36. canibuild-0.1.0/src/canibuild/cli.py +0 -163
  37. canibuild-0.1.0/src/canibuild/model.py +0 -102
  38. canibuild-0.1.0/tests/test_report.py +0 -45
  39. {canibuild-0.1.0 → canibuild-0.3.0}/.github/workflows/tests.yml +0 -0
  40. {canibuild-0.1.0 → canibuild-0.3.0}/.gitignore +0 -0
  41. {canibuild-0.1.0 → canibuild-0.3.0}/LICENSE +0 -0
  42. {canibuild-0.1.0 → canibuild-0.3.0}/pyproject.toml +0 -0
  43. {canibuild-0.1.0 → canibuild-0.3.0}/src/canibuild/__main__.py +0 -0
  44. {canibuild-0.1.0 → canibuild-0.3.0}/src/canibuild/py.typed +0 -0
  45. {canibuild-0.1.0 → canibuild-0.3.0}/src/canibuild/rules.py +0 -0
  46. {canibuild-0.1.0 → canibuild-0.3.0}/src/canibuild/target.py +0 -0
  47. {canibuild-0.1.0 → canibuild-0.3.0}/tests/conftest.py +0 -0
  48. {canibuild-0.1.0 → canibuild-0.3.0}/tests/fixtures/base.txt +0 -0
  49. {canibuild-0.1.0 → canibuild-0.3.0}/tests/fixtures/pylock.toml +0 -0
  50. {canibuild-0.1.0 → canibuild-0.3.0}/tests/fixtures/requirements.txt +0 -0
  51. {canibuild-0.1.0 → canibuild-0.3.0}/tests/fixtures/uv.lock +0 -0
  52. {canibuild-0.1.0 → canibuild-0.3.0}/tests/test_pypi.py +0 -0
  53. {canibuild-0.1.0 → canibuild-0.3.0}/tests/test_rules.py +0 -0
  54. {canibuild-0.1.0 → canibuild-0.3.0}/tests/test_target.py +0 -0
@@ -0,0 +1,118 @@
1
+ name: integrations
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ action:
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ os: [ubuntu-latest, macos-latest, windows-latest]
17
+ runs-on: ${{ matrix.os }}
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+
21
+ - name: Clean lockfile passes
22
+ uses: ./
23
+ with:
24
+ lockfiles: examples/clean/uv.lock
25
+
26
+ - name: Broken lockfile fails
27
+ id: broken
28
+ continue-on-error: true
29
+ uses: ./
30
+ with:
31
+ lockfiles: examples/broken/requirements.txt
32
+ python: "3.12"
33
+ tool: uv-pip pip
34
+ verify: "true"
35
+
36
+ - name: Check the broken run failed, and a real build confirmed it
37
+ shell: bash
38
+ env:
39
+ OUTCOME: ${{ steps.broken.outcome }}
40
+ REPORT: ${{ steps.broken.outputs.report }}
41
+ run: |
42
+ test "$OUTCOME" = failure
43
+ python3 - "$REPORT" <<'PY'
44
+ import json, sys
45
+ reports = json.load(open(sys.argv[1]))
46
+ [flatdict] = [f for r in reports for f in r["findings"] if f["package"] == "flatdict"]
47
+ assert flatdict["rule"] == "pkg-resources", flatdict
48
+ assert flatdict["verification"]["status"] == "confirmed", flatdict
49
+ assert flatdict["verification"]["fix_builds"] is True, flatdict
50
+ PY
51
+
52
+ - name: no-build turns the missing wheel into a failure
53
+ id: nobuild
54
+ continue-on-error: true
55
+ uses: ./
56
+ with:
57
+ lockfiles: examples/broken/requirements.txt
58
+ python: "3.12"
59
+ no-build: ":all:"
60
+
61
+ - name: Check the no-build run reported the no-build rule
62
+ shell: bash
63
+ env:
64
+ OUTCOME: ${{ steps.nobuild.outcome }}
65
+ REPORT: ${{ steps.nobuild.outputs.report }}
66
+ run: |
67
+ test "$OUTCOME" = failure
68
+ python3 - "$REPORT" <<'PY'
69
+ import json, sys
70
+ reports = json.load(open(sys.argv[1]))
71
+ rules = {f["rule"] for r in reports for f in r["findings"]}
72
+ assert rules == {"no-build"}, rules
73
+ PY
74
+
75
+ - name: Git dependency is fetched, checked and built
76
+ id: git
77
+ continue-on-error: true
78
+ uses: ./
79
+ with:
80
+ lockfiles: examples/git/requirements.txt
81
+ python: "3.12"
82
+ verify: "true"
83
+
84
+ - name: Check the git dependency was confirmed by a real build
85
+ shell: bash
86
+ env:
87
+ OUTCOME: ${{ steps.git.outcome }}
88
+ REPORT: ${{ steps.git.outputs.report }}
89
+ run: |
90
+ test "$OUTCOME" = failure
91
+ python3 - "$REPORT" <<'PY'
92
+ import json, sys
93
+ [finding] = [f for r in json.load(open(sys.argv[1])) for f in r["findings"]]
94
+ assert finding["rule"] == "pkg-resources", finding
95
+ assert finding["source"].startswith("flatdict @ git+https://github.com/gmr/flatdict@"), finding
96
+ assert finding["verification"]["status"] == "confirmed", finding
97
+ assert finding["verification"]["fix_builds"] is True, finding
98
+ PY
99
+
100
+ - name: Lockfiles found automatically
101
+ uses: ./
102
+ with:
103
+ working-directory: examples/clean
104
+
105
+ pre-commit:
106
+ runs-on: ubuntu-latest
107
+ steps:
108
+ - uses: actions/checkout@v4
109
+ - uses: astral-sh/setup-uv@v10.4.2
110
+ with:
111
+ enable-cache: false
112
+ - name: Hook passes on the clean lockfile
113
+ run: uvx pre-commit try-repo . canibuild --files examples/clean/uv.lock examples/clean/pyproject.toml
114
+ - name: Hook fails on the broken lockfile
115
+ run: |
116
+ if uvx pre-commit try-repo . canibuild --files examples/broken/requirements.txt; then
117
+ echo "expected the hook to fail"; exit 1
118
+ fi
@@ -0,0 +1,8 @@
1
+ - id: canibuild
2
+ name: canibuild
3
+ description: Check lockfiles for dependencies that will fail to build from source
4
+ entry: canibuild
5
+ language: python
6
+ files: (^|/)(uv\.lock|pylock(\.[^/]+)?\.toml|requirements[^/]*\.txt)$
7
+ pass_filenames: true
8
+ require_serial: true
@@ -0,0 +1,46 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0 (2026-12-05)
4
+
5
+ - Git, path and URL dependencies are now checked instead of listed as not checked.
6
+ Git sources are fetched at the locked commit (shallow, hooks disabled, no submodules)
7
+ and cached by commit; local directories and archives are read in place; URL sdists are
8
+ downloaded and wheel URLs are matched against the target. Package code is never run.
9
+ Findings say where the code came from, and `--verify` builds them from the same
10
+ reference.
11
+ - no-binary and no-build settings are honoured: from `[tool.uv]`, `[tool.uv.pip]`,
12
+ `uv.toml`, requirements-file `--no-binary` / `--only-binary` lines, and the new
13
+ `--no-binary` / `--no-build` options. A package that needs a build while builds are
14
+ forbidden is reported with the new `no-build` rule. The report shows the settings in
15
+ effect. The GitHub Action has matching `no-binary` and `no-build` inputs.
16
+ - `--verify` retries a confirmed missing build requirement with it added through uv's
17
+ `extra-build-dependencies`, and shows the next error when the build still fails.
18
+ - `--verify` explains why it skipped a foreign target platform.
19
+
20
+ ## 0.2.0 (2026-12-05)
21
+
22
+ - `--verify` builds each flagged sdist in a throwaway uv environment and reports, per
23
+ finding, whether the failure is confirmed, fails differently, is refuted, or timed out,
24
+ and whether the suggested build constraint makes it build. Refuted findings no longer
25
+ fail the run. `--verify-timeout` limits each build (default 900 seconds).
26
+ - Several lockfiles can be checked in one run; the run fails if any of them does.
27
+ - `--json-report PATH` writes the JSON report while printing text.
28
+ - A composite GitHub Action (`uses: driftwright/canibuild@v0.2.0`) that writes the report
29
+ to the job summary, and a pre-commit hook (`id: canibuild`).
30
+ - Example lockfiles in `examples/`, used by the integration tests.
31
+ - The summary line uses the singular for counts of one.
32
+
33
+ ## 0.1.0 (2026-12-05)
34
+
35
+ First release.
36
+
37
+ - Reads `uv.lock`, `pylock.toml` and requirements files (with `-r` includes), keeping
38
+ only the packages the target Python and platform need.
39
+ - Finds the packages with no wheel for the target, inspects their sdists without running
40
+ them, and reports builds that will fail: `pkg_resources` with setuptools 82+, old
41
+ setuptools-scm and pbr pins, removed setuptools APIs, `numpy.distutils`, `distutils` on
42
+ Python 3.12+, undeclared build imports such as `torch`, and releases with nothing to
43
+ install.
44
+ - Gives fixes for uv, uv pip, pip and Poetry, and suggests the oldest newer release that
45
+ installs cleanly.
46
+ - Text and JSON output; exits with 1 when something will fail.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: canibuild
3
- Version: 0.1.0
3
+ Version: 0.3.0
4
4
  Summary: Check a lockfile for dependencies that will fail to build from source, before you install.
5
5
  Project-URL: Homepage, https://github.com/driftwright/canibuild
6
6
  Project-URL: Issues, https://github.com/driftwright/canibuild/issues
@@ -56,7 +56,7 @@ at `904dc66`), whose `uv sync` broke on `flatdict` 4.0.1:
56
56
  ```console
57
57
  $ canibuild check uv.lock --python 3.12 --platform linux-x86_64
58
58
  canibuild: uv.lock for CPython 3.12 on linux-x86_64
59
- 81 packages checked, 1 build from source, 1 will fail, 0 may fail
59
+ 81 packages checked, 1 builds from source, 1 will fail, 0 may fail
60
60
 
61
61
  SEVERITY PACKAGE VERSION RULE PROBLEM
62
62
  ERROR flatdict 4.0.1 pkg-resources setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1
@@ -121,6 +121,47 @@ is reported as a warning, since it fails only if that code runs during the build
121
121
  Packages that build from source with no known problem are listed as such, with a note
122
122
  when they compile native code.
123
123
 
124
+ ### Git, path and URL dependencies
125
+
126
+ Dependencies that installers fetch directly are always built from source, so canibuild
127
+ checks them with the same rules:
128
+
129
+ - **git** (`source = { git = ... }` in `uv.lock`, `vcs` in `pylock.toml`,
130
+ `name @ git+https://...@rev` or `-e git+...` in requirements): fetched with
131
+ `git fetch --depth 1` at the locked commit (or the branch or tag the requirement names),
132
+ with hooks disabled and no submodules, then read like an sdist. Checkouts of a pinned
133
+ commit are cached. When the requirement names a branch or tag, or nothing, the report
134
+ says which commit was checked.
135
+ - **path** (`directory`, `path` and non-root `editable` sources, `./dir`, `file:` URLs):
136
+ the local directory or archive is read in place, relative to the lockfile.
137
+ - **URL** (`source = { url = ... }`, `archive` in `pylock.toml`, `name @ https://...`):
138
+ sdists are downloaded and read; a wheel URL is only checked against the target's tags.
139
+
140
+ Findings for these show where the code came from, and `--verify` builds them from the same
141
+ reference (`name @ git+URL@commit`), so a git build needs access to that git host.
142
+
143
+ ### Forcing or forbidding source builds
144
+
145
+ Some projects build certain packages from source on purpose, or forbid source builds
146
+ entirely. canibuild reads those settings and checks accordingly:
147
+
148
+ | Setting | Where canibuild reads it | Effect |
149
+ | --- | --- | --- |
150
+ | 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. |
151
+ | 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. |
152
+
153
+ `PKGS` is a comma-separated list of names or `:all:`; requirements files also accept
154
+ `:none:`, and later lines override earlier ones as in pip. A package named explicitly in
155
+ one setting beats `:all:` in the other. The report shows the settings in effect and where
156
+ they came from:
157
+
158
+ ```console
159
+ $ canibuild examples/broken/requirements.txt --python 3.12 --no-build :all:
160
+ canibuild: examples/broken/requirements.txt for CPython 3.12 on linux-x86_64
161
+ 2 packages checked, 0 build from source, 1 will fail, 0 may fail
162
+ build settings: no-build: :all: (from --no-build)
163
+ ```
164
+
124
165
  The setuptools version a build would get is worked out from the sdist's own
125
166
  `build-system.requires` (or pip's and uv's default of `setuptools>=40.8.0` when it has
126
167
  none) and the setuptools releases on PyPI, so a package that already caps
@@ -148,6 +189,51 @@ suggests upgrading to the oldest such release first.
148
189
  Note that uv's own hint for this error suggests adding `pkg_resources` to
149
190
  `extra-build-dependencies`. That can't work: `pkg_resources` isn't a package on PyPI.
150
191
 
192
+ ## Confirming a prediction with a real build
193
+
194
+ The checks above are static. `--verify` goes one step further: for every package with an
195
+ error or warning, it builds that sdist in a throwaway environment with uv
196
+ (`uv pip install --no-deps --no-binary PKG`, from PyPI only, isolated from your uv config),
197
+ and records whether the build really fails the way canibuild said. When the finding has a
198
+ build constraint such as `setuptools<82`, it builds once more with that constraint to show
199
+ whether the fix works. For a missing build requirement such as `torch`, it builds once more
200
+ with the requirement added through uv's `extra-build-dependencies`, and shows the next error
201
+ if the build still fails (for `flash-attn` that is `CUDA_HOME` not being set).
202
+
203
+ ```console
204
+ $ canibuild examples/broken/requirements.txt --python 3.12 --verify --tool uv-pip
205
+ canibuild: building flatdict 4.0.1 to verify...
206
+ canibuild: examples/broken/requirements.txt for CPython 3.12 on linux-x86_64
207
+ 2 packages checked, 1 builds from source, 1 will fail, 0 may fail, 1 confirmed by a real build
208
+
209
+ SEVERITY PACKAGE VERSION RULE PROBLEM
210
+ ERROR flatdict 4.0.1 pkg-resources setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1
211
+
212
+ flatdict 4.0.1: setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1
213
+ at setup.py:1: import pkg_resources
214
+ verified: confirmed (ModuleNotFoundError: No module named 'pkg_resources')
215
+ with setuptools<82 in the build: builds
216
+ fix (any): Upgrade flatdict to 4.1.0, the first newer release with a wheel for this target
217
+ flatdict>=4.1.0 # in requirements
218
+ fix (uv pip): Pass a build constraints file
219
+ echo 'setuptools<82' > build-constraints.txt
220
+ uv pip install -b build-constraints.txt -r requirements.txt
221
+ ```
222
+
223
+ Each finding gets one of these results:
224
+
225
+ | Result | Meaning |
226
+ | --- | --- |
227
+ | `confirmed` | The build failed with the error the finding predicts. |
228
+ | `fails-differently` | The build failed, but not with that error. The last error line is shown. |
229
+ | `refuted` | The build succeeded. The finding no longer counts toward `--fail-on`. |
230
+ | `timeout` | No result within `--verify-timeout` seconds (default 900). |
231
+ | `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. |
232
+
233
+ Builds run one at a time, so `--verify` takes as long as the flagged builds do; large
234
+ native packages can take minutes. uv may download the target Python if it isn't installed.
235
+ Missing-file and not-checked findings are not built.
236
+
151
237
  ## Tested on real lockfiles
152
238
 
153
239
  canibuild was run on 13 lockfiles from public repositories (5 `uv.lock`, 8 requirements
@@ -165,18 +251,24 @@ environment with `uv pip install --no-deps`, to see which builds really fail.
165
251
  setuptools-scm 3.x) is caught by `build-tool-needs-pkg-resources`, fails for real, and
166
252
  builds with the same constraint.
167
253
 
254
+ Running the same lockfiles with `--verify` confirmed all 9 build failures it could build
255
+ (`faiss-cpu` has nothing to build), and the `setuptools<82` constraint made all 8
256
+ `pkg_resources` cases build.
257
+
168
258
  The lockfiles, their commits and the per-package results are in
169
259
  [`docs/validation.md`](docs/validation.md).
170
260
 
171
261
  ## Usage
172
262
 
173
263
  ```
174
- canibuild [check] LOCKFILE [--python X.Y] [--platform P] [--format text|json]
175
- [--fail-on error|warning|never] [--tool TOOL] [--jobs N]
176
- [--cache-dir DIR] [--no-cache] [-v]
264
+ canibuild [check] LOCKFILE... [--python X.Y] [--platform P] [--format text|json]
265
+ [--fail-on error|warning|never] [--tool TOOL] [--jobs N]
266
+ [--no-binary PKGS] [--no-build PKGS]
267
+ [--verify] [--verify-timeout SECONDS] [--json-report PATH]
268
+ [--cache-dir DIR] [--no-cache] [-v]
177
269
  ```
178
270
 
179
- - `LOCKFILE`: `uv.lock`, `pylock.toml` (or `pylock.NAME.toml`), or a requirements file.
271
+ - `LOCKFILE`: one or more of `uv.lock`, `pylock.toml` (or `pylock.NAME.toml`), or a requirements file.
180
272
  Requirements files may include other files with `-r`. Unpinned requirements are checked
181
273
  at the newest release that matches and supports the target Python.
182
274
  - `--python`: the target Python, such as `3.12`. Defaults to the running interpreter, or
@@ -185,17 +277,60 @@ canibuild [check] LOCKFILE [--python X.Y] [--platform P] [--format text|json]
185
277
  - `--platform`: `linux-x86_64`, `linux-aarch64`, `musllinux-x86_64`, `musllinux-aarch64`,
186
278
  `macos-arm64`, `macos-x86_64`, `windows-amd64`, `windows-arm64`, `windows-x86`, or a raw
187
279
  platform tag such as `manylinux_2_28_x86_64`. Defaults to the current machine.
188
- - `--format json`: machine-readable output with every finding and fix.
280
+ - `--format json`: machine-readable output with every finding and fix (a list when you
281
+ pass several lockfiles).
282
+ - `--json-report PATH`: also write the JSON report, always as a list, while printing text.
283
+ - `--no-binary`, `--no-build`: force or forbid source builds (see above); added to the
284
+ settings found in the project's files.
285
+ - `--verify`, `--verify-timeout`: build flagged sdists to confirm the findings (see above).
189
286
  - `--fail-on`: exit with 1 on errors (the default), on warnings too, or never.
190
- Usage errors and unreadable lockfiles exit with 2.
287
+ With several lockfiles, the run fails if any of them does. Usage errors and unreadable
288
+ lockfiles exit with 2.
191
289
 
192
290
  Downloaded sdists are cached in the user cache directory (`~/.cache/canibuild` on Linux,
193
291
  or `$CANIBUILD_CACHE_DIR`).
194
292
 
293
+ ## GitHub Action
294
+
295
+ ```yaml
296
+ - uses: actions/checkout@v4
297
+ - uses: driftwright/canibuild@v0.3.0
298
+ with:
299
+ lockfiles: uv.lock # default: every uv.lock, pylock*.toml, requirements*.txt
300
+ python: "3.12" # default: as for --python below
301
+ # platform: linux-x86_64 # default: the runner
302
+ # fail-on: error # error, warning or never
303
+ # tool: uv # tools to show fixes for
304
+ # no-binary: ":all:" # build these from source even when a wheel exists
305
+ # no-build: numpy # these must install from a wheel
306
+ # verify: "true" # build flagged sdists to confirm the findings
307
+ ```
308
+
309
+ The action installs uv, runs canibuild with the code of the tag you pinned (or the PyPI
310
+ release given in `version`), prints the report, adds it to the job summary, and fails the
311
+ step when something will fail to build. The JSON report's path is in the `report` output.
312
+ Check several targets with a matrix over `python` and `platform`; `verify` only builds
313
+ when `platform` is the runner's own.
314
+
315
+ ## pre-commit
316
+
317
+ ```yaml
318
+ repos:
319
+ - repo: https://github.com/driftwright/canibuild
320
+ rev: v0.3.0
321
+ hooks:
322
+ - id: canibuild
323
+ # args: [--python, "3.12"]
324
+ ```
325
+
326
+ The hook runs when `uv.lock`, a `pylock*.toml` or a `requirements*.txt` changes, and needs
327
+ network access to PyPI.
328
+
195
329
  ## Limits
196
330
 
197
- - Only packages from PyPI are checked. Git, path and URL dependencies, and versions from
198
- other indexes (such as `torch==2.1.2+cu121`), are listed as not checked.
331
+ - Versions from other indexes (such as `torch==2.1.2+cu121`) and non-git version control
332
+ (Mercurial, Subversion, Bazaar) are listed as not checked. Private git repositories work
333
+ only if `git` can reach them without a prompt.
199
334
  - The checks are static. A `setup.py` that fails for a reason not in the table above, or
200
335
  that needs a compiler or system library you don't have, isn't caught.
201
336
  - Requirements files are not resolved: only the packages they list are checked, not their
@@ -24,7 +24,7 @@ at `904dc66`), whose `uv sync` broke on `flatdict` 4.0.1:
24
24
  ```console
25
25
  $ canibuild check uv.lock --python 3.12 --platform linux-x86_64
26
26
  canibuild: uv.lock for CPython 3.12 on linux-x86_64
27
- 81 packages checked, 1 build from source, 1 will fail, 0 may fail
27
+ 81 packages checked, 1 builds from source, 1 will fail, 0 may fail
28
28
 
29
29
  SEVERITY PACKAGE VERSION RULE PROBLEM
30
30
  ERROR flatdict 4.0.1 pkg-resources setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1
@@ -89,6 +89,47 @@ is reported as a warning, since it fails only if that code runs during the build
89
89
  Packages that build from source with no known problem are listed as such, with a note
90
90
  when they compile native code.
91
91
 
92
+ ### Git, path and URL dependencies
93
+
94
+ Dependencies that installers fetch directly are always built from source, so canibuild
95
+ checks them with the same rules:
96
+
97
+ - **git** (`source = { git = ... }` in `uv.lock`, `vcs` in `pylock.toml`,
98
+ `name @ git+https://...@rev` or `-e git+...` in requirements): fetched with
99
+ `git fetch --depth 1` at the locked commit (or the branch or tag the requirement names),
100
+ with hooks disabled and no submodules, then read like an sdist. Checkouts of a pinned
101
+ commit are cached. When the requirement names a branch or tag, or nothing, the report
102
+ says which commit was checked.
103
+ - **path** (`directory`, `path` and non-root `editable` sources, `./dir`, `file:` URLs):
104
+ the local directory or archive is read in place, relative to the lockfile.
105
+ - **URL** (`source = { url = ... }`, `archive` in `pylock.toml`, `name @ https://...`):
106
+ sdists are downloaded and read; a wheel URL is only checked against the target's tags.
107
+
108
+ Findings for these show where the code came from, and `--verify` builds them from the same
109
+ reference (`name @ git+URL@commit`), so a git build needs access to that git host.
110
+
111
+ ### Forcing or forbidding source builds
112
+
113
+ Some projects build certain packages from source on purpose, or forbid source builds
114
+ entirely. canibuild reads those settings and checks accordingly:
115
+
116
+ | Setting | Where canibuild reads it | Effect |
117
+ | --- | --- | --- |
118
+ | 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. |
119
+ | 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. |
120
+
121
+ `PKGS` is a comma-separated list of names or `:all:`; requirements files also accept
122
+ `:none:`, and later lines override earlier ones as in pip. A package named explicitly in
123
+ one setting beats `:all:` in the other. The report shows the settings in effect and where
124
+ they came from:
125
+
126
+ ```console
127
+ $ canibuild examples/broken/requirements.txt --python 3.12 --no-build :all:
128
+ canibuild: examples/broken/requirements.txt for CPython 3.12 on linux-x86_64
129
+ 2 packages checked, 0 build from source, 1 will fail, 0 may fail
130
+ build settings: no-build: :all: (from --no-build)
131
+ ```
132
+
92
133
  The setuptools version a build would get is worked out from the sdist's own
93
134
  `build-system.requires` (or pip's and uv's default of `setuptools>=40.8.0` when it has
94
135
  none) and the setuptools releases on PyPI, so a package that already caps
@@ -116,6 +157,51 @@ suggests upgrading to the oldest such release first.
116
157
  Note that uv's own hint for this error suggests adding `pkg_resources` to
117
158
  `extra-build-dependencies`. That can't work: `pkg_resources` isn't a package on PyPI.
118
159
 
160
+ ## Confirming a prediction with a real build
161
+
162
+ The checks above are static. `--verify` goes one step further: for every package with an
163
+ error or warning, it builds that sdist in a throwaway environment with uv
164
+ (`uv pip install --no-deps --no-binary PKG`, from PyPI only, isolated from your uv config),
165
+ and records whether the build really fails the way canibuild said. When the finding has a
166
+ build constraint such as `setuptools<82`, it builds once more with that constraint to show
167
+ whether the fix works. For a missing build requirement such as `torch`, it builds once more
168
+ with the requirement added through uv's `extra-build-dependencies`, and shows the next error
169
+ if the build still fails (for `flash-attn` that is `CUDA_HOME` not being set).
170
+
171
+ ```console
172
+ $ canibuild examples/broken/requirements.txt --python 3.12 --verify --tool uv-pip
173
+ canibuild: building flatdict 4.0.1 to verify...
174
+ canibuild: examples/broken/requirements.txt for CPython 3.12 on linux-x86_64
175
+ 2 packages checked, 1 builds from source, 1 will fail, 0 may fail, 1 confirmed by a real build
176
+
177
+ SEVERITY PACKAGE VERSION RULE PROBLEM
178
+ ERROR flatdict 4.0.1 pkg-resources setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1
179
+
180
+ flatdict 4.0.1: setup.py imports pkg_resources, which setuptools 82 removed; a fresh build gets setuptools 84.2.1
181
+ at setup.py:1: import pkg_resources
182
+ verified: confirmed (ModuleNotFoundError: No module named 'pkg_resources')
183
+ with setuptools<82 in the build: builds
184
+ fix (any): Upgrade flatdict to 4.1.0, the first newer release with a wheel for this target
185
+ flatdict>=4.1.0 # in requirements
186
+ fix (uv pip): Pass a build constraints file
187
+ echo 'setuptools<82' > build-constraints.txt
188
+ uv pip install -b build-constraints.txt -r requirements.txt
189
+ ```
190
+
191
+ Each finding gets one of these results:
192
+
193
+ | Result | Meaning |
194
+ | --- | --- |
195
+ | `confirmed` | The build failed with the error the finding predicts. |
196
+ | `fails-differently` | The build failed, but not with that error. The last error line is shown. |
197
+ | `refuted` | The build succeeded. The finding no longer counts toward `--fail-on`. |
198
+ | `timeout` | No result within `--verify-timeout` seconds (default 900). |
199
+ | `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. |
200
+
201
+ Builds run one at a time, so `--verify` takes as long as the flagged builds do; large
202
+ native packages can take minutes. uv may download the target Python if it isn't installed.
203
+ Missing-file and not-checked findings are not built.
204
+
119
205
  ## Tested on real lockfiles
120
206
 
121
207
  canibuild was run on 13 lockfiles from public repositories (5 `uv.lock`, 8 requirements
@@ -133,18 +219,24 @@ environment with `uv pip install --no-deps`, to see which builds really fail.
133
219
  setuptools-scm 3.x) is caught by `build-tool-needs-pkg-resources`, fails for real, and
134
220
  builds with the same constraint.
135
221
 
222
+ Running the same lockfiles with `--verify` confirmed all 9 build failures it could build
223
+ (`faiss-cpu` has nothing to build), and the `setuptools<82` constraint made all 8
224
+ `pkg_resources` cases build.
225
+
136
226
  The lockfiles, their commits and the per-package results are in
137
227
  [`docs/validation.md`](docs/validation.md).
138
228
 
139
229
  ## Usage
140
230
 
141
231
  ```
142
- canibuild [check] LOCKFILE [--python X.Y] [--platform P] [--format text|json]
143
- [--fail-on error|warning|never] [--tool TOOL] [--jobs N]
144
- [--cache-dir DIR] [--no-cache] [-v]
232
+ canibuild [check] LOCKFILE... [--python X.Y] [--platform P] [--format text|json]
233
+ [--fail-on error|warning|never] [--tool TOOL] [--jobs N]
234
+ [--no-binary PKGS] [--no-build PKGS]
235
+ [--verify] [--verify-timeout SECONDS] [--json-report PATH]
236
+ [--cache-dir DIR] [--no-cache] [-v]
145
237
  ```
146
238
 
147
- - `LOCKFILE`: `uv.lock`, `pylock.toml` (or `pylock.NAME.toml`), or a requirements file.
239
+ - `LOCKFILE`: one or more of `uv.lock`, `pylock.toml` (or `pylock.NAME.toml`), or a requirements file.
148
240
  Requirements files may include other files with `-r`. Unpinned requirements are checked
149
241
  at the newest release that matches and supports the target Python.
150
242
  - `--python`: the target Python, such as `3.12`. Defaults to the running interpreter, or
@@ -153,17 +245,60 @@ canibuild [check] LOCKFILE [--python X.Y] [--platform P] [--format text|json]
153
245
  - `--platform`: `linux-x86_64`, `linux-aarch64`, `musllinux-x86_64`, `musllinux-aarch64`,
154
246
  `macos-arm64`, `macos-x86_64`, `windows-amd64`, `windows-arm64`, `windows-x86`, or a raw
155
247
  platform tag such as `manylinux_2_28_x86_64`. Defaults to the current machine.
156
- - `--format json`: machine-readable output with every finding and fix.
248
+ - `--format json`: machine-readable output with every finding and fix (a list when you
249
+ pass several lockfiles).
250
+ - `--json-report PATH`: also write the JSON report, always as a list, while printing text.
251
+ - `--no-binary`, `--no-build`: force or forbid source builds (see above); added to the
252
+ settings found in the project's files.
253
+ - `--verify`, `--verify-timeout`: build flagged sdists to confirm the findings (see above).
157
254
  - `--fail-on`: exit with 1 on errors (the default), on warnings too, or never.
158
- Usage errors and unreadable lockfiles exit with 2.
255
+ With several lockfiles, the run fails if any of them does. Usage errors and unreadable
256
+ lockfiles exit with 2.
159
257
 
160
258
  Downloaded sdists are cached in the user cache directory (`~/.cache/canibuild` on Linux,
161
259
  or `$CANIBUILD_CACHE_DIR`).
162
260
 
261
+ ## GitHub Action
262
+
263
+ ```yaml
264
+ - uses: actions/checkout@v4
265
+ - uses: driftwright/canibuild@v0.3.0
266
+ with:
267
+ lockfiles: uv.lock # default: every uv.lock, pylock*.toml, requirements*.txt
268
+ python: "3.12" # default: as for --python below
269
+ # platform: linux-x86_64 # default: the runner
270
+ # fail-on: error # error, warning or never
271
+ # tool: uv # tools to show fixes for
272
+ # no-binary: ":all:" # build these from source even when a wheel exists
273
+ # no-build: numpy # these must install from a wheel
274
+ # verify: "true" # build flagged sdists to confirm the findings
275
+ ```
276
+
277
+ The action installs uv, runs canibuild with the code of the tag you pinned (or the PyPI
278
+ release given in `version`), prints the report, adds it to the job summary, and fails the
279
+ step when something will fail to build. The JSON report's path is in the `report` output.
280
+ Check several targets with a matrix over `python` and `platform`; `verify` only builds
281
+ when `platform` is the runner's own.
282
+
283
+ ## pre-commit
284
+
285
+ ```yaml
286
+ repos:
287
+ - repo: https://github.com/driftwright/canibuild
288
+ rev: v0.3.0
289
+ hooks:
290
+ - id: canibuild
291
+ # args: [--python, "3.12"]
292
+ ```
293
+
294
+ The hook runs when `uv.lock`, a `pylock*.toml` or a `requirements*.txt` changes, and needs
295
+ network access to PyPI.
296
+
163
297
  ## Limits
164
298
 
165
- - Only packages from PyPI are checked. Git, path and URL dependencies, and versions from
166
- other indexes (such as `torch==2.1.2+cu121`), are listed as not checked.
299
+ - Versions from other indexes (such as `torch==2.1.2+cu121`) and non-git version control
300
+ (Mercurial, Subversion, Bazaar) are listed as not checked. Private git repositories work
301
+ only if `git` can reach them without a prompt.
167
302
  - The checks are static. A `setup.py` that fails for a reason not in the table above, or
168
303
  that needs a compiler or system library you don't have, isn't caught.
169
304
  - Requirements files are not resolved: only the packages they list are checked, not their
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env bash
2
+ # Runs canibuild for the composite action. Inputs arrive as CANIBUILD_* variables.
3
+ set -euo pipefail
4
+
5
+ if [[ -n "$CANIBUILD_VERSION" ]]; then
6
+ source_spec="canibuild==$CANIBUILD_VERSION"
7
+ else
8
+ source_spec="$CANIBUILD_ACTION_PATH"
9
+ fi
10
+
11
+ read -r -a lockfiles <<< "$(echo "$CANIBUILD_LOCKFILES" | tr '\n' ' ')"
12
+ if [[ ${#lockfiles[@]} -eq 0 ]]; then
13
+ shopt -s nullglob
14
+ lockfiles=(uv.lock pylock*.toml requirements*.txt)
15
+ shopt -u nullglob
16
+ existing=()
17
+ for f in "${lockfiles[@]}"; do [[ -f "$f" ]] && existing+=("$f"); done
18
+ lockfiles=("${existing[@]+"${existing[@]}"}")
19
+ fi
20
+ if [[ ${#lockfiles[@]} -eq 0 ]]; then
21
+ echo "::error::canibuild: no lockfile found; set the lockfiles input"
22
+ exit 2
23
+ fi
24
+
25
+ args=(--fail-on "$CANIBUILD_FAIL_ON")
26
+ [[ -n "$CANIBUILD_PYTHON" ]] && args+=(--python "$CANIBUILD_PYTHON")
27
+ [[ -n "$CANIBUILD_PLATFORM" ]] && args+=(--platform "$CANIBUILD_PLATFORM")
28
+ for tool in $CANIBUILD_TOOL; do args+=(--tool "$tool"); done
29
+ [[ "$CANIBUILD_VERIFY" == "true" ]] && args+=(--verify)
30
+ [[ -n "${CANIBUILD_NO_BINARY:-}" ]] && args+=(--no-binary "$CANIBUILD_NO_BINARY")
31
+ [[ -n "${CANIBUILD_NO_BUILD:-}" ]] && args+=(--no-build "$CANIBUILD_NO_BUILD")
32
+
33
+ report="${RUNNER_TEMP:-/tmp}/canibuild-report.json"
34
+ text="${RUNNER_TEMP:-/tmp}/canibuild-report.txt"
35
+ echo "report=$report" >> "${GITHUB_OUTPUT:-/dev/null}"
36
+
37
+ status=0
38
+ uvx --no-config --from "$source_spec" canibuild "${lockfiles[@]}" "${args[@]}" \
39
+ --json-report "$report" > "$text" || status=$?
40
+ cat "$text"
41
+
42
+ if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
43
+ {
44
+ echo "### canibuild"
45
+ echo
46
+ echo '```'
47
+ cat "$text"
48
+ echo '```'
49
+ } >> "$GITHUB_STEP_SUMMARY"
50
+ fi
51
+ exit "$status"