hansu 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 (39) hide show
  1. hansu-0.3.0/.github/workflows/ci.yml +18 -0
  2. hansu-0.3.0/.github/workflows/publish.yml +20 -0
  3. hansu-0.3.0/CONTRIBUTING.md +71 -0
  4. hansu-0.3.0/LICENSE +21 -0
  5. hansu-0.3.0/MANIFEST.in +6 -0
  6. hansu-0.3.0/PKG-INFO +279 -0
  7. hansu-0.3.0/PUBLISHING.md +59 -0
  8. hansu-0.3.0/README.md +257 -0
  9. hansu-0.3.0/README.zh-CN.md +152 -0
  10. hansu-0.3.0/benchmarks/bench.py +30 -0
  11. hansu-0.3.0/benchmarks/compare_all.py +77 -0
  12. hansu-0.3.0/benchmarks/make_set.py +208 -0
  13. hansu-0.3.0/docs/COMPARISON.md +107 -0
  14. hansu-0.3.0/docs/HS2-format.md +316 -0
  15. hansu-0.3.0/examples/demo.py +23 -0
  16. hansu-0.3.0/hansu/__init__.py +18 -0
  17. hansu-0.3.0/hansu/_arith.py +152 -0
  18. hansu-0.3.0/hansu/_backend.py +16 -0
  19. hansu-0.3.0/hansu/_fast.py +41 -0
  20. hansu-0.3.0/hansu/_hs_ac.c +228 -0
  21. hansu-0.3.0/hansu/_yco.py +12 -0
  22. hansu-0.3.0/hansu/build_c.py +20 -0
  23. hansu-0.3.0/hansu/cli.py +102 -0
  24. hansu-0.3.0/hansu/codec.py +339 -0
  25. hansu-0.3.0/hansu/idx2d.py +130 -0
  26. hansu-0.3.0/hansu/index.py +27 -0
  27. hansu-0.3.0/hansu/palette.py +29 -0
  28. hansu-0.3.0/hansu/standalone.py +268 -0
  29. hansu-0.3.0/hansu/tilepal.py +121 -0
  30. hansu-0.3.0/hansu/topology.py +73 -0
  31. hansu-0.3.0/hansu.egg-info/PKG-INFO +279 -0
  32. hansu-0.3.0/hansu.egg-info/SOURCES.txt +37 -0
  33. hansu-0.3.0/hansu.egg-info/dependency_links.txt +1 -0
  34. hansu-0.3.0/hansu.egg-info/entry_points.txt +2 -0
  35. hansu-0.3.0/hansu.egg-info/requires.txt +5 -0
  36. hansu-0.3.0/hansu.egg-info/top_level.txt +1 -0
  37. hansu-0.3.0/pyproject.toml +39 -0
  38. hansu-0.3.0/setup.cfg +4 -0
  39. hansu-0.3.0/tests/test_hansu.py +217 -0
