crawlberg-cli 1.13.3__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.
- crawlberg_cli-1.13.3/.gitignore +366 -0
- crawlberg_cli-1.13.3/PKG-INFO +32 -0
- crawlberg_cli-1.13.3/README.md +10 -0
- crawlberg_cli-1.13.3/crawlberg_cli/__init__.py +8 -0
- crawlberg_cli-1.13.3/crawlberg_cli/cli.py +45 -0
- crawlberg_cli-1.13.3/crawlberg_cli/downloader.py +299 -0
- crawlberg_cli-1.13.3/hatch_build.py +152 -0
- crawlberg_cli-1.13.3/pyproject.toml +38 -0
- crawlberg_cli-1.13.3/tests/conftest.py +13 -0
- crawlberg_cli-1.13.3/tests/test_downloader.py +80 -0
- crawlberg_cli-1.13.3/tests/test_hatch_build.py +100 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
# Build artifacts
|
|
2
|
+
target/
|
|
3
|
+
build/
|
|
4
|
+
dist/
|
|
5
|
+
|
|
6
|
+
# polylint cache
|
|
7
|
+
.polylint/
|
|
8
|
+
*.so
|
|
9
|
+
*.dylib
|
|
10
|
+
*.dll
|
|
11
|
+
*.pdb
|
|
12
|
+
*.node
|
|
13
|
+
*.whl
|
|
14
|
+
*.tar.gz
|
|
15
|
+
*.gem
|
|
16
|
+
*.jar
|
|
17
|
+
*.a
|
|
18
|
+
*.rlib
|
|
19
|
+
wheels/
|
|
20
|
+
# C test_app downloads the FFI artefacts via download_ffi.sh at build time
|
|
21
|
+
test_apps/c/ffi/include/
|
|
22
|
+
test_apps/c/ffi/lib/
|
|
23
|
+
# ~keep The e2e C leg stages the downloaded prebuilt library, header and version marker
|
|
24
|
+
# into e2e/c/ffi/ (ci-e2e.yaml, "Stage FFI artifacts") BEFORE the fixture-freshness check
|
|
25
|
+
# runs. That check reports untracked files (`git status --porcelain -uall`), so leaving these
|
|
26
|
+
# unignored made the C leg fail as fixture drift on its own build output. Scoped to this
|
|
27
|
+
# directory, not the basenames: test_apps/c/ffi/.alef-ffi-version is tracked.
|
|
28
|
+
e2e/c/ffi/
|
|
29
|
+
**/bin/
|
|
30
|
+
!**/src/bin/
|
|
31
|
+
**/obj/
|
|
32
|
+
|
|
33
|
+
# Rust
|
|
34
|
+
*.rs.bk
|
|
35
|
+
*.profraw
|
|
36
|
+
rust-coverage.lcov
|
|
37
|
+
rust_out
|
|
38
|
+
|
|
39
|
+
# Python
|
|
40
|
+
*.py[cod]
|
|
41
|
+
*$py.class
|
|
42
|
+
*.egg-info/
|
|
43
|
+
__pycache__/
|
|
44
|
+
.venv/
|
|
45
|
+
.ruff_cache/
|
|
46
|
+
.pytest_cache/
|
|
47
|
+
.hypothesis/
|
|
48
|
+
.coverage
|
|
49
|
+
.coverage*
|
|
50
|
+
htmlcov/
|
|
51
|
+
share/python-wheels/
|
|
52
|
+
|
|
53
|
+
# Node.js / WASM
|
|
54
|
+
node_modules/
|
|
55
|
+
.yardoc/
|
|
56
|
+
*.tsbuildinfo
|
|
57
|
+
npm-debug.log*
|
|
58
|
+
pnpm-debug.log*
|
|
59
|
+
yarn-debug.log*
|
|
60
|
+
yarn-error.log*
|
|
61
|
+
# ~keep index.d.ts is NOT ignored: alef generates it from the IR (it carries an alef:hash
|
|
62
|
+
# marker) and `alef verify` fails the build when a generated file is missing AND gitignored
|
|
63
|
+
# -- `alef generate` would write it and git would discard it again, so the loop never closes.
|
|
64
|
+
# ~keep Track the loader after Alef decorates it; NAPI builds must preserve its error shim.
|
|
65
|
+
crates/crawlberg-node/index.native.d.ts
|
|
66
|
+
.wrangler/
|
|
67
|
+
.pnpm-store/
|
|
68
|
+
|
|
69
|
+
# Zig build cache (transient artefacts in e2e/zig and elsewhere)
|
|
70
|
+
.zig-cache/
|
|
71
|
+
zig-out/
|
|
72
|
+
|
|
73
|
+
# Dart pub / build cache
|
|
74
|
+
.dart_tool/
|
|
75
|
+
|
|
76
|
+
# Gradle / Kotlin build cache
|
|
77
|
+
.gradle/
|
|
78
|
+
|
|
79
|
+
# Swift / SwiftPM build cache
|
|
80
|
+
.build/
|
|
81
|
+
.swiftpm/
|
|
82
|
+
# `Packages/` removed: with `core.ignorecase=true` (the macOS default) it
|
|
83
|
+
# case-insensitively matches the language-binding `packages/` tree and silently
|
|
84
|
+
# ignores newly emitted files like `packages/dart/bin/download_libs.dart` —
|
|
85
|
+
# which is alef-generated output we must commit. SwiftPM's `Packages/`
|
|
86
|
+
# resolution dir is opt-in and rarely created in this repo; if it appears,
|
|
87
|
+
# scope-ignore it under `packages/swift/` specifically.
|
|
88
|
+
packages/swift/**/Packages/
|
|
89
|
+
Package.resolved
|
|
90
|
+
*.xcodeproj/
|
|
91
|
+
*.xcworkspace/
|
|
92
|
+
DerivedData/
|
|
93
|
+
|
|
94
|
+
# PHPStan / PHP runtime cache
|
|
95
|
+
packages/php/var/
|
|
96
|
+
|
|
97
|
+
# Ruby
|
|
98
|
+
packages/ruby/.bundle/
|
|
99
|
+
packages/ruby/vendor/
|
|
100
|
+
packages/ruby/tmp/
|
|
101
|
+
packages/ruby/ext/src_rb/
|
|
102
|
+
packages/ruby/lib/*.bundle
|
|
103
|
+
*.Cache
|
|
104
|
+
|
|
105
|
+
# PHP
|
|
106
|
+
php-crawlberg.ini
|
|
107
|
+
packages/php/php-crawlberg.ini
|
|
108
|
+
packages/php/tests.xml
|
|
109
|
+
.php-cs-fixer.cache
|
|
110
|
+
|
|
111
|
+
# Java / C# / .NET
|
|
112
|
+
*.suo
|
|
113
|
+
*.user
|
|
114
|
+
*.cscfg
|
|
115
|
+
*.cobertura.xml
|
|
116
|
+
*.nupkg
|
|
117
|
+
*.versionsBackup
|
|
118
|
+
TestResults/
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
# Elixir
|
|
122
|
+
packages/elixir/_build/
|
|
123
|
+
packages/elixir/deps/
|
|
124
|
+
e2e/elixir/_build/
|
|
125
|
+
e2e/elixir/deps/
|
|
126
|
+
.nox/
|
|
127
|
+
|
|
128
|
+
# C FFI
|
|
129
|
+
crates/crawlberg-ffi/tests/c/test_*
|
|
130
|
+
!crates/crawlberg-ffi/tests/c/test_*.c
|
|
131
|
+
!crates/crawlberg-ffi/tests/c/test_*.h
|
|
132
|
+
crates/crawlberg-ffi/tests/c/*.o
|
|
133
|
+
crates/crawlberg-ffi/tests/c/*.dSYM/
|
|
134
|
+
e2e/c/test_*
|
|
135
|
+
!e2e/c/test_*.c
|
|
136
|
+
!e2e/c/test_*.h
|
|
137
|
+
e2e/c/*.o
|
|
138
|
+
e2e/c/*.dSYM/
|
|
139
|
+
e2e/c/run_tests
|
|
140
|
+
|
|
141
|
+
# Generated pkg-config
|
|
142
|
+
*.pc
|
|
143
|
+
|
|
144
|
+
# Coverage
|
|
145
|
+
coverage/
|
|
146
|
+
coverage.info
|
|
147
|
+
coverage.json
|
|
148
|
+
coverage.lcov
|
|
149
|
+
coverage.out
|
|
150
|
+
coverage.xml
|
|
151
|
+
packages/*/.coverage
|
|
152
|
+
packages/*/coverage.json
|
|
153
|
+
packages/*/coverage.out
|
|
154
|
+
packages/*/htmlcov/
|
|
155
|
+
packages/*/test-results/
|
|
156
|
+
packages/*/TestResults/
|
|
157
|
+
|
|
158
|
+
# IDE / Editor
|
|
159
|
+
.idea/
|
|
160
|
+
.vscode/
|
|
161
|
+
.run/
|
|
162
|
+
.DS_Store
|
|
163
|
+
*.swp
|
|
164
|
+
*.swo
|
|
165
|
+
Thumbs.db
|
|
166
|
+
|
|
167
|
+
# CI / Tools
|
|
168
|
+
.cache/
|
|
169
|
+
.rumdl_cache/
|
|
170
|
+
.tmp/
|
|
171
|
+
*temp/
|
|
172
|
+
*.temp
|
|
173
|
+
*.tmp
|
|
174
|
+
*.log
|
|
175
|
+
.mvn/
|
|
176
|
+
.tox/
|
|
177
|
+
.artifacts/
|
|
178
|
+
.remote-cache/
|
|
179
|
+
docker-logs/
|
|
180
|
+
|
|
181
|
+
# Docs
|
|
182
|
+
docs/_build/
|
|
183
|
+
docs/build/
|
|
184
|
+
site/
|
|
185
|
+
|
|
186
|
+
# Tests
|
|
187
|
+
test_report.json
|
|
188
|
+
tests/e2e/logs/
|
|
189
|
+
tests/e2e/test_report.json
|
|
190
|
+
temp-test-*
|
|
191
|
+
**/test_output.log
|
|
192
|
+
**/logs/
|
|
193
|
+
|
|
194
|
+
# AI / MCP / Agent config
|
|
195
|
+
.alef/
|
|
196
|
+
.claude/
|
|
197
|
+
.codex/
|
|
198
|
+
.gemini/
|
|
199
|
+
.mcp.json
|
|
200
|
+
# ...but the coding-agent plugin bundle's .mcp.json is an ai-rulez-generated
|
|
201
|
+
# output that CI Plugin (`ai-rulez verify --plugin`) requires to be committed.
|
|
202
|
+
!plugin/.mcp.json
|
|
203
|
+
.playwright-mcp/
|
|
204
|
+
AGENTS.md
|
|
205
|
+
CLAUDE.md
|
|
206
|
+
GEMINI.md
|
|
207
|
+
.cursorrules
|
|
208
|
+
.windsurfrules
|
|
209
|
+
[Tt][Oo][Dd][Oo]*
|
|
210
|
+
|
|
211
|
+
# Git worktrees
|
|
212
|
+
.worktrees/
|
|
213
|
+
|
|
214
|
+
# Environment
|
|
215
|
+
.env
|
|
216
|
+
.env.*
|
|
217
|
+
!.env.example
|
|
218
|
+
|
|
219
|
+
# Misc
|
|
220
|
+
output.txt
|
|
221
|
+
/tmp/crawlberg-docker-test-results.json
|
|
222
|
+
*.pyd
|
|
223
|
+
.gems/
|
|
224
|
+
vendor/bundle/
|
|
225
|
+
vendor/*
|
|
226
|
+
!vendor/crawlberg-chromiumoxide/
|
|
227
|
+
!vendor/crawlberg-chromiumoxide/**
|
|
228
|
+
*.h.bak
|
|
229
|
+
*.test
|
|
230
|
+
*.class
|
|
231
|
+
bin/
|
|
232
|
+
# Exempt the alef-emitted Dart entrypoint dir which is real source we must
|
|
233
|
+
# track (used by `dart run crawlberg:download_libs` consumers).
|
|
234
|
+
!packages/dart/bin/
|
|
235
|
+
obj/
|
|
236
|
+
# pkg/ removed — needed for WASM npm publish (wasm-pack outputs to pkg/)
|
|
237
|
+
erl_crash.dump
|
|
238
|
+
test_apps/elixir/_build/
|
|
239
|
+
test_apps/elixir/deps/
|
|
240
|
+
test_apps/elixir/mix.lock
|
|
241
|
+
test_apps/node/pnpm-lock.yaml
|
|
242
|
+
test_apps/zig/zig-pkg/
|
|
243
|
+
pkg/
|
|
244
|
+
|
|
245
|
+
.lycheecache
|
|
246
|
+
.benchmark_results/
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
# E2E mock-server runtime state
|
|
250
|
+
.mock-server.env
|
|
251
|
+
.mock-server.out
|
|
252
|
+
.mock-server.pid
|
|
253
|
+
|
|
254
|
+
# chromiumoxide leak watcher (scripts/chrome-memwatch.sh) — repo-relative
|
|
255
|
+
# log destination so CI can collect it as a build artifact via the
|
|
256
|
+
# predictable path. Already covered by `*.log` above; listed explicitly so
|
|
257
|
+
# the contract is obvious to anyone reading this file.
|
|
258
|
+
chrome-memwatch.log
|
|
259
|
+
|
|
260
|
+
# Per-language smoke workflows scaffolded by alef. crawlberg uses the unified
|
|
261
|
+
# ci-e2e.yaml matrix for all language coverage; these standalone workflows are
|
|
262
|
+
# kept emitted on disk for upstream parity but never committed.
|
|
263
|
+
.github/workflows/dart.yml
|
|
264
|
+
.github/workflows/kotlin.yml
|
|
265
|
+
.github/workflows/swift.yml
|
|
266
|
+
.github/workflows/zig.yml
|
|
267
|
+
|
|
268
|
+
e2e/ruby/.bundle/
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
# basemind local code-map index (machine-local, do not commit)
|
|
272
|
+
.basemind/
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
# Alef-generated skills are source-controlled; other agent-local state stays ignored.
|
|
276
|
+
!.codex/
|
|
277
|
+
.codex/*
|
|
278
|
+
!.codex/skills/
|
|
279
|
+
.codex/skills/*
|
|
280
|
+
!.codex/skills/api/
|
|
281
|
+
!.codex/skills/api/SKILL.md
|
|
282
|
+
!.codex/skills/cli/
|
|
283
|
+
!.codex/skills/cli/SKILL.md
|
|
284
|
+
!.codex/skills/mcp/
|
|
285
|
+
!.codex/skills/mcp/SKILL.md
|
|
286
|
+
!.agents/
|
|
287
|
+
.agents/*
|
|
288
|
+
!.agents/skills/
|
|
289
|
+
.agents/skills/*
|
|
290
|
+
!.agents/skills/api/
|
|
291
|
+
!.agents/skills/api/SKILL.md
|
|
292
|
+
!.agents/skills/cli/
|
|
293
|
+
!.agents/skills/cli/SKILL.md
|
|
294
|
+
!.agents/skills/mcp/
|
|
295
|
+
!.agents/skills/mcp/SKILL.md
|
|
296
|
+
!.agents/plugins/
|
|
297
|
+
!.agents/plugins/marketplace.json
|
|
298
|
+
!.claude/
|
|
299
|
+
.claude/*
|
|
300
|
+
!.claude/skills/
|
|
301
|
+
.claude/skills/*
|
|
302
|
+
!.claude/skills/api/
|
|
303
|
+
!.claude/skills/api/SKILL.md
|
|
304
|
+
!.claude/skills/cli/
|
|
305
|
+
!.claude/skills/cli/SKILL.md
|
|
306
|
+
!.claude/skills/mcp/
|
|
307
|
+
!.claude/skills/mcp/SKILL.md
|
|
308
|
+
!.github/skills/
|
|
309
|
+
.github/skills/*
|
|
310
|
+
!.github/skills/api/
|
|
311
|
+
!.github/skills/api/SKILL.md
|
|
312
|
+
!.github/skills/cli/
|
|
313
|
+
!.github/skills/cli/SKILL.md
|
|
314
|
+
!.github/skills/mcp/
|
|
315
|
+
!.github/skills/mcp/SKILL.md
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
# Astro Starlight docs site build artifacts
|
|
319
|
+
docs-site/dist/
|
|
320
|
+
docs-site/.astro/
|
|
321
|
+
|
|
322
|
+
poly.local.toml
|
|
323
|
+
|
|
324
|
+
# Alef snippet validator scratch workspaces and caches ~keep
|
|
325
|
+
**/.alef-snippet-*/
|
|
326
|
+
**/.alef-cache/
|
|
327
|
+
**/.alef/
|
|
328
|
+
|
|
329
|
+
# BEGIN ai-rulez (DO NOT EDIT - managed by ai-rulez)
|
|
330
|
+
.ai-rulez/.config.local.*
|
|
331
|
+
.opencode/agents/
|
|
332
|
+
.opencode/commands/
|
|
333
|
+
/opencode.json
|
|
334
|
+
# END ai-rulez
|
|
335
|
+
|
|
336
|
+
# Runtime log written and truncated by e2e/brew/run_tests.sh on every run.
|
|
337
|
+
mock_server.stdout
|
|
338
|
+
vendor/
|
|
339
|
+
|
|
340
|
+
!test_apps/node/pnpm-lock.yaml
|
|
341
|
+
|
|
342
|
+
# Agent harness output outside the ai-rulez managed block: the machine-local overlay,
|
|
343
|
+
# plugin-root manifests, and presets this repository does not enable.
|
|
344
|
+
.ai-rulez/config.local.*
|
|
345
|
+
.ai-rulez/local/
|
|
346
|
+
**/.ai-rulez/.generated-manifest.local.json
|
|
347
|
+
plugin/.ai-rulez/.generated-manifest.json
|
|
348
|
+
.agents/settings.json
|
|
349
|
+
.claude/settings.json
|
|
350
|
+
.claude/plugins.json
|
|
351
|
+
.codex/commands/
|
|
352
|
+
.codex/plugins.json
|
|
353
|
+
.cursor/
|
|
354
|
+
.github/commands/
|
|
355
|
+
|
|
356
|
+
!/vendor/
|
|
357
|
+
!/vendor/crawlberg-chromiumoxide-fetcher/
|
|
358
|
+
/vendor/crawlberg-chromiumoxide-fetcher/*
|
|
359
|
+
!/vendor/crawlberg-chromiumoxide-fetcher/Cargo.toml
|
|
360
|
+
!/vendor/crawlberg-chromiumoxide-fetcher/Cargo.lock
|
|
361
|
+
!/vendor/crawlberg-chromiumoxide-fetcher/LICENSE-MIT
|
|
362
|
+
!/vendor/crawlberg-chromiumoxide-fetcher/LICENSE-APACHE
|
|
363
|
+
!/vendor/crawlberg-chromiumoxide-fetcher/README.md
|
|
364
|
+
!/vendor/crawlberg-chromiumoxide-fetcher/UPSTREAM.md
|
|
365
|
+
!/vendor/crawlberg-chromiumoxide-fetcher/src/
|
|
366
|
+
!/vendor/crawlberg-chromiumoxide-fetcher/tests/
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: crawlberg-cli
|
|
3
|
+
Version: 1.13.3
|
|
4
|
+
Summary: CLI proxy for crawlberg — downloads and runs the native crawlberg binary from GitHub releases.
|
|
5
|
+
Project-URL: Homepage, https://github.com/xberg-io/crawlberg
|
|
6
|
+
Project-URL: Issues, https://github.com/xberg-io/crawlberg/issues
|
|
7
|
+
Project-URL: Repository, https://github.com/xberg-io/crawlberg.git
|
|
8
|
+
Author-email: Na'aman Hirschfeld <naaman@xberg.io>, Tobias Perlstein <tobias@xberg.io>
|
|
9
|
+
Maintainer-email: Na'aman Hirschfeld <naaman@xberg.io>, Tobias Perlstein <tobias@xberg.io>
|
|
10
|
+
License: MIT
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# crawlberg-cli
|
|
24
|
+
|
|
25
|
+
CLI proxy for [`crawlberg`](https://github.com/xberg-io/crawlberg). Installing
|
|
26
|
+
this package provides a `crawlberg` command. Platform wheels bundle the native
|
|
27
|
+
binary; the source distribution downloads the binary of the matching release
|
|
28
|
+
from GitHub and verifies it against that release's SHA256SUMS.
|
|
29
|
+
|
|
30
|
+
The package version is the crawlberg release version, so a given version of this
|
|
31
|
+
package only ever runs (or downloads) that release. Override the release tag
|
|
32
|
+
explicitly with the `CRAWLBERG_CLI_VERSION` environment variable.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# crawlberg-cli
|
|
2
|
+
|
|
3
|
+
CLI proxy for [`crawlberg`](https://github.com/xberg-io/crawlberg). Installing
|
|
4
|
+
this package provides a `crawlberg` command. Platform wheels bundle the native
|
|
5
|
+
binary; the source distribution downloads the binary of the matching release
|
|
6
|
+
from GitHub and verifies it against that release's SHA256SUMS.
|
|
7
|
+
|
|
8
|
+
The package version is the crawlberg release version, so a given version of this
|
|
9
|
+
package only ever runs (or downloads) that release. Override the release tag
|
|
10
|
+
explicitly with the `CRAWLBERG_CLI_VERSION` environment variable.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""CLI entry point for the crawlberg proxy.
|
|
2
|
+
|
|
3
|
+
A platform-specific wheel bundles the native binary under
|
|
4
|
+
``crawlberg_cli/bin/<target>/``; the sdist (and unknown platforms) ship no binary
|
|
5
|
+
and fall back to the runtime downloader. Each wheel contains exactly one ``bin/<target>``
|
|
6
|
+
directory, so the binary is located by globbing rather than by recomputing the target
|
|
7
|
+
triple (which cannot distinguish glibc from musl at runtime).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import platform
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
from .downloader import run
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _find_bundled_binary() -> str | None:
|
|
22
|
+
"""Return the path to the bundled native binary if this wheel shipped one."""
|
|
23
|
+
bin_root = Path(__file__).parent / "bin"
|
|
24
|
+
if not bin_root.is_dir():
|
|
25
|
+
return None
|
|
26
|
+
|
|
27
|
+
binary_name = "crawlberg.exe" if platform.system().lower() == "windows" else "crawlberg"
|
|
28
|
+
for candidate in bin_root.glob(f"*/{binary_name}"):
|
|
29
|
+
if candidate.is_file() and os.access(candidate, os.X_OK):
|
|
30
|
+
return str(candidate)
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def main() -> None:
|
|
35
|
+
"""Resolve the native binary (bundled or downloaded) and exec it with forwarded argv."""
|
|
36
|
+
bundled = _find_bundled_binary()
|
|
37
|
+
if bundled:
|
|
38
|
+
completed = subprocess.run([bundled, *sys.argv[1:]], check=False)
|
|
39
|
+
sys.exit(completed.returncode)
|
|
40
|
+
|
|
41
|
+
sys.exit(run(sys.argv[1:]))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
main()
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"""Resolve, download, verify, and run the native crawlberg binary.
|
|
2
|
+
|
|
3
|
+
The package is published in lockstep with the product, so it downloads exactly the
|
|
4
|
+
release whose version it carries (``CRAWLBERG_CLI_VERSION`` overrides that tag
|
|
5
|
+
explicitly; there is no "latest" fallback). Asset discovery queries that release and
|
|
6
|
+
picks the asset whose name contains the platform target triple, instead of hardcoding
|
|
7
|
+
one exact asset name. The archive is checked against the release's SHA256SUMS.
|
|
8
|
+
All diagnostics go to stderr.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import hashlib
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
import platform
|
|
17
|
+
import re
|
|
18
|
+
import shutil
|
|
19
|
+
import subprocess
|
|
20
|
+
import sys
|
|
21
|
+
import tarfile
|
|
22
|
+
import tempfile
|
|
23
|
+
import zipfile
|
|
24
|
+
from importlib.metadata import PackageNotFoundError
|
|
25
|
+
from importlib.metadata import version as installed_version
|
|
26
|
+
from pathlib import Path, PurePosixPath
|
|
27
|
+
from typing import Any
|
|
28
|
+
from urllib.error import URLError
|
|
29
|
+
from urllib.parse import quote, urlsplit
|
|
30
|
+
from urllib.request import HTTPRedirectHandler, Request, build_opener
|
|
31
|
+
|
|
32
|
+
REPO = "xberg-io/crawlberg"
|
|
33
|
+
BIN_NAME = "crawlberg"
|
|
34
|
+
PKG_NAME = "crawlberg-cli"
|
|
35
|
+
VERSION_ENV = "CRAWLBERG_CLI_VERSION"
|
|
36
|
+
_USER_AGENT = "crawlberg-cli-python-proxy"
|
|
37
|
+
|
|
38
|
+
_PEP440_RE = re.compile(r"^(?P<core>\d+\.\d+\.\d+)(?:(?P<kind>a|b|rc)(?P<number>\d+))?$")
|
|
39
|
+
_TAG_RE = re.compile(r"^v\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$")
|
|
40
|
+
_PRERELEASE_SPELLING = {"a": "alpha", "b": "beta", "rc": "rc"}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _release_tag(package_version: str, override: str | None = None) -> str:
|
|
44
|
+
"""Return the release tag for this package version, or the explicit override.
|
|
45
|
+
|
|
46
|
+
PyPI respells a semver prerelease (``1.14.0-rc.1`` becomes ``1.14.0rc1``); the GitHub
|
|
47
|
+
release tag keeps the semver spelling, so the PEP 440 form is mapped back.
|
|
48
|
+
"""
|
|
49
|
+
if override:
|
|
50
|
+
tag = override
|
|
51
|
+
else:
|
|
52
|
+
match = _PEP440_RE.match(package_version)
|
|
53
|
+
if not match:
|
|
54
|
+
raise RuntimeError(f"cannot derive a release tag from package version '{package_version}'")
|
|
55
|
+
tag = f"v{match['core']}"
|
|
56
|
+
if match["kind"]:
|
|
57
|
+
tag += f"-{_PRERELEASE_SPELLING[match['kind']]}.{match['number']}"
|
|
58
|
+
if not _TAG_RE.match(tag):
|
|
59
|
+
raise RuntimeError(f"refusing to resolve release tag '{tag}'")
|
|
60
|
+
return tag
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _package_version() -> str:
|
|
64
|
+
try:
|
|
65
|
+
return installed_version(PKG_NAME)
|
|
66
|
+
except PackageNotFoundError as exc:
|
|
67
|
+
raise RuntimeError(f"{PKG_NAME} is not installed, so its release version is unknown") from exc
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _target_triple() -> str:
|
|
71
|
+
system = platform.system().lower()
|
|
72
|
+
machine = platform.machine().lower()
|
|
73
|
+
|
|
74
|
+
if system == "windows":
|
|
75
|
+
if machine in {"amd64", "x86_64"}:
|
|
76
|
+
return "x86_64-pc-windows-msvc"
|
|
77
|
+
raise RuntimeError(f"unsupported Windows arch: {machine}")
|
|
78
|
+
if system == "linux":
|
|
79
|
+
if machine in {"amd64", "x86_64"}:
|
|
80
|
+
return "x86_64-unknown-linux-gnu"
|
|
81
|
+
if machine in {"aarch64", "arm64"}:
|
|
82
|
+
return "aarch64-unknown-linux-gnu"
|
|
83
|
+
raise RuntimeError(f"unsupported Linux arch: {machine}")
|
|
84
|
+
if system == "darwin":
|
|
85
|
+
if machine in {"aarch64", "arm64"}:
|
|
86
|
+
return "aarch64-apple-darwin"
|
|
87
|
+
if machine in {"amd64", "x86_64"}:
|
|
88
|
+
return "x86_64-apple-darwin"
|
|
89
|
+
raise RuntimeError(f"unsupported macOS arch: {machine}")
|
|
90
|
+
raise RuntimeError(f"unsupported platform: {system} {machine}")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _binary_name() -> str:
|
|
94
|
+
return f"{BIN_NAME}.exe" if platform.system().lower() == "windows" else BIN_NAME
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class _HttpsOnlyRedirectHandler(HTTPRedirectHandler):
|
|
98
|
+
"""Reject any redirect whose target is not https (downgrade/SSRF guard)."""
|
|
99
|
+
|
|
100
|
+
def redirect_request(self, req, fp, code, msg, headers, newurl): # type: ignore[no-untyped-def]
|
|
101
|
+
if urlsplit(newurl).scheme.lower() != "https":
|
|
102
|
+
raise URLError(f"refusing non-https redirect to: {newurl}")
|
|
103
|
+
return super().redirect_request(req, fp, code, msg, headers, newurl)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
_opener = build_opener(_HttpsOnlyRedirectHandler())
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _http_get(url: str, accept: str | None = None) -> bytes:
|
|
110
|
+
if urlsplit(url).scheme.lower() != "https":
|
|
111
|
+
raise RuntimeError(f"refusing non-https URL: {url}")
|
|
112
|
+
headers = {"User-Agent": _USER_AGENT}
|
|
113
|
+
if accept:
|
|
114
|
+
headers["Accept"] = accept
|
|
115
|
+
request = Request(url, headers=headers)
|
|
116
|
+
try:
|
|
117
|
+
with _opener.open(request, timeout=60) as response:
|
|
118
|
+
if response.status != 200:
|
|
119
|
+
raise RuntimeError(f"HTTP {response.status} for {url}")
|
|
120
|
+
body: bytes = response.read()
|
|
121
|
+
return body
|
|
122
|
+
except URLError as exc:
|
|
123
|
+
raise RuntimeError(f"failed to fetch {url}: {exc}") from exc
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _asset_score(name: str) -> int:
|
|
127
|
+
lowered = name.lower()
|
|
128
|
+
score = 0
|
|
129
|
+
if BIN_NAME.lower() in lowered:
|
|
130
|
+
score += 2
|
|
131
|
+
if "cli" in lowered:
|
|
132
|
+
score += 1
|
|
133
|
+
return score
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _resolve_release() -> tuple[str, dict[str, Any], dict[str, Any] | None]:
|
|
137
|
+
"""Return (tag, archive_asset, checksums_asset_or_none) for this platform."""
|
|
138
|
+
triple = _target_triple()
|
|
139
|
+
pinned = _release_tag(_package_version(), os.getenv(VERSION_ENV))
|
|
140
|
+
api_url = f"https://api.github.com/repos/{REPO}/releases/tags/{quote(pinned, safe='')}"
|
|
141
|
+
|
|
142
|
+
release = json.loads(_http_get(api_url, accept="application/vnd.github+json"))
|
|
143
|
+
assets = release.get("assets") or []
|
|
144
|
+
tag = release.get("tag_name") or pinned
|
|
145
|
+
|
|
146
|
+
archives = [
|
|
147
|
+
a
|
|
148
|
+
for a in assets
|
|
149
|
+
if triple in (a.get("name") or "").lower()
|
|
150
|
+
and ((a.get("name") or "").lower().endswith(".tar.gz") or (a.get("name") or "").lower().endswith(".zip"))
|
|
151
|
+
]
|
|
152
|
+
if not archives:
|
|
153
|
+
raise RuntimeError(f'no release asset matching target triple "{triple}" in {REPO} release {tag}')
|
|
154
|
+
archives.sort(key=lambda a: _asset_score(a.get("name") or ""), reverse=True)
|
|
155
|
+
archive = archives[0]
|
|
156
|
+
|
|
157
|
+
checksums = next((a for a in assets if "SHA256SUMS" in (a.get("name") or "").upper()), None)
|
|
158
|
+
return tag, archive, checksums
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _expected_digest(text: str, asset_name: str) -> str | None:
|
|
162
|
+
for line in text.splitlines():
|
|
163
|
+
stripped = line.strip()
|
|
164
|
+
if not stripped:
|
|
165
|
+
continue
|
|
166
|
+
parts = stripped.split()
|
|
167
|
+
if len(parts) < 2:
|
|
168
|
+
continue
|
|
169
|
+
name = parts[-1].lstrip("*")
|
|
170
|
+
if name == asset_name:
|
|
171
|
+
return parts[0].lower()
|
|
172
|
+
return None
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _verify_checksum(archive_path: Path, asset_name: str, sums_text: str, sums_name: str = "SHA256SUMS") -> None:
|
|
176
|
+
expected = _expected_digest(sums_text, asset_name)
|
|
177
|
+
if not expected:
|
|
178
|
+
raise RuntimeError(f"no checksum entry for {asset_name} in {sums_name} — refusing to install unverified binary")
|
|
179
|
+
digest = hashlib.sha256(archive_path.read_bytes()).hexdigest().lower()
|
|
180
|
+
if digest != expected:
|
|
181
|
+
raise RuntimeError(f"checksum mismatch for {asset_name} (expected {expected}, got {digest})")
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _verify_or_warn(archive_path: Path, asset_name: str, checksums: dict[str, Any] | None) -> None:
|
|
185
|
+
if not checksums:
|
|
186
|
+
print(
|
|
187
|
+
f"WARNING: no SHA256SUMS asset found for {asset_name}; "
|
|
188
|
+
"installing over HTTPS without checksum verification.",
|
|
189
|
+
file=sys.stderr,
|
|
190
|
+
)
|
|
191
|
+
return
|
|
192
|
+
sums_text = _http_get(checksums["browser_download_url"]).decode("utf-8")
|
|
193
|
+
_verify_checksum(archive_path, asset_name, sums_text, checksums["name"])
|
|
194
|
+
print(f"Checksum verified for {asset_name}.", file=sys.stderr)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _is_within(base: Path, target: Path) -> bool:
|
|
198
|
+
"""True if `target`'s resolved path stays inside `base`."""
|
|
199
|
+
base_resolved = base.resolve()
|
|
200
|
+
try:
|
|
201
|
+
target.resolve().relative_to(base_resolved)
|
|
202
|
+
except ValueError:
|
|
203
|
+
return False
|
|
204
|
+
return True
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _reject_unsafe_member(name: str) -> None:
|
|
208
|
+
"""Reject absolute paths and any `..` component (zip-slip / tar-slip)."""
|
|
209
|
+
normalized = name.replace("\\", "/")
|
|
210
|
+
pure = PurePosixPath(normalized)
|
|
211
|
+
if pure.is_absolute() or normalized.startswith("/"):
|
|
212
|
+
raise RuntimeError(f"refusing absolute path in archive: {name}")
|
|
213
|
+
if len(normalized) >= 2 and normalized[1] == ":":
|
|
214
|
+
raise RuntimeError(f"refusing absolute path in archive: {name}")
|
|
215
|
+
if any(part == ".." for part in pure.parts):
|
|
216
|
+
raise RuntimeError(f"refusing parent-directory escape in archive: {name}")
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def _safe_extract(archive_path: Path, asset_name: str, dest: Path) -> None:
|
|
220
|
+
"""Extract a tar/zip, validating every member stays within `dest`.
|
|
221
|
+
|
|
222
|
+
Does not rely on extractall() defaults or the 3.12-only ``filter='data'``:
|
|
223
|
+
each member name is rejected up front if it is absolute or contains ``..``,
|
|
224
|
+
and the resolved destination path is re-checked against ``dest``.
|
|
225
|
+
"""
|
|
226
|
+
dest = dest.resolve()
|
|
227
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
228
|
+
|
|
229
|
+
if asset_name.lower().endswith(".zip"):
|
|
230
|
+
with zipfile.ZipFile(archive_path) as zf:
|
|
231
|
+
for entry in zf.namelist():
|
|
232
|
+
_reject_unsafe_member(entry)
|
|
233
|
+
if not _is_within(dest, dest / entry):
|
|
234
|
+
raise RuntimeError(f"refusing archive entry escaping dest: {entry}")
|
|
235
|
+
for entry in zf.namelist():
|
|
236
|
+
zf.extract(entry, dest)
|
|
237
|
+
else:
|
|
238
|
+
with tarfile.open(archive_path, "r:gz") as tf:
|
|
239
|
+
for member in tf.getmembers():
|
|
240
|
+
_reject_unsafe_member(member.name)
|
|
241
|
+
if not _is_within(dest, dest / member.name):
|
|
242
|
+
raise RuntimeError(f"refusing archive entry escaping dest: {member.name}")
|
|
243
|
+
if member.islnk() or member.issym():
|
|
244
|
+
link_target = dest / member.name
|
|
245
|
+
if not _is_within(dest, link_target.parent / member.linkname):
|
|
246
|
+
raise RuntimeError(f"refusing link escaping dest: {member.name}")
|
|
247
|
+
tf.extractall(dest) # noqa: S202 (members validated above)
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def _find_binary(root: Path, name: str) -> Path | None:
|
|
251
|
+
for candidate in root.rglob(name):
|
|
252
|
+
if candidate.is_file():
|
|
253
|
+
return candidate
|
|
254
|
+
return None
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def _cache_dir(tag: str) -> Path:
|
|
258
|
+
cache = Path.home() / ".cache" / PKG_NAME / tag
|
|
259
|
+
cache.mkdir(parents=True, exist_ok=True, mode=0o700)
|
|
260
|
+
return cache
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def ensure_binary() -> str:
|
|
264
|
+
"""Ensure the native binary exists locally, downloading if necessary."""
|
|
265
|
+
override = os.getenv("CRAWLBERG_BINARY")
|
|
266
|
+
if override:
|
|
267
|
+
return override
|
|
268
|
+
|
|
269
|
+
tag, archive, checksums = _resolve_release()
|
|
270
|
+
cache = _cache_dir(tag)
|
|
271
|
+
binary_path = cache / _binary_name()
|
|
272
|
+
if binary_path.exists() and os.access(binary_path, os.X_OK):
|
|
273
|
+
return str(binary_path)
|
|
274
|
+
|
|
275
|
+
print(f"Downloading {BIN_NAME} {tag} asset {archive['name']}...", file=sys.stderr)
|
|
276
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
277
|
+
tmp = Path(tmpdir)
|
|
278
|
+
archive_path = tmp / Path(archive["name"]).name
|
|
279
|
+
archive_path.write_bytes(_http_get(archive["browser_download_url"]))
|
|
280
|
+
_verify_or_warn(archive_path, archive["name"], checksums)
|
|
281
|
+
extract_dir = tmp / "extract"
|
|
282
|
+
extract_dir.mkdir()
|
|
283
|
+
_safe_extract(archive_path, archive["name"], extract_dir)
|
|
284
|
+
found = _find_binary(extract_dir, _binary_name())
|
|
285
|
+
if not found:
|
|
286
|
+
raise RuntimeError(f"binary {_binary_name()} not found after extracting {archive['name']}")
|
|
287
|
+
shutil.move(str(found), str(binary_path))
|
|
288
|
+
|
|
289
|
+
if platform.system().lower() != "windows":
|
|
290
|
+
binary_path.chmod(0o755)
|
|
291
|
+
print(f"{BIN_NAME} installed.", file=sys.stderr)
|
|
292
|
+
return str(binary_path)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def run(args: list[str]) -> int:
|
|
296
|
+
"""Run the native binary with the given args, returning its exit code."""
|
|
297
|
+
binary_path = ensure_binary()
|
|
298
|
+
completed = subprocess.run([binary_path, *args], check=False)
|
|
299
|
+
return completed.returncode
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""Custom hatchling build hook that bundles the native crawlberg binary into a wheel.
|
|
2
|
+
|
|
3
|
+
When building a platform-specific wheel in CI, the target triple is supplied via
|
|
4
|
+
the ``CRAWLBERG_CLI_TARGET`` env var (the build host is always linux/amd64, so the
|
|
5
|
+
triple cannot be inferred from ``platform.*``). The matching
|
|
6
|
+
``crawlberg-cli-<target>.tar.gz`` / ``.zip`` is located (repo root or ``dist/``),
|
|
7
|
+
the binary is extracted into ``crawlberg_cli/bin/<target>/``, force-included in the
|
|
8
|
+
wheel, and the wheel is tagged for that platform so PyPI serves the right artifact.
|
|
9
|
+
|
|
10
|
+
If no target is set (e.g. the sdist build), the hook is a no-op and the package falls
|
|
11
|
+
back to the runtime downloader in ``crawlberg_cli/downloader.py`` (see ``cli.py``).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import os
|
|
17
|
+
import shutil
|
|
18
|
+
import tarfile
|
|
19
|
+
import zipfile
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
|
23
|
+
|
|
24
|
+
_TAG_MAP = {
|
|
25
|
+
"x86_64-pc-windows-msvc": "win_amd64",
|
|
26
|
+
"x86_64-unknown-linux-gnu": "manylinux_2_28_x86_64",
|
|
27
|
+
"aarch64-unknown-linux-gnu": "manylinux_2_28_aarch64",
|
|
28
|
+
"x86_64-unknown-linux-musl": "musllinux_1_2_x86_64",
|
|
29
|
+
"aarch64-unknown-linux-musl": "musllinux_1_2_aarch64",
|
|
30
|
+
"aarch64-apple-darwin": "macosx_15_0_arm64",
|
|
31
|
+
"x86_64-apple-darwin": "macosx_15_0_x86_64",
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _safe_destination(root: Path, member_name: str) -> Path:
|
|
36
|
+
"""Resolve an archive member path and require it to stay under root."""
|
|
37
|
+
root = root.resolve()
|
|
38
|
+
target = (root / member_name.replace("\\", "/")).resolve(strict=False)
|
|
39
|
+
if target != root and not target.is_relative_to(root):
|
|
40
|
+
raise RuntimeError(f"archive member escapes extraction directory: {member_name}")
|
|
41
|
+
return target
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _extract_zip_bounded(archive: Path, extract_dir: Path) -> None:
|
|
45
|
+
"""Extract zip entries after bounding each destination path."""
|
|
46
|
+
with zipfile.ZipFile(archive) as zf:
|
|
47
|
+
for member in zf.infolist():
|
|
48
|
+
target = _safe_destination(extract_dir, member.filename)
|
|
49
|
+
if member.is_dir():
|
|
50
|
+
target.mkdir(parents=True, exist_ok=True)
|
|
51
|
+
continue
|
|
52
|
+
|
|
53
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
54
|
+
with zf.open(member) as source, target.open("wb") as destination:
|
|
55
|
+
shutil.copyfileobj(source, destination)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _extract_tar_bounded(archive: Path, extract_dir: Path) -> None:
|
|
59
|
+
"""Extract regular tar entries after bounding each destination path."""
|
|
60
|
+
with tarfile.open(archive, "r:gz") as tf:
|
|
61
|
+
for member in tf.getmembers():
|
|
62
|
+
target = _safe_destination(extract_dir, member.name)
|
|
63
|
+
if member.isdir():
|
|
64
|
+
target.mkdir(parents=True, exist_ok=True)
|
|
65
|
+
continue
|
|
66
|
+
if not member.isfile():
|
|
67
|
+
raise RuntimeError(f"unsupported archive member type: {member.name}")
|
|
68
|
+
|
|
69
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
70
|
+
source = tf.extractfile(member)
|
|
71
|
+
if source is None:
|
|
72
|
+
raise RuntimeError(f"could not read archive member: {member.name}")
|
|
73
|
+
with source, target.open("wb") as destination:
|
|
74
|
+
shutil.copyfileobj(source, destination)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class CustomBuildHook(BuildHookInterface):
|
|
78
|
+
"""Inject the matching native binary into a platform-tagged wheel."""
|
|
79
|
+
|
|
80
|
+
PLUGIN_NAME = "custom"
|
|
81
|
+
|
|
82
|
+
def initialize(self, version: str, build_data: dict) -> None: # noqa: ARG002
|
|
83
|
+
"""Bundle a staged native binary when building a targeted wheel."""
|
|
84
|
+
target = os.environ.get("CRAWLBERG_CLI_TARGET", "").strip()
|
|
85
|
+
if not target:
|
|
86
|
+
return
|
|
87
|
+
|
|
88
|
+
archive = self._find_archive(target)
|
|
89
|
+
if archive is None:
|
|
90
|
+
raise RuntimeError(
|
|
91
|
+
f"CRAWLBERG_CLI_TARGET={target} but no crawlberg-cli-{target}.(tar.gz|zip) "
|
|
92
|
+
f"found in repo root or dist/; refusing to build an empty platform wheel."
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
wheel_tag = _TAG_MAP.get(target)
|
|
96
|
+
if wheel_tag is None:
|
|
97
|
+
raise RuntimeError(f"no wheel platform tag mapped for target {target}")
|
|
98
|
+
|
|
99
|
+
binary = self._extract_binary(archive, target)
|
|
100
|
+
|
|
101
|
+
relative = f"crawlberg_cli/bin/{target}/{binary.name}"
|
|
102
|
+
force_include = build_data.setdefault("force_include", {})
|
|
103
|
+
force_include[str(binary)] = relative
|
|
104
|
+
|
|
105
|
+
self._include_staged_payload(force_include, binary, target)
|
|
106
|
+
|
|
107
|
+
build_data["pure_python"] = False
|
|
108
|
+
build_data["infer_tag"] = False
|
|
109
|
+
build_data["tag"] = f"py3-none-{wheel_tag}"
|
|
110
|
+
|
|
111
|
+
def _include_staged_payload(self, force_include: dict[str, str], binary: Path, target: str) -> None:
|
|
112
|
+
"""Force-include every file the release archive staged beside the binary.
|
|
113
|
+
|
|
114
|
+
Copying the staged tree wholesale, rather than only the binary, is what stops a
|
|
115
|
+
library or support file that a release archive starts shipping from being
|
|
116
|
+
dropped from the wheel without anyone noticing.
|
|
117
|
+
"""
|
|
118
|
+
stage_dir = binary.parent
|
|
119
|
+
for path in sorted(stage_dir.rglob("*")):
|
|
120
|
+
if not path.is_file() or path == binary:
|
|
121
|
+
continue
|
|
122
|
+
relative_path = path.relative_to(stage_dir).as_posix()
|
|
123
|
+
force_include[str(path)] = f"crawlberg_cli/bin/{target}/{relative_path}"
|
|
124
|
+
|
|
125
|
+
def _find_archive(self, target: str) -> Path | None:
|
|
126
|
+
root = Path(self.root)
|
|
127
|
+
repo_root = root.parent.parent
|
|
128
|
+
for base in (repo_root, repo_root / "dist", root, root / "dist"):
|
|
129
|
+
for ext in ("tar.gz", "zip"):
|
|
130
|
+
candidate = base / f"crawlberg-cli-{target}.{ext}"
|
|
131
|
+
if candidate.is_file():
|
|
132
|
+
return candidate
|
|
133
|
+
return None
|
|
134
|
+
|
|
135
|
+
def _extract_binary(self, archive: Path, target: str) -> Path:
|
|
136
|
+
is_windows = target.endswith("windows-msvc")
|
|
137
|
+
binary_name = "crawlberg.exe" if is_windows else "crawlberg"
|
|
138
|
+
extract_dir = Path(self.root) / ".build-extract" / target
|
|
139
|
+
if extract_dir.exists():
|
|
140
|
+
shutil.rmtree(extract_dir, ignore_errors=True)
|
|
141
|
+
extract_dir.mkdir(parents=True, exist_ok=True)
|
|
142
|
+
|
|
143
|
+
if str(archive).lower().endswith(".zip"):
|
|
144
|
+
_extract_zip_bounded(archive, extract_dir)
|
|
145
|
+
else:
|
|
146
|
+
_extract_tar_bounded(archive, extract_dir)
|
|
147
|
+
|
|
148
|
+
for candidate in extract_dir.rglob(binary_name):
|
|
149
|
+
if candidate.is_file():
|
|
150
|
+
candidate.chmod(0o755)
|
|
151
|
+
return candidate
|
|
152
|
+
raise RuntimeError(f"binary {binary_name} not found inside {archive.name}")
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
build-backend = "hatchling.build"
|
|
3
|
+
requires = ["hatchling"]
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
maintainers = [
|
|
7
|
+
{ name = "Na'aman Hirschfeld", email = "naaman@xberg.io" },
|
|
8
|
+
{ name = "Tobias Perlstein", email = "tobias@xberg.io" },
|
|
9
|
+
]
|
|
10
|
+
name = "crawlberg-cli"
|
|
11
|
+
version = "1.13.3"
|
|
12
|
+
description = "CLI proxy for crawlberg — downloads and runs the native crawlberg binary from GitHub releases."
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
license = { text = "MIT" }
|
|
15
|
+
authors = [
|
|
16
|
+
{ name = "Na'aman Hirschfeld", email = "naaman@xberg.io" },
|
|
17
|
+
{ name = "Tobias Perlstein", email = "tobias@xberg.io" },
|
|
18
|
+
]
|
|
19
|
+
requires-python = ">=3.11"
|
|
20
|
+
classifiers = [
|
|
21
|
+
"Development Status :: 4 - Beta",
|
|
22
|
+
"Environment :: Console",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
"License :: OSI Approved :: MIT License",
|
|
25
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Programming Language :: Python :: 3.12",
|
|
28
|
+
"Programming Language :: Python :: 3.13",
|
|
29
|
+
"Programming Language :: Python :: 3.14",
|
|
30
|
+
]
|
|
31
|
+
urls.Homepage = "https://github.com/xberg-io/crawlberg"
|
|
32
|
+
urls.Issues = "https://github.com/xberg-io/crawlberg/issues"
|
|
33
|
+
urls.Repository = "https://github.com/xberg-io/crawlberg.git"
|
|
34
|
+
scripts.crawlberg = "crawlberg_cli.cli:main"
|
|
35
|
+
|
|
36
|
+
[tool.hatch]
|
|
37
|
+
build.hooks.custom.path = "hatch_build.py"
|
|
38
|
+
build.targets.wheel.packages = ["crawlberg_cli"]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Make the build hook and the package importable from the tests directory.
|
|
2
|
+
|
|
3
|
+
``hatch_build.py`` sits at the package root because hatchling loads it by path
|
|
4
|
+
rather than as an installed module, so it is not importable from ``tests/``
|
|
5
|
+
without help.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import sys
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Tests for the release pinning and checksum verification of the runtime downloader."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
from crawlberg_cli import downloader
|
|
10
|
+
|
|
11
|
+
_ARCHIVE_NAME = "crawlberg-cli-aarch64-apple-darwin.tar.gz"
|
|
12
|
+
_PAYLOAD = b"archive bytes"
|
|
13
|
+
_DIGEST = hashlib.sha256(_PAYLOAD).hexdigest()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@pytest.mark.parametrize(
|
|
17
|
+
("package_version", "tag"),
|
|
18
|
+
[
|
|
19
|
+
("1.13.1", "v1.13.1"),
|
|
20
|
+
("1.14.0rc1", "v1.14.0-rc.1"),
|
|
21
|
+
("1.14.0a2", "v1.14.0-alpha.2"),
|
|
22
|
+
("1.14.0b3", "v1.14.0-beta.3"),
|
|
23
|
+
],
|
|
24
|
+
)
|
|
25
|
+
def test_should_derive_the_release_tag_from_the_package_version(package_version: str, tag: str) -> None:
|
|
26
|
+
assert downloader._release_tag(package_version) == tag
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_should_prefer_an_explicit_override_over_the_package_version() -> None:
|
|
30
|
+
assert downloader._release_tag("1.13.1", "v1.12.0") == "v1.12.0"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.mark.parametrize("override", ["latest", "1.12.0", "v1.12", "../v1.0.0"])
|
|
34
|
+
def test_should_reject_a_malformed_override(override: str) -> None:
|
|
35
|
+
with pytest.raises(RuntimeError, match="refusing to resolve release tag"):
|
|
36
|
+
downloader._release_tag("1.13.1", override)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_should_reject_a_version_it_cannot_map_to_a_tag() -> None:
|
|
40
|
+
with pytest.raises(RuntimeError, match="cannot derive a release tag"):
|
|
41
|
+
downloader._release_tag("1.13.1.dev4")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_should_resolve_exactly_the_release_of_the_installed_version(monkeypatch) -> None:
|
|
45
|
+
requested: list[str] = []
|
|
46
|
+
|
|
47
|
+
def fake_get(url: str, accept: str | None = None) -> bytes:
|
|
48
|
+
requested.append(url)
|
|
49
|
+
return b'{"tag_name": "v1.13.1", "assets": [{"name": "crawlberg-cli-aarch64-apple-darwin.tar.gz"}]}'
|
|
50
|
+
|
|
51
|
+
monkeypatch.setattr(downloader, "_http_get", fake_get)
|
|
52
|
+
monkeypatch.setattr(downloader, "_package_version", lambda: "1.13.1")
|
|
53
|
+
monkeypatch.setattr(downloader, "_target_triple", lambda: "aarch64-apple-darwin")
|
|
54
|
+
monkeypatch.delenv(downloader.VERSION_ENV, raising=False)
|
|
55
|
+
|
|
56
|
+
tag, archive, _ = downloader._resolve_release()
|
|
57
|
+
|
|
58
|
+
assert requested == ["https://api.github.com/repos/xberg-io/crawlberg/releases/tags/v1.13.1"]
|
|
59
|
+
assert tag == "v1.13.1"
|
|
60
|
+
assert archive["name"] == _ARCHIVE_NAME
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_should_accept_a_matching_checksum(tmp_path: Path) -> None:
|
|
64
|
+
archive = tmp_path / _ARCHIVE_NAME
|
|
65
|
+
archive.write_bytes(_PAYLOAD)
|
|
66
|
+
downloader._verify_checksum(archive, _ARCHIVE_NAME, f"{_DIGEST} {_ARCHIVE_NAME}\n")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_should_reject_a_tampered_archive(tmp_path: Path) -> None:
|
|
70
|
+
archive = tmp_path / _ARCHIVE_NAME
|
|
71
|
+
archive.write_bytes(b"tampered")
|
|
72
|
+
with pytest.raises(RuntimeError, match="checksum mismatch"):
|
|
73
|
+
downloader._verify_checksum(archive, _ARCHIVE_NAME, f"{_DIGEST} {_ARCHIVE_NAME}\n")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def test_should_refuse_an_archive_with_no_checksum_entry(tmp_path: Path) -> None:
|
|
77
|
+
archive = tmp_path / _ARCHIVE_NAME
|
|
78
|
+
archive.write_bytes(_PAYLOAD)
|
|
79
|
+
with pytest.raises(RuntimeError, match="no checksum entry"):
|
|
80
|
+
downloader._verify_checksum(archive, _ARCHIVE_NAME, f"{_DIGEST} other.tar.gz\n")
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""Tests for the wheel build hook that repackages the released CLI archives."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import io
|
|
6
|
+
import tarfile
|
|
7
|
+
import zipfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
from hatch_build import CustomBuildHook
|
|
12
|
+
|
|
13
|
+
_GNU_TARGET = "x86_64-unknown-linux-gnu"
|
|
14
|
+
_MUSL_TARGET = "aarch64-unknown-linux-musl"
|
|
15
|
+
_WINDOWS_TARGET = "x86_64-pc-windows-msvc"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _hook(root: Path) -> CustomBuildHook:
|
|
19
|
+
return CustomBuildHook(
|
|
20
|
+
str(root),
|
|
21
|
+
config={},
|
|
22
|
+
build_config={},
|
|
23
|
+
metadata=None,
|
|
24
|
+
directory=str(root / "dist"),
|
|
25
|
+
target_name="wheel",
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _write_tar(root: Path, target: str, members: dict[str, bytes]) -> None:
|
|
30
|
+
dist = root / "dist"
|
|
31
|
+
dist.mkdir(parents=True, exist_ok=True)
|
|
32
|
+
with tarfile.open(dist / f"crawlberg-cli-{target}.tar.gz", "w:gz") as archive:
|
|
33
|
+
for name, payload in members.items():
|
|
34
|
+
info = tarfile.TarInfo(name)
|
|
35
|
+
info.size = len(payload)
|
|
36
|
+
archive.addfile(info, io.BytesIO(payload))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _build(root: Path, target: str, monkeypatch) -> dict:
|
|
40
|
+
monkeypatch.setenv("CRAWLBERG_CLI_TARGET", target)
|
|
41
|
+
build_data: dict = {}
|
|
42
|
+
_hook(root).initialize("1.0.0", build_data)
|
|
43
|
+
return build_data
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_should_do_nothing_without_a_target(tmp_path: Path, monkeypatch) -> None:
|
|
47
|
+
monkeypatch.delenv("CRAWLBERG_CLI_TARGET", raising=False)
|
|
48
|
+
build_data: dict = {}
|
|
49
|
+
_hook(tmp_path).initialize("1.0.0", build_data)
|
|
50
|
+
assert build_data == {}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_should_bundle_the_binary_and_tag_the_wheel_for_the_platform(tmp_path: Path, monkeypatch) -> None:
|
|
54
|
+
_write_tar(tmp_path, _GNU_TARGET, {f"crawlberg-cli-{_GNU_TARGET}/crawlberg": b"\x7fELF"})
|
|
55
|
+
|
|
56
|
+
build_data = _build(tmp_path, _GNU_TARGET, monkeypatch)
|
|
57
|
+
|
|
58
|
+
assert set(build_data["force_include"].values()) == {f"crawlberg_cli/bin/{_GNU_TARGET}/crawlberg"}
|
|
59
|
+
assert build_data["tag"] == "py3-none-manylinux_2_28_x86_64"
|
|
60
|
+
assert build_data["pure_python"] is False
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_should_preserve_the_relative_paths_of_the_staged_payload(tmp_path: Path, monkeypatch) -> None:
|
|
64
|
+
stage = f"crawlberg-cli-{_MUSL_TARGET}"
|
|
65
|
+
_write_tar(
|
|
66
|
+
tmp_path,
|
|
67
|
+
_MUSL_TARGET,
|
|
68
|
+
{f"{stage}/crawlberg": b"\x7fELF", f"{stage}/lib/libextra.so": b"lib", f"{stage}/LICENSE": b"mit"},
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
build_data = _build(tmp_path, _MUSL_TARGET, monkeypatch)
|
|
72
|
+
|
|
73
|
+
assert set(build_data["force_include"].values()) == {
|
|
74
|
+
f"crawlberg_cli/bin/{_MUSL_TARGET}/crawlberg",
|
|
75
|
+
f"crawlberg_cli/bin/{_MUSL_TARGET}/lib/libextra.so",
|
|
76
|
+
f"crawlberg_cli/bin/{_MUSL_TARGET}/LICENSE",
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_should_bundle_the_windows_exe_from_a_zip(tmp_path: Path, monkeypatch) -> None:
|
|
81
|
+
dist = tmp_path / "dist"
|
|
82
|
+
dist.mkdir()
|
|
83
|
+
with zipfile.ZipFile(dist / f"crawlberg-cli-{_WINDOWS_TARGET}.zip", "w") as archive:
|
|
84
|
+
archive.writestr(f"crawlberg-cli-{_WINDOWS_TARGET}/crawlberg.exe", b"MZ")
|
|
85
|
+
|
|
86
|
+
build_data = _build(tmp_path, _WINDOWS_TARGET, monkeypatch)
|
|
87
|
+
|
|
88
|
+
assert set(build_data["force_include"].values()) == {f"crawlberg_cli/bin/{_WINDOWS_TARGET}/crawlberg.exe"}
|
|
89
|
+
assert build_data["tag"] == "py3-none-win_amd64"
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_should_refuse_to_build_an_empty_platform_wheel(tmp_path: Path, monkeypatch) -> None:
|
|
93
|
+
with pytest.raises(RuntimeError, match="refusing to build an empty platform wheel"):
|
|
94
|
+
_build(tmp_path, _GNU_TARGET, monkeypatch)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_should_reject_an_archive_member_that_escapes_the_extraction_directory(tmp_path: Path, monkeypatch) -> None:
|
|
98
|
+
_write_tar(tmp_path, _GNU_TARGET, {"../escape": b"x", "crawlberg": b"\x7fELF"})
|
|
99
|
+
with pytest.raises(RuntimeError, match="escapes extraction directory"):
|
|
100
|
+
_build(tmp_path, _GNU_TARGET, monkeypatch)
|