cistula 0.1.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.
cistula-0.1.0/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ EUROPEAN UNION PUBLIC LICENCE v. 1.2
2
+ EUPL © the European Union 2007, 2016
3
+
4
+ This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined below) which is provided under the
5
+ terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such
6
+ use is covered by a right of the copyright holder of the Work).
7
+ The Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following
8
+ notice immediately following the copyright notice for the Work:
9
+ Licensed under the EUPL
10
+ or has expressed by any other means his willingness to license under the EUPL.
11
+
12
+ 1.Definitions
13
+ In this Licence, the following terms have the following meaning:
14
+ — ‘The Licence’:this Licence.
15
+ — ‘The Original Work’:the work or software distributed or communicated by the Licensor under this Licence, available
16
+ as Source Code and also as Executable Code as the case may be.
17
+ — ‘Derivative Works’:the works or software that could be created by the Licensee, based upon the Original Work or
18
+ modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work
19
+ required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in
20
+ the country mentioned in Article 15.
21
+ — ‘The Work’:the Original Work or its Derivative Works.
22
+ — ‘The Source Code’:the human-readable form of the Work which is the most convenient for people to study and
23
+ modify.
24
+ — ‘The Executable Code’:any code which has generally been compiled and which is meant to be interpreted by
25
+ a computer as a program.
26
+ — ‘The Licensor’:the natural or legal person that distributes or communicates the Work under the Licence.
27
+ — ‘Contributor(s)’:any natural or legal person who modifies the Work under the Licence, or otherwise contributes to
28
+ the creation of a Derivative Work.
29
+ — ‘The Licensee’ or ‘You’:any natural or legal person who makes any usage of the Work under the terms of the
30
+ Licence.
31
+ — ‘Distribution’ or ‘Communication’:any act of selling, giving, lending, renting, distributing, communicating,
32
+ transmitting, or otherwise making available, online or offline, copies of the Work or providing access to its essential
33
+ functionalities at the disposal of any other natural or legal person.
34
+
35
+ 2.Scope of the rights granted by the Licence
36
+ The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, sublicensable licence to do the following, for
37
+ the duration of copyright vested in the Original Work:
38
+ — use the Work in any circumstance and for all usage,
39
+ — reproduce the Work,
40
+ — modify the Work, and make Derivative Works based upon the Work,
41
+ — communicate to the public, including the right to make available or display the Work or copies thereof to the public
42
+ and perform publicly, as the case may be, the Work,
43
+ — distribute the Work or copies thereof,
44
+ — lend and rent the Work or copies thereof,
45
+ — sublicense rights in the Work or copies thereof.
46
+ Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the
47
+ applicable law permits so.
48
+ In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed
49
+ by law in order to make effective the licence of the economic rights here above listed.
50
+ The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to any patents held by the Licensor, to the
51
+ extent necessary to make use of the rights granted on the Work under this Licence.
52
+
53
+ 3.Communication of the Source Code
54
+ The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as
55
+ Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with
56
+ each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to
57
+ the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to
58
+ distribute or communicate the Work.
59
+
60
+ 4.Limitations on copyright
61
+ Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the
62
+ exclusive rights of the rights owners in the Work, of the exhaustion of those rights or of other applicable limitations
63
+ thereto.
64
+
65
+ 5.Obligations of the Licensee
66
+ The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those
67
+ obligations are the following:
68
+
69
+ Attribution right: The Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to
70
+ the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the
71
+ Licence with every copy of the Work he/she distributes or communicates. The Licensee must cause any Derivative Work
72
+ to carry prominent notices stating that the Work has been modified and the date of modification.
73
+
74
+ Copyleft clause: If the Licensee distributes or communicates copies of the Original Works or Derivative Works, this
75
+ Distribution or Communication will be done under the terms of this Licence or of a later version of this Licence unless
76
+ the Original Work is expressly distributed only under this version of the Licence — for example by communicating
77
+ ‘EUPL v. 1.2 only’. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the
78
+ Work or Derivative Work that alter or restrict the terms of the Licence.
79
+
80
+ Compatibility clause: If the Licensee Distributes or Communicates Derivative Works or copies thereof based upon both
81
+ the Work and another work licensed under a Compatible Licence, this Distribution or Communication can be done
82
+ under the terms of this Compatible Licence. For the sake of this clause, ‘Compatible Licence’ refers to the licences listed
83
+ in the appendix attached to this Licence. Should the Licensee's obligations under the Compatible Licence conflict with
84
+ his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail.
85
+
86
+ Provision of Source Code: When distributing or communicating copies of the Work, the Licensee will provide
87
+ a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available
88
+ for as long as the Licensee continues to distribute or communicate the Work.
89
+ Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names
90
+ of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and
91
+ reproducing the content of the copyright notice.
92
+
93
+ 6.Chain of Authorship
94
+ The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or
95
+ licensed to him/her and that he/she has the power and authority to grant the Licence.
96
+ Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or
97
+ licensed to him/her and that he/she has the power and authority to grant the Licence.
98
+ Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions
99
+ to the Work, under the terms of this Licence.
100
+
101
+ 7.Disclaimer of Warranty
102
+ The Work is a work in progress, which is continuously improved by numerous Contributors. It is not a finished work
103
+ and may therefore contain defects or ‘bugs’ inherent to this type of development.
104
+ For the above reason, the Work is provided under the Licence on an ‘as is’ basis and without warranties of any kind
105
+ concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or
106
+ errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this
107
+ Licence.
108
+ This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work.
109
+
110
+ 8.Disclaimer of Liability
111
+ Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be
112
+ liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the
113
+ Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss
114
+ of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However,
115
+ the Licensor will be liable under statutory product liability laws as far such laws apply to the Work.
116
+
117
+ 9.Additional agreements
118
+ While distributing the Work, You may choose to conclude an additional agreement, defining obligations or services
119
+ consistent with this Licence. However, if accepting obligations, You may act only on your own behalf and on your sole
120
+ responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify,
121
+ defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by
122
+ the fact You have accepted any warranty or additional liability.
123
+
124
+ 10.Acceptance of the Licence
125
+ The provisions of this Licence can be accepted by clicking on an icon ‘I agree’ placed under the bottom of a window
126
+ displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of
127
+ applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms
128
+ and conditions.
129
+ Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You
130
+ by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution
131
+ or Communication by You of the Work or copies thereof.
132
+
133
+ 11.Information to the public
134
+ In case of any Distribution or Communication of the Work by means of electronic communication by You (for example,
135
+ by offering to download the Work from a remote location) the distribution channel or media (for example, a website)
136
+ must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence
137
+ and the way it may be accessible, concluded, stored and reproduced by the Licensee.
138
+
139
+ 12.Termination of the Licence
140
+ The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms
141
+ of the Licence.
142
+ Such a termination will not terminate the licences of any person who has received the Work from the Licensee under
143
+ the Licence, provided such persons remain in full compliance with the Licence.
144
+
145
+ 13.Miscellaneous
146
+ Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the
147
+ Work.
148
+ If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or
149
+ enforceability of the Licence as a whole. Such provision will be construed or reformed so as necessary to make it valid
150
+ and enforceable.
151
+ The European Commission may publish other linguistic versions or new versions of this Licence or updated versions of
152
+ the Appendix, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence.
153
+ New versions of the Licence will be published with a unique version number.
154
+ All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take
155
+ advantage of the linguistic version of their choice.
156
+
157
+ 14.Jurisdiction
158
+ Without prejudice to specific agreement between parties,
159
+ — any litigation resulting from the interpretation of this License, arising between the European Union institutions,
160
+ bodies, offices or agencies, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice
161
+ of the European Union, as laid down in article 272 of the Treaty on the Functioning of the European Union,
162
+ — any litigation arising between other parties and resulting from the interpretation of this License, will be subject to
163
+ the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business.
164
+
165
+ 15.Applicable Law
166
+ Without prejudice to specific agreement between parties,
167
+ — this Licence shall be governed by the law of the European Union Member State where the Licensor has his seat,
168
+ resides or has his registered office,
169
+ — this licence shall be governed by Belgian law if the Licensor has no seat, residence or registered office inside
170
+ a European Union Member State.
171
+
172
+
173
+ Appendix
174
+
175
+ ‘Compatible Licences’ according to Article 5 EUPL are:
176
+ — GNU General Public License (GPL) v. 2, v. 3
177
+ — GNU Affero General Public License (AGPL) v. 3
178
+ — Open Software License (OSL) v. 2.1, v. 3.0
179
+ — Eclipse Public License (EPL) v. 1.0
180
+ — CeCILL v. 2.0, v. 2.1
181
+ — Mozilla Public Licence (MPL) v. 2
182
+ — GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
183
+ — Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for works other than software
184
+ — European Union Public Licence (EUPL) v. 1.1, v. 1.2
185
+ — Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong Reciprocity (LiLiQ-R+).
186
+
187
+ The European Commission may update this Appendix to later versions of the above licences without producing
188
+ a new version of the EUPL, as long as they provide the rights granted in Article 2 of this Licence and protect the
189
+ covered Source Code from exclusive appropriation.
190
+ All other changes or additions to this Appendix require the production of a new EUPL version.
cistula-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,379 @@
1
+ Metadata-Version: 2.4
2
+ Name: cistula
3
+ Version: 0.1.0
4
+ Summary: Shared Python helpers of the Plurano framework family.
5
+ Author-email: Lusoris <lusoris@proton.me>
6
+ License-Expression: EUPL-1.2
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Operating System :: POSIX :: Linux
9
+ Classifier: Programming Language :: Python :: 3 :: Only
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.11
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Dynamic: license-file
19
+
20
+ # Cistula
21
+
22
+ <!-- praetor:readme-governance:start -->
23
+ [![HISS Adopted][praetor-hiss-badge]][praetor-hiss-agents]
24
+
25
+ Praetor manages this repository's declared governance policy. This managed
26
+ block records adoption state; it is not a verification certificate.
27
+
28
+ **Verification**: `make verify-all` runs the repository's configured
29
+ verification cascade.
30
+
31
+ **HISS Audit**: `praetorctl audit` enforces policy, generated-surface
32
+ integrity, and the debt ratchet.
33
+
34
+ **Context Sync**: `praetorctl compile-context --verify` verifies every
35
+ generated agent context against `AGENTS.md`.
36
+
37
+ **Debt Baseline**: `.standards-baseline.json` anchors the debt ratchet at
38
+ 0 recorded infractions; audit forbids growth.
39
+
40
+ [praetor-hiss-badge]: https://img.shields.io/badge/Standards-HISS%20Adopted-blue
41
+ [praetor-hiss-agents]: https://github.com/plurano/cistula/blob/HEAD/AGENTS.md
42
+ <!-- praetor:readme-governance:end -->
43
+
44
+ Shared Python helpers of the Plurano framework family: one tested
45
+ implementation of the helpers that every repository used to repeat.
46
+
47
+ ## Name
48
+
49
+ Cistula (pronounced KIS-tu-la) is Latin for a small chest: the case that held
50
+ a craftsman's or a scribe's small tools. The word is the diminutive of *cista*,
51
+ from Greek *kiste*. The repository, the distribution and the import package
52
+ all carry the name `cistula`.
53
+
54
+ ## Status
55
+
56
+ Public. The version is `0.1.0`, the first release ([CHANGELOG](CHANGELOG.md)).
57
+
58
+ ## What the first release contains
59
+
60
+ Three modules. They use the standard library only, and no function contacts a
61
+ network.
62
+
63
+ | Module | What it does |
64
+ | --- | --- |
65
+ | `process` | `run` starts a command under a time limit the caller must state. `child_env` builds the environment for such a child. |
66
+ | `files` | `read_json` and `loads_json` refuse a repeated key and a number JSON does not have. `write_bytes_atomic`, `write_text_atomic` and `write_json` replace a file in one step. `open_bytes_atomic`, `open_text_atomic` and `staged_path` do that for content written in a `with` block. Files that can be made again (caches, per-item results) take `durable=False`; everything else keeps the default, which costs milliseconds per file (see Guarantees). |
67
+ | `digest` | `sha256_file`, `sha256_bytes` and `sha256_text`. |
68
+
69
+ ```python
70
+ from cistula import read_json, run, sha256_file, write_json
71
+
72
+ result = run(["git", "rev-parse", "HEAD"], timeout=30, check=True)
73
+ record = read_json("record.json")
74
+ record["commit"] = result.stdout.strip()
75
+ record["digest"] = sha256_file("artifact.bin")
76
+ write_json("record.json", record)
77
+ ```
78
+
79
+ ### Guarantees
80
+
81
+ - **Time limit.** `run` has no default time limit and accepts no value that
82
+ means "for ever": zero, a negative number, infinity and NaN are refused.
83
+ - **Group kill.** The child runs in a process group of its own. When the limit
84
+ expires the whole group gets `SIGTERM` and, after `kill_after` seconds,
85
+ `SIGKILL`. A child that ignores the first signal, or a descendant that holds
86
+ the output open, cannot keep the caller waiting.
87
+ - **Atomic write.** New content goes to a temporary file in the same directory,
88
+ is flushed to disk and then replaces the target in one step. A failure at any
89
+ point before the replace leaves the old file whole and no temporary file
90
+ behind.
91
+ - **Writing in a block.** Content that is produced in steps, or by a producer
92
+ that takes a file name, is written in a `with` block under the same
93
+ guarantee: the target is replaced when the block ends, and a block that
94
+ raises leaves the old file whole and no temporary file behind.
95
+
96
+ ```python
97
+ with open_text_atomic("rows.jsonl") as rows:
98
+ for record in records:
99
+ rows.write(json.dumps(record) + "\n")
100
+
101
+ with staged_path("table.parquet") as temporary:
102
+ frame.to_parquet(temporary)
103
+ ```
104
+
105
+ `open_bytes_atomic` and `open_text_atomic` lend an open file. Text is
106
+ written as UTF-8 with the line endings given, and what is still buffered
107
+ when the block ends is written before the rename. `staged_path` lends a
108
+ name instead, for a library call or a child process that opens the file
109
+ itself: an absolute path beside the target, of a file that does not exist
110
+ yet, ending with the suffix of the target. A relative target is tied to the
111
+ working directory at the start of the block, so the block may change the
112
+ directory ([tests/test_files.py](tests/test_files.py),
113
+ `test_text_still_buffered_when_the_block_ends_is_in_the_file_before_the_rename`,
114
+ `test_an_error_in_the_block_leaves_the_old_file_whole_and_reaches_the_caller`,
115
+ `test_a_block_may_change_the_current_directory`).
116
+ - **What `staged_path` checks.** The producer must have closed the file before
117
+ the block ends. Content a producer still holds in memory is not in the
118
+ file, and only the producer knows. Two signs of that mistake are refused,
119
+ with the old file whole: no file under the name raises `FileNotFoundError`,
120
+ an empty file raises `ValueError`. A caller for whom an empty file is a
121
+ valid result passes `allow_empty=True`; a missing file is refused then too.
122
+ A link, a pipe or a directory under the name is refused, and a directory is
123
+ not removed. An existing target's permissions are applied when the block
124
+ ends; a new file keeps the permissions the producer gave it
125
+ (`test_staged_path_refuses_a_producer_that_wrote_no_file`,
126
+ `test_staged_path_refuses_the_file_of_a_producer_that_has_not_written_yet`).
127
+ - **Durable by default.** The writers flush the file before the rename and the
128
+ directory after it. On a disk a flush takes milliseconds where the write
129
+ alone takes microseconds. Measured for one small file on NVMe disks
130
+ (median of 200 calls, `PYTHONPATH=src python
131
+ tools/measure_durable_write.py DIRECTORY`):
132
+
133
+ | File system | Default (`durable=True`) | `durable=False` |
134
+ | --- | --- | --- |
135
+ | btrfs | 10 ms (18 to 36 ms in earlier runs) | 15 µs |
136
+ | ZFS, `sync=standard` | 3 ms | 22 to 28 µs |
137
+ | tmpfs (memory, no disk) | 11 to 13 µs | 10 to 11 µs |
138
+
139
+ `make verify` measures the file system of the checkout and fails when the
140
+ table is out of date (`tools/check_durable_figures.py`): every disk row must
141
+ state the default at least 20 times the cost without the flushes, a
142
+ measured figure must lie within a factor of 4 of its row, and on a disk the
143
+ measured default must cost at least 4 times the write alone. The last bound
144
+ is lower because a virtual disk with a write cache flushes fast: ext4 on
145
+ the CI runner measured 433 µs against 48 µs.
146
+
147
+ A caller that writes many files it can make again (caches, per-item
148
+ results) passes `durable=False`. That call is **not crash-safe**: after a
149
+ power failure or a crash of the operating system the target can hold the
150
+ old content, the new content, or an empty or incomplete file. The replace
151
+ is still one step for every reader. A flush shared by a group of files is
152
+ not offered; [ADR 0002](docs/adr/0002-grouped-flush.md) proposes one.
153
+ - **Permissions.** An existing file keeps its permissions. A new file gets the
154
+ permissions of any newly created file, so the process umask decides who can
155
+ read it (mode 644 under umask 022). The writers make no file private; a
156
+ caller that needs that sets the umask or the mode itself.
157
+ - **Directories.** A missing directory of the target raises
158
+ `FileNotFoundError`. A caller that wants it created passes `parents=True`;
159
+ missing directories above it are created too, as `os.makedirs` does. A new
160
+ directory gets its permissions the way a new file does, from the umask (mode
161
+ 755 under umask 022); a directory that exists is left as it is. Directories
162
+ created stay when the write then fails: the one step is the file, not its
163
+ directories ([tests/test_files.py](tests/test_files.py),
164
+ `test_new_directories_take_their_permissions_from_the_umask`,
165
+ `test_directories_created_stay_when_the_write_fails`).
166
+ - **Strict JSON.** A repeated key, a byte-order mark and invalid UTF-8 are
167
+ errors when reading. So are NaN, the two infinities and a number too large
168
+ for a float, none of which JSON has: `json.loads` reads them silently, the
169
+ readers raise `ValueError`. `write_json` refuses the same values and leaves
170
+ the old file whole. A caller that must read a file holding such a number
171
+ passes `finite_numbers=False`; that lifts this one check and no other, as
172
+ `unique_keys=False` does for a repeated key
173
+ ([tests/test_files.py](tests/test_files.py),
174
+ `test_each_keyword_lifts_its_own_check_only`).
175
+
176
+ ### Limits
177
+
178
+ - Tested on Linux only: CI runs Ubuntu 24.04
179
+ ([ci.yml](.github/workflows/ci.yml)). The code uses POSIX interfaces only,
180
+ but no test runs on macOS or a BSD, and the guarantees can differ there. On
181
+ macOS, for one, `fsync` hands the data to the drive without asking the drive
182
+ to store it; that takes `F_FULLFSYNC`
183
+ ([fsync(2)](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fsync.2.html)),
184
+ which the writers do not call. Process groups do not exist on Windows; `run`
185
+ raises `NotImplementedError` there instead of running without the guarantee.
186
+ - A descendant that moves itself into another session leaves the group and
187
+ outlives the kill. `run` still returns within the limit plus the grace
188
+ period.
189
+ - When the whole process is killed between write and replace, or inside a
190
+ block, the old file is whole, but the temporary file
191
+ `.<name>.<16 hex digits>.tmp` stays in the directory. The temporary file of
192
+ `staged_path` has the suffix of the target after `.tmp`.
193
+ - `staged_path` cannot refuse a file that is neither empty nor complete: a
194
+ producer that wrote a part and still holds the rest gets that part
195
+ published
196
+ (`test_staged_path_cannot_see_what_a_producer_still_holds_in_a_file_that_is_not_empty`).
197
+ - Python 3.11 or newer.
198
+
199
+ ### Compared with other libraries
200
+
201
+ Checked on 2026-10-17 against the newest release on PyPI and its source.
202
+
203
+ | Need | Libraries compared | What they do that cistula does not |
204
+ | --- | --- | --- |
205
+ | Atomic file writes | atomicwrites 1.4.1 (archived, last release 2022), safer 6.1.0, boltons 26.2.0 (`AtomicSaver`) | Code for Windows (atomicwrites, boltons); `F_FULLFSYNC` on macOS (atomicwrites) |
206
+ | Subprocess wrappers | sh 2.4.0, plumbum 2.0.2, sarge 0.1.8, invoke 3.0.3, anyio 4.15.1 (`run_process`) | Shell-style pipelines (sh, plumbum, sarge); an `async` interface (anyio) |
207
+ | JSON reading | standard library `json`, orjson 3.13.0, msgspec 0.22.0 | Speed (orjson, msgspec); none of the three refuses a repeated key by default |
208
+ | Digests | standard library `hashlib.file_digest`, dirhash 0.5.0, checksumdir 1.3.0 | Any algorithm by name (`hashlib`); one digest over a directory tree (dirhash, checksumdir) |
209
+
210
+ The comparison found these features missing from cistula. Each is left out for
211
+ the reason given:
212
+
213
+ - **Windows.** Every guarantee of `run` rests on a process group, which
214
+ Windows does not have (see Limits). The writers are tested on Linux only. A
215
+ Windows port is a release of its own, and it waits until a project that
216
+ uses cistula runs on Windows.
217
+ - **`F_FULLFSYNC` on macOS.** No test runs on macOS, so a call there would
218
+ ship unproven. Limits states the gap.
219
+ - **Pipelines and shell syntax.** `run` takes a list of arguments and never a
220
+ shell, so no string is parsed into a command. A caller passes the output of
221
+ one call as `input` of the next, or runs a script under one time limit.
222
+ - **An `async` interface.** anyio needs a dependency, and cistula uses the
223
+ standard library only. `run` blocks, and a caller in an event loop can call
224
+ it in a worker thread (`asyncio.to_thread`).
225
+ - **Faster JSON.** orjson and msgspec are compiled dependencies, and like the
226
+ standard library they take the last of repeated keys instead of refusing
227
+ them. `read_json` is meant for records and configuration, not for bulk data.
228
+ - **Other digest algorithms and tree digests.** The records cistula writes
229
+ name SHA-256 only. `hashlib.file_digest` takes any algorithm for a caller
230
+ that needs one. A tree digest needs rules for ordering, links and
231
+ permissions that no consumer has asked for yet.
232
+
233
+ Where cistula goes further than the compared libraries:
234
+
235
+ - `run` requires a time limit, kills the whole process group when the limit
236
+ passes, and builds the environment of the child from an allow-list
237
+ (`child_env`). The compared wrappers make the time limit optional and pass
238
+ the full environment on to the child. sh, plumbum, sarge and invoke kill
239
+ only the child on a timeout; sh kills the group only when the caller asks
240
+ for it.
241
+ - The writers flush the directory as well as the file. Of the compared
242
+ libraries, only atomicwrites flushes the directory, boltons flushes the file
243
+ only, and safer flushes neither.
244
+ - `staged_path` refuses to publish an empty file unless the caller allows
245
+ one; none of the compared writers checks the size of what it publishes.
246
+ - `read_json` refuses repeated keys and the non-finite numbers `NaN` and
247
+ `Infinity`. The standard library accepts both; orjson and msgspec refuse the
248
+ numbers but accept repeated keys.
249
+
250
+ ## Installing
251
+
252
+ While the repository is private there is no package index entry. A consumer
253
+ installs the built wheel from a local path and pins its hash:
254
+
255
+ ```sh
256
+ make package # prints the SHA-256 of dist/*.whl
257
+ pip install --require-hashes -r requirements.txt
258
+ ```
259
+
260
+ with this line in the consumer's `requirements.txt`:
261
+
262
+ ```text
263
+ cistula @ file:///path/to/dist/cistula-0.1.0-py3-none-any.whl --hash=sha256:<hash printed by make package>
264
+ ```
265
+
266
+ The bytes of the wheel and of the source distribution depend on the commit
267
+ only: every host and every supported interpreter builds the same two files
268
+ from the same commit. The hash to pin is the one `make package` prints for
269
+ that commit, and a second build of it must print the same
270
+ (see [Reproducible package](#reproducible-package)).
271
+
272
+ ## Development
273
+
274
+ ```sh
275
+ make verify-all
276
+ ```
277
+
278
+ This is the whole gate, and CI runs the same target. It needs `python3.11`,
279
+ `python3.12`, `python3.13` and `python3.14` on `PATH` (or `PYTHONS="..."` with full paths),
280
+ `reuse` 6.2.0, `trivy` 0.76.0 (or `TRIVY=...`) and the standards engine. An
281
+ interpreter or a tool that is missing fails the gate.
282
+
283
+ The engine is the commit that `PRAETOR_REF` in
284
+ [ci.yml](.github/workflows/ci.yml) pins, for the gate and for the Git hooks
285
+ alike. [.config/lefthook/engine.sh](.config/lefthook/engine.sh) installs it
286
+ once per pin with `go install` and fails when it cannot; a `praetorctl` on
287
+ `PATH` is not used in its place. `make praetor-engine-path` prints the binary
288
+ in use, and the gate stops at its first step (`make verify-engine-pin`) when
289
+ no workflow declares the pin.
290
+
291
+ 1. One environment per interpreter is installed from `requirements/dev.txt`.
292
+ Every package is pinned by hash; nothing else is installed.
293
+ 2. Format, lint, types, licence headers, the exception list and the list of
294
+ supported Python versions are checked once. Then
295
+ [tools/scanners.py](tools/scanners.py) runs semgrep with the rules in
296
+ [.config/semgrep/hiss.yml](.config/semgrep/hiss.yml) and trivy on both
297
+ locks. Each scanner first has to report the defects planted in a scratch
298
+ folder; a scanner that reports nothing there fails the gate.
299
+ 3. One source distribution and one wheel are built, and their sizes are
300
+ checked against the figures under [Reproducible package](#reproducible-package).
301
+ 4. Every interpreter builds both once more. One differing byte fails.
302
+ 5. The wheel of step 3 is installed into each environment, and the tests run
303
+ against the installed package with 100 % branch coverage required. Before
304
+ them, [tools/check_consumer.py](tools/check_consumer.py) installs the wheel
305
+ as [Installing](#installing) describes, into a new environment that holds
306
+ nothing else, and [tests/consumer.py](tests/consumer.py) calls the public
307
+ interface there from an empty directory.
308
+ 6. The standards engine checks that the agent contexts equal `AGENTS.md`,
309
+ checks the register of the configured texts and runs its audit.
310
+
311
+ `make verify` runs steps 1 to 5 and needs no engine.
312
+
313
+ `make lock` regenerates `requirements/dev.txt` from `requirements/dev.in`
314
+ and `requirements/semgrep.txt` from `requirements/semgrep.in`. A release
315
+ younger than three days is not eligible. semgrep has its own environment
316
+ under `.venv/semgrep`, so its dependencies never pin those of the tests.
317
+
318
+ Every public function has positive, negative and boundary tests. A test that
319
+ guards a guarantee was seen failing once with the guarantee removed from the
320
+ code.
321
+
322
+ ### Reproducible package
323
+
324
+ `make package` gives the same bytes for the same commit on every host. Four
325
+ things make it so:
326
+
327
+ - **Date.** `SOURCE_DATE_EPOCH` is the time of the last commit
328
+ ([Makefile](Makefile)); the wall clock is never used.
329
+ - **Source distribution.** The build backend records the build time, the
330
+ owner and the mode of each file. [tools/reproducible_sdist.py](tools/reproducible_sdist.py)
331
+ writes the archive again: members sorted by name, owned by nobody, mode 644
332
+ or 755, dated by the commit.
333
+ - **Wheel.** It is built from the rewritten source distribution under the
334
+ file mode mask 022.
335
+ - **No compression.** Both files store their members uncompressed
336
+ ([setup.cfg](setup.cfg) for the wheel). zlib and zlib-ng give different
337
+ bytes for the same input, and interpreters are built with either. The price
338
+ is size: about 307 kB and 66 kB instead of 63 kB and 25 kB.
339
+ [tools/check_package_size.py](tools/check_package_size.py) measures the
340
+ four sizes in the gate (`make verify-package-size`) and fails when a figure
341
+ in this sentence is off by more than a tenth.
342
+
343
+ `make verify-reproducible` is the check, and part of the gate: each
344
+ interpreter builds the package again under another file mode mask, and
345
+ [tools/compare_packages.py](tools/compare_packages.py) fails on one differing
346
+ byte, naming the archive member and the field.
347
+
348
+ Two limits:
349
+
350
+ - The date comes from the commit, so the hash means something for a clean
351
+ tree only.
352
+ - A pull request run in CI builds the forge's test merge commit, which has
353
+ its own date. Its hashes are not those of the branch. The hashes of a build
354
+ on the main branch or on a tag are the ones to compare and to pin.
355
+
356
+ ### Supported Python versions
357
+
358
+ The classifiers in [pyproject.toml](pyproject.toml) are the list; the oldest
359
+ version is the floor. Every version on it is tested: `PYTHONS` in the
360
+ [Makefile](Makefile) and the interpreter list in
361
+ [ci.yml](.github/workflows/ci.yml) name the same versions, and
362
+ `requires-python`, the lint target in [ruff.toml](ruff.toml), `python_version`
363
+ of the type check and the lock are set to the floor.
364
+ [tools/check_python_versions.py](tools/check_python_versions.py) fails the
365
+ gate when one of these places disagrees, so adding or dropping a version means
366
+ changing all of them in one commit, and then `make lock`.
367
+
368
+ ### Exceptions
369
+
370
+ Every check binds every file. A file that is left out of a check has an entry
371
+ in [exceptions.toml](exceptions.toml): one file, one rule, a reason and an
372
+ expiry at most 90 days ahead. The gate fails when an entry has expired, when
373
+ its file is gone or passes the check again, and when `ruff.toml` leaves a file
374
+ out of the lint without an entry. The three entries today are scripts the
375
+ standards engine writes; they end when the engine ships them clean.
376
+
377
+ ## Licence
378
+
379
+ EUPL-1.2, see [LICENSE](LICENSE).