@@ -0,0 +1,18 @@
1
+ name: ci
2
+ on: [push, pull_request]
3
+
4
+ jobs:
5
+ test:
6
+ runs-on: ubuntu-22.04 # 24.04/26.04 images no longer ship a 3.9 manifest entry
7
+ strategy:
8
+ matrix:
9
+ python-version: ["3.9", "3.11", "3.12"]
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: actions/setup-python@v5
13
+ with:
14
+ python-version: ${{ matrix.python-version }}
15
+ - run: pip install -e ".[test]"
16
+ - run: python -m hansu.build_c
17
+ - run: pytest -q -m "not slow"
18
+ - run: pytest -q -m slow
@@ -0,0 +1,20 @@
1
+ name: publish
2
+ on:
3
+ release:
4
+ types: [published]
5
+ workflow_dispatch: # 允许手动触发一次(首发用,之后靠 tag/Release)
6
+ jobs:
7
+ pypi:
8
+ runs-on: ubuntu-22.04
9
+ environment: pypi # 必须与 PyPI 上登记的 environment 一致
10
+ permissions:
11
+ id-token: write # OIDC token for PyPI trusted publishing
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: actions/setup-python@v5
15
+ with:
16
+ python-version: "3.12"
17
+ - run: pip install build && python -m build
18
+ - uses: pypa/gh-action-pypi-publish@release/v1
19
+ with:
20
+ print-hash: true
@@ -0,0 +1,71 @@
1
+ # Contributing
2
+
3
+ ## Setup
4
+
5
+ ```bash
6
+ git clone https://github.com/<owner>/hansu.git
7
+ cd hansu
8
+ pip install -e ".[test]"
9
+ python -m hansu.build_c # optional but recommended
10
+ pytest -q # 26 tests, ~12 s with the C backend
11
+ ```
12
+
13
+ ## What is worth changing
14
+
15
+ In rough order of value:
16
+
17
+ 1. **A real third-party decoder.** The strongest contribution this project can
18
+ receive. Implement HS2 v3 in Rust/C/Go from `docs/HS2-format.md` alone and
19
+ add it to a `third_party/` directory with a conformance run against the
20
+ streams `tests/` produces. If two independent implementations agree, the
21
+ format is real.
22
+ 2. **Entropy model improvements on anti-aliased content.** Currently the
23
+ clearest loss against WebP lossless (2× on text). The index plane uses a
24
+ single linear MED context; a 2-D neighbourhood context is untried.
25
+ 3. **Band selection by content.** `encode_auto` splits at 1024² unconditionally,
26
+ which costs 20 B×8 on very low-entropy images. A size-aware decision would fix
27
+ a known regression.
28
+ 4. **Other bindings** (wasm, C API) so the codec can be used outside Python.
29
+
30
+ ## Rules for format changes
31
+
32
+ The format has a version byte for a reason.
33
+
34
+ - Adding a route: new `mode` value, bump `VER`, update `docs/HS2-format.md`,
35
+ update **both** `codec.py` and `standalone.py`, add a test that decodes a
36
+ stream produced by the *old* version if you claim compatibility.
37
+ - Never change the arithmetic coder or context layout without bumping `VER`.
38
+ Old streams must remain decodable by a decoder that branches on `VER`.
39
+ - Every new route needs: a round-trip test, a cross-check against
40
+ `standalone.py`, and a line in the benchmark table.
41
+
42
+ ## Code expectations
43
+
44
+ - The pure-Python path (`_arith.py`) is normative. If you change coding logic,
45
+ change it there first, then mirror it in `_hs_ac.c`, then assert both produce
46
+ identical bytes (`pytest -m slow`).
47
+ - No new dependencies beyond numpy and Pillow in the core package.
48
+ - Keep `hansu/` under ~1 500 lines total. This is a small codec, not a framework.
49
+
50
+ ## Benchmark claims
51
+
52
+ Any PR that says "smaller" must include the before/after row from
53
+
54
+ ```bash
55
+ python benchmarks/make_set.py
56
+ python benchmarks/bench.py benchmarks/set/set256
57
+ ```
58
+
59
+ Regenerating the set is deterministic; numbers must match to the byte.
60
+
61
+ ## PR checklist
62
+
63
+ - [ ] `pytest -q` passes
64
+ - [ ] `pytest -q -m slow` passes (requires the C backend)
65
+ - [ ] `python -m hansu.cli info` prints the expected backend
66
+ - [ ] If the format changed: `docs/HS2-format.md` updated, `VER` bumped
67
+ - [ ] If size changed: benchmark table row included
68
+
69
+ ## Licence
70
+
71
+ Contributions are accepted under MIT.
hansu-0.3.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zhi & Heng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ include README.md README.zh-CN.md LICENSE CONTRIBUTING.md PUBLISHING.md
2
+ recursive-include docs *.md
3
+ recursive-include tests *.py
4
+ recursive-include benchmarks *.py
5
+ recursive-include examples *.py
6
+ recursive-include .github *.yml
hansu-0.3.0/PKG-INFO ADDED
@@ -0,0 +1,279 @@
1
+ Metadata-Version: 2.4
2
+ Name: hansu
3
+ Version: 0.3.0
4
+ Summary: A structural image codec (HS2) with topology signatures and an image-similarity index
5
+ Author: Zhi & Heng
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/antlee160429-collab/hansu
8
+ Keywords: image,compression,codec,arithmetic-coding,palette,topology
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: numpy>=1.21
18
+ Requires-Dist: pillow>=9.0
19
+ Provides-Extra: test
20
+ Requires-Dist: pytest>=7.0; extra == "test"
21
+ Dynamic: license-file
22
+
23
+ # hansu
24
+
25
+ ![ci](https://github.com/antlee160429-collab/hansu/actions/workflows/ci.yml/badge.svg)
26
+
27
+ > **Verify it, don't trust it.** [`docs/HS2-format.md`](docs/HS2-format.md) is a
28
+ > complete bitstream specification — enough that a third party can implement a
29
+ > decoder without reading this code. `hansu/standalone.py` *is* that third
30
+ > party: written from the document alone, and CI asserts the two decoders agree
31
+ > pixel for pixel on every test image.
32
+
33
+ **A structural image codec — small files on graphics, screenshots and flat UI, plus a topology signature that other systems can query.**
34
+
35
+ Thirty-second check:
36
+
37
+ ```bash
38
+ pip install hansu
39
+ python -c "import hansu,numpy as np; d,r=hansu.encode(np.zeros((64,64,3),np.uint8)); print(len(d),'bytes for a blank 64x64 RGB')"
40
+ ```
41
+ — small files on graphics, screenshots and flat UI, plus a topology signature that other systems can query.**
42
+
43
+ `hansu` (珩速) is an HS2 codec: MED-style prediction with a 250-context binary
44
+ arithmetic coder, a palette route for few-colour images, banded streams for
45
+ parallel / random-access decoding, and an RGBA path. It ships with a second,
46
+ independently written decoder so the format can be verified rather than trusted.
47
+
48
+ Two things make it more than another compressor:
49
+
50
+ - **The bitstream is specified.** [`docs/HS2-format.md`](docs/HS2-format.md) is
51
+ written to the level where a third party can implement a decoder without
52
+ reading this code. `hansu/standalone.py` is exactly that: written from the
53
+ document alone, and the test suite asserts the two agree pixel for pixel.
54
+ - **Images have signatures.** `hansu.signature(img)` returns a JSON description
55
+ of the image's *structure* — colour count, flatness, edge density, dominant
56
+ periods, entropy, family — plus the codec's own result. Signatures are
57
+ comparable, so you can build a library and search it by topology instead of
58
+ by content hash.
59
+
60
+ ## Where it wins
61
+
62
+ Against WebP **lossless**, on 256×256 synthetic graphics (10 images):
63
+
64
+ | image | hansu | WebP-LL | ratio |
65
+ |---|---:|---:|---:|
66
+ | blocks5 | 65 B | 114 B | **0.57×** |
67
+ | icon | 370 B | 466 B | **0.79×** |
68
+ | blocks2 | 51 B | 60 B | **0.85×** |
69
+ | chart | 104 B | 120 B | **0.87×** |
70
+ | circles | 645 B | 726 B | **0.89×** |
71
+ | checker8 | 128 B | 142 B | **0.90×** |
72
+ | gradstep | 98 B | 106 B | **0.92×** |
73
+ | ui | 238 B | 240 B | 0.99× |
74
+ | stripes4 | 86 B | 82 B | 1.05× |
75
+ | noise16 | 116 761 B | 98 394 B | 1.19× |
76
+
77
+ Nine of ten beat WebP lossless; at 512² and 1024² graphics the margin grows
78
+ (2.2×–3.0× on 5-colour blocks vs PNG).
79
+
80
+ † `noise16` is the one entry that does **not** hold up. The 0.84× figure that
81
+ appeared in earlier versions compared a very low-quality hansu setting
82
+ (PSNR 9.4) against lossless WebP — not an equal-quality comparison. At the
83
+ default setting (PSNR 33.49) it is 1.19×, i.e. larger. Noise is the case this
84
+ codec is worst at, and the table now says so.
85
+
86
+ **A correction on the lossy comparison.** An earlier version of this README
87
+ reported "2.4×–8× smaller than WebP q35". That compared hansu at q16 (≈36 dB)
88
+ against WebP at q35 (≈30 dB) — different quality, so the number was wrong. At
89
+ matched PSNR WebP is ahead on every page-type image. See
90
+ [`docs/COMPARISON.md`](docs/COMPARISON.md) for the corrected study.
91
+
92
+ On 512×512 near-real pages (generated by `benchmarks/make_set.py`):
93
+
94
+ | page | hansu q16 | PSNR | WebP-LL | WebP q35 | ratio to LL* | ratio to q35* |
95
+ |---|---:|---:|---:|---:|---:|---:|
96
+ | shot_ui | 10 296 B | 36.93 | 11 042 B | 7 712 B | **0.93×** | 1.34× |
97
+ | shot_icons | 1 733 B | 99.00 | 1 686 B | 3 908 B | **1.03×** | **0.44×** |
98
+ | shot_text | 29 470 B | 43.99 | 15 056 B | 35 442 B | 1.96× | **0.83×** |
99
+ | shot_chart | 1 658 B | 41.74 | 1 354 B | 2 148 B | 1.22× | **0.77×** |
100
+ | shot_grad | 5 665 B | 34.81 | 5 292 B | 3 538 B | 1.07× | 1.60× |
101
+ | shot_photo | 159 264 B | 34.28 | 443 376 B | 9 302 B | **0.36×** | 17.12× |
102
+
103
+ Reading it: on pages made of flat blocks and sharp edges it holds up against
104
+ lossless WebP and wins against q35; on anti-aliased text and photographs it
105
+ loses, exactly as the boundaries below say.
106
+
107
+ ### An independent check on real images
108
+
109
+ The two tables above come from `benchmarks/make_set.py` — synthetic pages built
110
+ for testing, not real screenshots. A separate run on 512² real inputs (six
111
+ object renders, one UI screenshot, one text page, one photograph) at q=1:
112
+
113
+ | input | q=1 | WebP-LL | ratio |
114
+ |---|---:|---:|---:|
115
+ | object render (chair) | 94 338 B | 67 476 B | 1.40× |
116
+ | UI screenshot | 25 030 B | 9 610 B | 2.60× |
117
+ | text page | 52 974 B | 8 538 B | 6.20× |
118
+ | photograph | 448 496 B | 443 158 B | 1.01× |
119
+
120
+ Near-lossless on real images is **larger than WebP lossless** on everything
121
+ except a photograph. Also note that q=1 is not a guarantee of pixel identity:
122
+ on three of these inputs the maximum channel difference was 1. The synthetic
123
+ tables describe a controlled testbed; they are not a claim about real pages.
124
+
125
+ ### v0.2.0 / v0.3.0 — tile palettes, then a 2-D index context
126
+
127
+ v0.2.0 gave every `ts × ts` tile its own local palette, grouped so tiles with
128
+ similar colour sets share one, with the tile-id map arithmetic coded as side
129
+ information. v0.3.0 then replaced the index plane's **context** (not its
130
+ predictor, not the palettes): instead of gradients over labels, the context is
131
+ the exact pair `(left, top)`, up to `(K+1)² ≤ 289` contexts, chosen per stream
132
+ by trying both models and keeping the smaller one.
133
+
134
+ Measured against 0.1.1 on the same images:
135
+
136
+ | image | 0.1.1 | v0.3.0 | Δ | of which index plane |
137
+ |---|---:|---:|---:|---:|
138
+ | icon 256² | 370 B | 286 B | **−22.7%** | 326 → 247 B (−24.2%) |
139
+ | circles 256² | 645 B | 426 B | **−34.0%** | 598 → 384 B (−35.8%) |
140
+ | ui 256² | 238 B | 196 B | **−17.6%** | 176 → 139 B (−21.0%) |
141
+ | checker8 1024² | 874 B | 263 B | **−69.9%** | 51 B |
142
+ | stripes4 1024² | 225 B | 163 B | **−27.6%** | 51 B |
143
+ | blocks5 256² | 65 B | 60 B | −7.7% | 18 B |
144
+ | chart 256² | 104 B | 99 B | −4.8% | 48 B |
145
+ | shot_icons 512² | 2 418 B | 1 733 B | **−28.3%** | 2 356 → 1 675 B |
146
+
147
+ Nine-image flat-graphics family, mean saving: **−23.2% at 256², −30.0% at
148
+ 512², −53.0% at 1024²**. The route is lossless by construction and takes part in
149
+ `smallest-of`, so it never enlarges a file.
150
+
151
+ The boundary that survived: the 2-D context loses on planes that are already
152
+ nearly free (a checker at `ts=64`, where every context has to warm up), so the
153
+ encoder keeps the legacy model there — `smallest-of` covers it, but it is a
154
+ measured edge, not a bug.
155
+
156
+ A VP8L-style colour cache was implemented and **rejected on numbers**: on these
157
+ planes the cache hits 99.98–99.99% of pixels, so a cache position must be coded
158
+ almost every pixel and costs 2–200× the MED residual it replaces.
159
+
160
+ ## Where it does not
161
+
162
+ Honest boundaries, measured:
163
+
164
+ - **Photographs against WebP lossy**: 19× larger. Do not use it for photos.
165
+ - **Anti-aliased text against WebP lossless**: ~2× larger — grey ramps break
166
+ index-plane prediction and the palette cannot pay for itself.
167
+ - **1024² low-entropy images**: banded mode costs 8×20 B of header; a
168
+ whole-image path would be smaller (a known trade-off, not a bug).
169
+
170
+ The niche is real and narrow: flat graphics, icons, charts, UI, palette-like
171
+ images — the same class where PNG/VP8L do worst.
172
+
173
+ ## Install
174
+
175
+ ```bash
176
+ pip install hansu # pure Python backend (slow, correct)
177
+ python -m hansu.build_c # optional: build the C backend (~100× faster)
178
+ ```
179
+
180
+ ## Use
181
+
182
+ ```python
183
+ import numpy as np, hansu
184
+ from PIL import Image
185
+
186
+ img = np.array(Image.open("shot.png").convert("RGB"))
187
+ data, rec = hansu.encode(img, qy=16, qc=8) # qy/qc = 1 → near-lossless
188
+ img2 = hansu.decode(data) # native decoder
189
+ img3 = hansu.decode_reference(data) # independent decoder, same bytes
190
+ ```
191
+
192
+ CLI:
193
+
194
+ ```bash
195
+ hansu encode shot.png -o shot.hs2
196
+ hansu decode shot.hs2 -o shot.png
197
+ hansu sign shot.png # topology signature as JSON
198
+ hansu lib images/ -o library.json # build a signature library
199
+ hansu query shot.png --lib library.json # nearest by topology
200
+ hansu bench images/ # batch encode, print a table
201
+ hansu info # backend + format version
202
+ ```
203
+
204
+ ## Topology signatures
205
+
206
+ ```python
207
+ import hansu, json
208
+ sig = hansu.signature(img)
209
+ print(json.dumps(sig, indent=2))
210
+ ```
211
+
212
+ ```json
213
+ {
214
+ "size": [512, 512], "colors": 8, "palette_top16": [[245,246,250], [255,255,255], [59,130,246]],
215
+ "flat_ratio": 0.983, "edge_density": 0.006,
216
+ "period_x": 0, "period_y": 0, "gray_entropy": 1.63,
217
+ "family": "flat-blocks",
218
+ "codec": {"bytes": 2368, "psnr": 99.0, "route": "banded k=4", "version": 3}
219
+ }
220
+ ```
221
+
222
+ Distance is a weighted Euclidean metric over
223
+ `[log2(colors)/16, flat_ratio, edge_density, has_period, entropy/8]`.
224
+ On a 16-image set, same-family pairs average 0.35 and cross-family 1.08 —
225
+ a 3.1× separation.
226
+
227
+ ## Reproduce
228
+
229
+ ```bash
230
+ python benchmarks/make_set.py # draws both sets, no assets needed
231
+ python benchmarks/bench.py benchmarks/set/set256
232
+ python benchmarks/bench.py benchmarks/set/set512
233
+ ```
234
+
235
+ \* These ratios are indicative only: the hansu column is its q16 setting (≈35 dB),
236
+ so comparing it with WebP lossless (99 dB) or q35 (≈30 dB) is not an equal-quality
237
+ comparison. `docs/COMPARISON.md` does the equal-quality study.
238
+
239
+ WebP numbers come from Pillow's encoder on the same pixels. If your Pillow
240
+ builds a different WebP, the comparison columns move; the hansu column does not.
241
+
242
+ ## Architecture
243
+
244
+ ```
245
+ img ──┬─ palette route ──┐
246
+ │ ├─ smaller wins ── HS2 stream
247
+ └─ predictive route┘ │
248
+ YCoCg-R → per-channel ├─ banded variant (parallel decode)
249
+ MED pred → 250 ctx AC ├─ alpha plane
250
+ └─ CRC32
251
+ ```
252
+
253
+ ## Performance
254
+
255
+ C backend, 4 threads, single machine:
256
+
257
+ | input | encode+decode | note |
258
+ |---|---:|---|
259
+ | 512² UI | ~100 ms | automatic route |
260
+ | 1024² UI | ~46 ms | banded k=8, 8.7× vs single band |
261
+
262
+ The pure-Python backend is the reference: same bits, roughly 60× slower.
263
+
264
+ ## Format
265
+
266
+ [`docs/HS2-format.md`](docs/HS2-format.md) — 11 sections, normative, including
267
+ the `uint64` overflow note that a 32-bit arithmetic coder implementation will
268
+ hit silently.
269
+
270
+ ## Status
271
+
272
+ Alpha, v0.1.0. What works: whole/banded encode, decode, alpha, CRC, palette and
273
+ predictive routes, independent decoder, topology signatures, CLI, tests.
274
+ What does not exist yet: HTTP service, language bindings other than Python,
275
+ a real third-party implementation, registered media type.
276
+
277
+ ## Licence
278
+
279
+ MIT.
@@ -0,0 +1,59 @@
1
+ # 发布到 GitHub 与 PyPI
2
+
3
+ 仓库已经初始化并有一次提交(`hansu 0.1.0`)。下面是从这里到「别人能装」的全部步骤。
4
+
5
+ ## 1. 推到 GitHub
6
+
7
+ ```bash
8
+ cd 珩速最优/pkg
9
+ git remote add origin git@github.com:<你的账号>/hansu.git # 先建空仓库
10
+ git branch -M main
11
+ git push -u origin main
12
+ ```
13
+
14
+ 建仓库时不要勾 README / .gitignore / licence,本目录自带,避免冲突。
15
+
16
+ ## 2. 改两处占位
17
+
18
+ - `pyproject.toml` 里 `Homepage = "https://github.com/your-org/hansu"` 换成真实地址
19
+ - `README.md` 顶部如需徽章,加 CI badge:`![ci](https://github.com/<账号>/hansu/actions/workflows/ci.yml/badge.svg)`
20
+
21
+ ## 3. 打 tag 与发布 Release
22
+
23
+ ```bash
24
+ git tag -a v0.1.0 -m "hansu 0.1.0"
25
+ git push origin v0.1.0
26
+ ```
27
+
28
+ GitHub Release 上传 `dist/hansu-0.1.0-py3-none-any.whl` 和 sdist。
29
+
30
+ ## 4. 发 PyPI(可选)
31
+
32
+ ```bash
33
+ python -m pip install build twine
34
+ python -m build # 生成 dist/*.whl + *.tar.gz
35
+ twine check dist/*
36
+ twine upload dist/* # 需要 PyPI token
37
+ ```
38
+
39
+ 包名 `hansu` 未被占用的话可直接用;被占则改名(`pyproject.toml` 的 `name` 与目录都要改)。
40
+
41
+ ## 5. 别人怎么装
42
+
43
+ ```bash
44
+ pip install hansu # PyPI 后
45
+ pip install git+https://github.com/<账号>/hansu.git # 直接从仓库
46
+ python -m hansu.build_c # 可选,快 60 倍
47
+ ```
48
+
49
+ ## 6. CI 已经在
50
+
51
+ `.github/workflows/ci.yml` 跑 Python 3.9/3.11/3.12,编译 C,跑全量测试(含慢的跨后端一致性)。
52
+
53
+ ## 7. 发布前自查
54
+
55
+ ```bash
56
+ python -m pytest -q # 24 passed
57
+ python -m hansu.cli info # backend / format
58
+ python benchmarks/make_set.py && python benchmarks/bench.py benchmarks/set/set256
59
+ ```