s-reports 0.1.0__py3-none-any.whl
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.
- s_reports-0.1.0.dist-info/METADATA +295 -0
- s_reports-0.1.0.dist-info/RECORD +69 -0
- s_reports-0.1.0.dist-info/WHEEL +5 -0
- s_reports-0.1.0.dist-info/entry_points.txt +2 -0
- s_reports-0.1.0.dist-info/licenses/LICENSE +21 -0
- s_reports-0.1.0.dist-info/top_level.txt +1 -0
- sr/__init__.py +13 -0
- sr/__main__.py +16 -0
- sr/api.py +194 -0
- sr/barcode/__init__.py +139 -0
- sr/barcode/aztec.py +796 -0
- sr/barcode/dmtx.py +370 -0
- sr/barcode/linear.py +324 -0
- sr/barcode/qr.py +583 -0
- sr/barcode/readable.py +116 -0
- sr/barcode/reedsolomon.py +134 -0
- sr/barcode/symbol.py +140 -0
- sr/cli.py +1630 -0
- sr/color.py +231 -0
- sr/data.py +352 -0
- sr/errors.py +523 -0
- sr/expr/__init__.py +63 -0
- sr/expr/builtins.py +1574 -0
- sr/expr/calc.py +544 -0
- sr/expr/compile.py +595 -0
- sr/expr/fmt.py +550 -0
- sr/expr/golayout.py +676 -0
- sr/expr/literals.py +557 -0
- sr/expr/values.py +1528 -0
- sr/fonts/__init__.py +70 -0
- sr/fonts/face.py +623 -0
- sr/fonts/hostenum.py +737 -0
- sr/fonts/resolve.py +566 -0
- sr/fonts/text.py +338 -0
- sr/image.py +358 -0
- sr/kdl.py +713 -0
- sr/layout/__init__.py +49 -0
- sr/layout/blobs.py +166 -0
- sr/layout/columns.py +191 -0
- sr/layout/context.py +212 -0
- sr/layout/defer.py +277 -0
- sr/layout/fonttable.py +147 -0
- sr/layout/frame.py +361 -0
- sr/layout/images.py +251 -0
- sr/layout/loop.py +2884 -0
- sr/layout/measure.py +1949 -0
- sr/layout/place.py +266 -0
- sr/layout/subreport.py +302 -0
- sr/layout/variables.py +183 -0
- sr/meta.py +32 -0
- sr/pdf/__init__.py +27 -0
- sr/pdf/document.py +663 -0
- sr/pdf/draw.py +569 -0
- sr/pdf/images.py +264 -0
- sr/pdf/objects.py +344 -0
- sr/pdf/subset.py +457 -0
- sr/printout/__init__.py +57 -0
- sr/printout/inspect.py +777 -0
- sr/printout/model.py +472 -0
- sr/printout/read.py +746 -0
- sr/printout/verify.py +672 -0
- sr/printout/write.py +635 -0
- sr/py.typed +0 -0
- sr/settle.py +300 -0
- sr/template/__init__.py +35 -0
- sr/template/load.py +1602 -0
- sr/template/model.py +1172 -0
- sr/template/validate.py +1313 -0
- sr/units.py +252 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: s-reports
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A banded report formatter: template plus records in, PDF out.
|
|
5
|
+
Author: Aleksandr Smyshliaev
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/a1s/sr.py
|
|
8
|
+
Project-URL: Reference, https://github.com/a1s/sr
|
|
9
|
+
Keywords: reporting,pdf,kdl,starlark
|
|
10
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Printing
|
|
14
|
+
Requires-Python: >=3.11
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: ckdl>=1.0
|
|
18
|
+
Requires-Dist: fonttools
|
|
19
|
+
Requires-Dist: cbor2
|
|
20
|
+
Requires-Dist: pillow
|
|
21
|
+
Requires-Dist: tzdata
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
24
|
+
Requires-Dist: pytest-xdist>=3; extra == "dev"
|
|
25
|
+
Requires-Dist: ruff==0.16.6; extra == "dev"
|
|
26
|
+
Requires-Dist: mypy==2.3.1; extra == "dev"
|
|
27
|
+
Provides-Extra: oracles
|
|
28
|
+
Requires-Dist: pypdfium2; extra == "oracles"
|
|
29
|
+
Requires-Dist: starlark; extra == "oracles"
|
|
30
|
+
Requires-Dist: qrcode; extra == "oracles"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# sr.py — structural reporting
|
|
34
|
+
|
|
35
|
+
A banded report formatter. Apply a template to a sequence of records
|
|
36
|
+
and get a paginated document: bands, groups, page and column headers
|
|
37
|
+
and footers, running aggregates, and page footers that know the final
|
|
38
|
+
page count.
|
|
39
|
+
|
|
40
|
+
A Python library with a CLI over it, counterpart to the parallel
|
|
41
|
+
[Go project](https://github.com/a1s/sr). Template plus JSON in, PDF out.
|
|
42
|
+
|
|
43
|
+
## Documentation
|
|
44
|
+
|
|
45
|
+
| | |
|
|
46
|
+
|---|---|
|
|
47
|
+
| [doc/template.md](https://github.com/a1s/sr.py/blob/main/doc/template.md) | Template format: nodes, properties, geometry, ordering rules, font resolution |
|
|
48
|
+
| [doc/expressions.md](https://github.com/a1s/sr.py/blob/main/doc/expressions.md) | Expression language, predefined names, formatting, variable semantics |
|
|
49
|
+
| [doc/layout.md](https://github.com/a1s/sr.py/blob/main/doc/layout.md) | Layout and pagination |
|
|
50
|
+
| [doc/printout.md](https://github.com/a1s/sr.py/blob/main/doc/printout.md) | The intermediate document a renderer consumes |
|
|
51
|
+
| [doc/barcode.md](https://github.com/a1s/sr.py/blob/main/doc/barcode.md) | Barcode encoding: which symbol each type draws for a value |
|
|
52
|
+
| [doc/render.md](https://github.com/a1s/sr.py/blob/main/doc/render.md) | PDF rendering: what a renderer decides, and what it must not |
|
|
53
|
+
| [doc/cli.md](https://github.com/a1s/sr.py/blob/main/doc/cli.md) | The command line: subcommands, flags, streams, exit codes |
|
|
54
|
+
| [example/minimal/](https://github.com/a1s/sr.py/tree/main/example/minimal/) | The smallest complete report, and the printout doc/printout.md shows |
|
|
55
|
+
| [example/sakila/](https://github.com/a1s/sr.py/tree/main/example/sakila/) | Reference template and dataset |
|
|
56
|
+
| [example/invoices/](https://github.com/a1s/sr.py/tree/main/example/invoices/) | Second example: both kinds of subreport, region grouping, the remaining variable modes |
|
|
57
|
+
| [example/fonts/](https://github.com/a1s/sr.py/tree/main/example/fonts/) | Fonts committed so examples resolve identically everywhere |
|
|
58
|
+
|
|
59
|
+
## How it works
|
|
60
|
+
|
|
61
|
+
Three artifacts and one language:
|
|
62
|
+
|
|
63
|
+
- A **template** is a [KDL](https://kdl.dev) v2 document describing page geometry
|
|
64
|
+
and a tree of bands. Bands are `title`, `summary`, `header`, `footer`, and
|
|
65
|
+
`detail`; groups nest around the detail band.
|
|
66
|
+
- **Data** is JSON or NDJSON. Field types are declared in the template, which is
|
|
67
|
+
what turns `"19.99"` into an exact decimal and `"2005-05-24T22:53:30Z"` into a
|
|
68
|
+
time value.
|
|
69
|
+
- A **printout** is the engine's output: pages of absolutely-positioned marks
|
|
70
|
+
with nothing evaluable left in them. Renderers do no layout.
|
|
71
|
+
- **Expressions** are [Starlark](https://github.com/bazelbuild/starlark) —
|
|
72
|
+
sandboxed, with no imports, filesystem, or network.
|
|
73
|
+
|
|
74
|
+
Layout is speculative: every band is measured before it is committed, then placed,
|
|
75
|
+
split, or deferred to the next frame. Band splitting, keep-together, orphan and
|
|
76
|
+
widow control, and correct deferred page counts all follow from that.
|
|
77
|
+
|
|
78
|
+
## Command line
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
python sr.py build --template sakila.kdl --data payments.jsonl --out report.pdf
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
That is the launcher at the root of a checkout, which runs the program
|
|
85
|
+
without installing the package. Installed with `pip install s-reports`,
|
|
86
|
+
the same program is the `s-reports` command, and `python -m sr` where
|
|
87
|
+
the interpreter's scripts directory is not on the path.
|
|
88
|
+
|
|
89
|
+
| Flag | |
|
|
90
|
+
|---|---|
|
|
91
|
+
| `-t`, `--template` | Template file. Required. |
|
|
92
|
+
| `-d`, `--data` | JSON array or NDJSON file, `-` for standard input. Omit for a template with no records. |
|
|
93
|
+
| `-o`, `--out` | Output path, `-` for standard output. Extension selects the format: `.pdf`, `.srp.jsonl`, `.srp.cbor`. |
|
|
94
|
+
| `--format` | `pdf`, `jsonl` or `cbor`, when the extension does not say. |
|
|
95
|
+
| `--param NAME=VALUE` | Supply a report parameter. Repeatable. `VALUE` is text, parsed per the parameter's declared type. A name the template does not declare is an error, not a value that goes nowhere. |
|
|
96
|
+
| `--build-time` | RFC 3339. Fixes `BUILD_TIME` for reproducible output. |
|
|
97
|
+
| `--strict-fonts` | Resolve only explicitly named font files; fail otherwise. |
|
|
98
|
+
| `--strict-names` | Refuse a node or property the format does not define, instead of warning about it. |
|
|
99
|
+
| `--accept NAME` | Take one such name without a warning. Repeatable. |
|
|
100
|
+
| `--allow-overflow` | Downgrade oversized-band errors to warnings recorded in the printout. |
|
|
101
|
+
| `--uncompressed` | Leave PDF streams uncompressed, to read the file in an editor. |
|
|
102
|
+
| `-v`, `--verbose` | Report host font diagnostics. |
|
|
103
|
+
|
|
104
|
+
Other subcommands:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
python sr.py validate sakila.kdl # check a template without data
|
|
108
|
+
python sr.py inspect report.srp.jsonl # dump a printout as readable text
|
|
109
|
+
python sr.py render report.srp.jsonl -o report.pdf
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`build` writing a printout and `render` reading one back produce the same PDF as
|
|
113
|
+
`build` writing PDF directly, which is what makes printouts worth archiving.
|
|
114
|
+
|
|
115
|
+
The document goes to standard output and everything about the run to
|
|
116
|
+
standard error, so `-o -` pipes. Exit 0 is success, 1 a run that failed,
|
|
117
|
+
2 a mistake in the command line; warnings never change it, because they
|
|
118
|
+
travel in the printout header where archiving keeps them. A one-letter flag
|
|
119
|
+
takes one dash and a long one two, so `-t` and `--template`, but not `--t`
|
|
120
|
+
or `-template`. A value is attached with `=` or separate, a flag may follow
|
|
121
|
+
the positional arguments, and a switch also takes `=true` or `=false`.
|
|
122
|
+
Full reference: [doc/cli.md](https://github.com/a1s/sr.py/blob/main/doc/cli.md).
|
|
123
|
+
|
|
124
|
+
## Library
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from pathlib import Path
|
|
128
|
+
|
|
129
|
+
from sr.api import Options, build
|
|
130
|
+
from sr.printout.write import write_jsonl
|
|
131
|
+
|
|
132
|
+
result = build(
|
|
133
|
+
Path("sakila.kdl"),
|
|
134
|
+
Path("payments.jsonl"),
|
|
135
|
+
Options(params={"period_start": "2005-06-01"}, strict_fonts=True),
|
|
136
|
+
)
|
|
137
|
+
out = Path("sakila.srp.jsonl")
|
|
138
|
+
with out.open("w", encoding="utf-8", newline="") as handle:
|
|
139
|
+
write_jsonl(result.printout, handle, out.parent)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`build` returns the printout as an object, which is the primary artifact:
|
|
143
|
+
serializing it is a separate step, and the directory it is written to is what
|
|
144
|
+
its font and image paths are made relative to. Every flag on the command line
|
|
145
|
+
is a field of `Options`, because the command line
|
|
146
|
+
[decides nothing](https://github.com/a1s/sr.py/blob/main/doc/cli.md).
|
|
147
|
+
|
|
148
|
+
Rendering is a separate step too, and takes the printout in memory
|
|
149
|
+
or one read back from a file. Both give the same bytes:
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from sr.pdf import render
|
|
153
|
+
from sr.printout.read import read
|
|
154
|
+
|
|
155
|
+
Path("sakila.pdf").write_bytes(render(result.printout))
|
|
156
|
+
Path("again.pdf").write_bytes(render(read(out)))
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Running the examples
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
python sr.py build -t example/minimal/minimal.kdl -d example/minimal/films.jsonl -o minimal.srp.jsonl
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
[minimal.kdl](https://github.com/a1s/sr.py/blob/main/example/minimal/minimal.kdl)
|
|
166
|
+
is the smallest report there is: one font, a header with a rule,
|
|
167
|
+
and one field per record. Its printout is the example at the end of
|
|
168
|
+
[doc/printout.md](https://github.com/a1s/sr.py/blob/main/doc/printout.md#example),
|
|
169
|
+
which the test suite builds and compares byte for byte, so that example is a
|
|
170
|
+
document rather than an illustration of one.
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
python sr.py build -t example/sakila/sakila.kdl -d example/sakila/payments.jsonl -o sakila.pdf
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Narrowed to one month, using the template's `date` parameters:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
python sr.py build -t example/sakila/sakila.kdl -d example/sakila/payments.jsonl -o june.pdf --param period_start=2005-06-01 --param period_end=2005-07-01
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
The second example, which uses both kinds of subreport:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
python sr.py build -t example/invoices/invoices.kdl -d example/invoices/invoices.jsonl -o invoices.pdf
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
[sakila.kdl](https://github.com/a1s/sr.py/blob/main/example/sakila/sakila.kdl) —
|
|
189
|
+
a payment list grouped by customer in two columns: every band type,
|
|
190
|
+
a group with its own title and summary, column header and footer,
|
|
191
|
+
stretch fields, a floating element, six barcode types, an embedded image
|
|
192
|
+
and a referenced one, both kinds of cross-reference, conditional outline entries,
|
|
193
|
+
a deferred page count, justified text, and typed parameters.
|
|
194
|
+
|
|
195
|
+
[invoices.kdl](https://github.com/a1s/sr.py/blob/main/example/invoices/invoices.kdl) —
|
|
196
|
+
invoices by region with line items: an inline `embedded` subreport
|
|
197
|
+
with an `arg` and its own `records`, a `template=` subreport in
|
|
198
|
+
[region_sheet.kdl](https://github.com/a1s/sr.py/blob/main/example/invoices/region_sheet.kdl)
|
|
199
|
+
that paginates itself onto landscape pages of its own, a group using `keeptogether`
|
|
200
|
+
with `minrows` and `mintailrows`, a `summary` with `swapfooter`, an image with
|
|
201
|
+
`embed=#false`, a compressed `data` blob, `iter="item"` against `iter="detail"`,
|
|
202
|
+
and the `calc` modes sakila leaves out.
|
|
203
|
+
|
|
204
|
+
Between them the two templates use every node in the format but `accept`,
|
|
205
|
+
and all twelve `calc` modes. They do not exhaust every property.
|
|
206
|
+
What they leave out, so that reading them as a reference does not mislead:
|
|
207
|
+
|
|
208
|
+
| | |
|
|
209
|
+
|---|---|
|
|
210
|
+
| Nodes | `accept` |
|
|
211
|
+
| Properties | `layout width` / `height` / `landscape`, `font typeface` / `data` / `bold` / `italic`, `line backslant`, `image type`, `barcode data`, `data expr`, `maxheight`, `format` as a date-parse layout on either `parameter` or `member`, `subreport ownpageno`, `columns balance` |
|
|
212
|
+
| Spellings | the `x` / `y` aliases for `left` / `top` — both examples use `left` and `top` throughout |
|
|
213
|
+
| Enumerations | barcode types `Code93`, `DataMatrix`, `QR-M`; `image scale="cut"` and `"grow"`; `dash="dash"` |
|
|
214
|
+
| Scopes | `iter="report"` / `"page"` / `"column"`; `reset="detail"` / `"item"` |
|
|
215
|
+
|
|
216
|
+
Both reference the [committed fonts](https://github.com/a1s/sr.py/tree/main/example/fonts/)
|
|
217
|
+
by path, so they build identically on any machine and work under `--strict-fonts`.
|
|
218
|
+
Swap `file=` for `typeface=` to use whatever the machine has instead.
|
|
219
|
+
|
|
220
|
+
## Reproducible output
|
|
221
|
+
|
|
222
|
+
The same template over the same data produces byte-identical printouts when
|
|
223
|
+
`--build-time` is fixed and `--strict-fonts` is set -- **on any machine**,
|
|
224
|
+
not just across runs on one. Rendering adds no timestamp of its own.
|
|
225
|
+
Without the first, the run timestamp differs; without the second,
|
|
226
|
+
output depends on which fonts are installed.
|
|
227
|
+
|
|
228
|
+
Nothing machine-specific survives in a strict printout. Strict mode admits only
|
|
229
|
+
fonts the template named by path, and every path the template named — fonts and
|
|
230
|
+
`embed=#false` images alike — is written relative to the printout rather than
|
|
231
|
+
absolute. So a printout and the files it points at move as one tree. The header
|
|
232
|
+
records which font file each typeface resolved to and by which step, so a difference
|
|
233
|
+
is diagnosable from the artifact.
|
|
234
|
+
|
|
235
|
+
## Development
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
make install # a venv, the dependencies, and the test and lint tools
|
|
239
|
+
make check # ruff, mypy, pytest
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Everything generated goes under `build/`: the pytest, ruff and mypy caches,
|
|
243
|
+
setuptools' metadata, and compiled bytecode. The first three come from
|
|
244
|
+
`pyproject.toml` and the fourth from `PYTHONPYCACHEPREFIX`, which the
|
|
245
|
+
`GNUmakefile` exports — a `pytest` typed straight into a shell still writes
|
|
246
|
+
`__pycache__` beside the sources unless that variable is exported there too.
|
|
247
|
+
|
|
248
|
+
Tests are `pytest`. `tests/unit/` covers a module at a time,
|
|
249
|
+
`tests/golden/` holds this engine to documents that are printed in the
|
|
250
|
+
specification, and `tests/differential/` compares this engine against the
|
|
251
|
+
Go one, byte for byte, over the examples and over a corpus of probes.
|
|
252
|
+
It compares the renderers too, by drawing each page of both PDFs
|
|
253
|
+
with pdfium, from the `oracles` extra, and comparing the pixels;
|
|
254
|
+
a PDF is also held to its structure by the tests' own reader,
|
|
255
|
+
and by `qpdf --check` where qpdf is on the path.
|
|
256
|
+
And it compares the command line: what `validate` reports on every
|
|
257
|
+
template in the corpus, what `inspect` dumps of every printout,
|
|
258
|
+
and the exit code, the output, and the summary line of a table
|
|
259
|
+
of command lines, each asking one question of doc/cli.md.
|
|
260
|
+
|
|
261
|
+
The engine was built a milestone at a time, and every command and
|
|
262
|
+
output format is here now. Every node the format has is built: it paginates
|
|
263
|
+
reports of `field`, `line`, `rectangle`, `image`, `barcode`, and `xref`
|
|
264
|
+
elements and outline entries, with groups, columns, band splitting,
|
|
265
|
+
`eject` nodes, keep-together rules, balanced columns, deferred values,
|
|
266
|
+
and subreports of both kinds, inline and with pages of their own,
|
|
267
|
+
and writes them as NDJSON, CBOR, or PDF. Each printout is held to its
|
|
268
|
+
own [invariants](https://github.com/a1s/sr.py/blob/main/doc/printout.md#invariants)
|
|
269
|
+
before it is written, and `s-reports inspect` holds
|
|
270
|
+
any printout it reads to them. Every barcode type is encoded here,
|
|
271
|
+
from the standards, rather than by a library, and an image
|
|
272
|
+
is interpreted only as far as the header that states its size.
|
|
273
|
+
The PDF writer is written here too: the object table and the cross
|
|
274
|
+
reference, the drawing, the outline and the links. `fontTools` subsets
|
|
275
|
+
the faces and Pillow decodes the images the file does not carry
|
|
276
|
+
as they stand. Each rendered page is drawn by pdfium and compared,
|
|
277
|
+
pixel by pixel, with the same printout rendered by the reference.
|
|
278
|
+
The command line and its two reports are held to the reference's too.
|
|
279
|
+
The cases the differential corpus cannot yet compare are listed,
|
|
280
|
+
with what each waits for, in
|
|
281
|
+
[tests/differential/pending.toml](https://github.com/a1s/sr.py/blob/main/tests/differential/pending.toml).
|
|
282
|
+
|
|
283
|
+
The Go implementation is the **oracle**: a reference binary whose *outputs*
|
|
284
|
+
settle questions the specification leaves open. Its source is not read --
|
|
285
|
+
this is a second implementation from the specification, not a port.
|
|
286
|
+
The harness builds it from a tree beside this repository, and skips
|
|
287
|
+
with a reason where there is no Go toolchain to build it with.
|
|
288
|
+
See [tests/differential/README.md](https://github.com/a1s/sr.py/blob/main/tests/differential/README.md).
|
|
289
|
+
|
|
290
|
+
Where the two engines disagree and `doc/` does not say who is right,
|
|
291
|
+
the answer is a sentence in `doc/`, not a workaround in either engine.
|
|
292
|
+
|
|
293
|
+
## License
|
|
294
|
+
|
|
295
|
+
MIT. See [LICENSE](https://github.com/a1s/sr.py/blob/main/LICENSE).
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
s_reports-0.1.0.dist-info/licenses/LICENSE,sha256=6DM0BNrtbsMnynS2Y_wcFiIP32KB0_4hL_B_AsyO5yA,1077
|
|
2
|
+
sr/__init__.py,sha256=vZmLVFRsj66C0UzAgEjLcg080glEyt-_VKV2valf26w,259
|
|
3
|
+
sr/__main__.py,sha256=MXACHLyIM53G_xG1U11IPahAukPlzrf1zHTUYSmRxaU,315
|
|
4
|
+
sr/api.py,sha256=1mUOXwoA14CbekOo2npFuVpF_wNvf2iJSSuZYGRh7q0,7015
|
|
5
|
+
sr/cli.py,sha256=UftbhIfovv7n7pHhyX0LJLr5CWayFsFmMesNSexA-wQ,56118
|
|
6
|
+
sr/color.py,sha256=H8t-hTRASPGV45GV4a9hTxGAWiEMXTLCFL0meBrKj5k,6897
|
|
7
|
+
sr/data.py,sha256=AECzbA6gLndQtXCeSB0w0clTiFpvaOk4_AAWy0TqB1M,12754
|
|
8
|
+
sr/errors.py,sha256=ri4Rd2aXO1QFkkMKp5QGwX2BaGsp_gmggu0a6J4RfsE,18426
|
|
9
|
+
sr/image.py,sha256=nw5SGymVLckp8ny1jHqLB5HfhDNqjnRQkkYNbx_59QI,11723
|
|
10
|
+
sr/kdl.py,sha256=Mn-cwiN0qqjDcVJbFXQN6BNP1I_TftpgGrs_hkh9Z90,24158
|
|
11
|
+
sr/meta.py,sha256=lDyVHTmNJGiW7huYM1EcBt-w1o9gpvV4id3LOjSfUWw,876
|
|
12
|
+
sr/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
+
sr/settle.py,sha256=29H2-jMM7EZjHRYqAyD9eYhbX0DLE-GOcnsAtpSV8ac,10147
|
|
14
|
+
sr/units.py,sha256=igp66jHx1lSep74tRNKgszT8HV-SDQpSCy5ARDJ4E4U,9151
|
|
15
|
+
sr/barcode/__init__.py,sha256=J0cCCLwcFe88PQvv_3IwtvpERMNH8LvzqpPjwFfQjCg,4221
|
|
16
|
+
sr/barcode/aztec.py,sha256=yWDT1D08_sRv_n6WryrqcNNHGn4lnl3zKgmGRG-wWqE,25521
|
|
17
|
+
sr/barcode/dmtx.py,sha256=jIA4bJjQWP6P3g9cNCQNz_07Ja7sx_rmFvj3xGQOVpo,11708
|
|
18
|
+
sr/barcode/linear.py,sha256=sB6u1pEA-4woh4eoTKU92Z48wqEQMUQbw8eL6Sg8EYw,11574
|
|
19
|
+
sr/barcode/qr.py,sha256=o8xq4XzWgbrXJgvZrecg1YUIm41ZgY-wTCz3ItoOpz4,18718
|
|
20
|
+
sr/barcode/readable.py,sha256=vDBLJhQNrqvr2Xa7M5-dPBt4OWuUeT3ifspSbVKj_0k,3943
|
|
21
|
+
sr/barcode/reedsolomon.py,sha256=gxaRPfxpRqxg74VuMlLry-rkESIEYb91JAYlHta0p_s,4556
|
|
22
|
+
sr/barcode/symbol.py,sha256=IAscJF8q70kSvbhgxE1D41ayDU7TxbemwlMggvA6BSk,4402
|
|
23
|
+
sr/expr/__init__.py,sha256=wRzIXmnwsS1-CL1yoQJapbSblF_mmrQgk-i_BZWXANg,1840
|
|
24
|
+
sr/expr/builtins.py,sha256=K8t1tngPdLiixVnUEOtDMhxukXdFEMm2vHbTDXSV9KU,48378
|
|
25
|
+
sr/expr/calc.py,sha256=nm5OzgiVZU2mhgBalYMKD5qEiDx8vets741gFCZKk88,16136
|
|
26
|
+
sr/expr/compile.py,sha256=n1oYyGVIQxVYXbTW7471L3nC6CHe9R_ejaMc363-O9M,22296
|
|
27
|
+
sr/expr/fmt.py,sha256=kg5ZaQnTXEZTwrTMTz0PjQPWo7fkwRqLj_zlR2Hmqog,18715
|
|
28
|
+
sr/expr/golayout.py,sha256=tPRZSQ0Uvf3q6cGwlGGD88hdYw3EIqAA6HnUnf6YdFA,24134
|
|
29
|
+
sr/expr/literals.py,sha256=kfETA_KFq6ysIM2GovJJ-KkP20edQS-RF_W-4NNWGJo,19192
|
|
30
|
+
sr/expr/values.py,sha256=zX59QnUgM8mAjxSBOiRn_h71yMv4jrSRyesVfV24Kjc,51635
|
|
31
|
+
sr/fonts/__init__.py,sha256=1ZkjCVzPwVO42qg2puwwGjeliD0hTQE_2Q2vIcDuGmk,1921
|
|
32
|
+
sr/fonts/face.py,sha256=H6KpRep903e1UfSAysfBmdzbYCqf03Wj_8kFg4041Zk,22943
|
|
33
|
+
sr/fonts/hostenum.py,sha256=9_b613JgmaTLhDODvPl32Pzhnd0Ikh2VCkJdQnngYxI,27211
|
|
34
|
+
sr/fonts/resolve.py,sha256=PoFn-cIjSnhTHa7WLeJPre026J1V2VCi-uRpd3wKRb8,21241
|
|
35
|
+
sr/fonts/text.py,sha256=esV5weETJK3mYNWkZdAF25ibu-OUcGOGvjb-syb4838,12889
|
|
36
|
+
sr/layout/__init__.py,sha256=D3gpALM71xNEYZl1mG2cXdZbLCFyVhec69HBD9g1fEg,2093
|
|
37
|
+
sr/layout/blobs.py,sha256=-ntjsigZTSKXcCUPHCrzNwtZfbCxQMeAwmZzJ68BTjA,6295
|
|
38
|
+
sr/layout/columns.py,sha256=Mjp8QQ3kKSc8z1f_rVYkrrCTjg2B3oqfly4Ti7KrMdQ,6506
|
|
39
|
+
sr/layout/context.py,sha256=9Duw3b9gBJvguriHyo-n5gfu8V3asIfxXykmXL-Drls,7356
|
|
40
|
+
sr/layout/defer.py,sha256=a0MP6bXp2l7HNCLkRxgkzkg4QnjwPCOjkJ_wnvcR7_4,8958
|
|
41
|
+
sr/layout/fonttable.py,sha256=IOQdA7CizAgnZSSOKR-9C7ocHlZHRHVh_7rwAcghkKw,5614
|
|
42
|
+
sr/layout/frame.py,sha256=UDHMI7UimAlR2Lwy_kudr5APkza15SD3XlqZWzwfOW8,13515
|
|
43
|
+
sr/layout/images.py,sha256=fR4vHrhNB-4Mccvle1pWIEMwXimfHQHKMtoTLMfYMfY,8852
|
|
44
|
+
sr/layout/loop.py,sha256=HqbExLX1s7iF7Q8jl8fd066fL-GvBJSQju0dUmWiKfQ,108548
|
|
45
|
+
sr/layout/measure.py,sha256=ITU0wzXgP8nKxdiG1wOzgdRXCjeZ5-_7JQHbMDGRW1U,72575
|
|
46
|
+
sr/layout/place.py,sha256=B7JRAVZo89Kr8l3gcS9-YdPto9t691VOHfS3WQliLrM,8589
|
|
47
|
+
sr/layout/subreport.py,sha256=a6Iw6DU7p4JV68Nfe4V-zjNtDrFpdl-wvDuWiUhasnQ,10224
|
|
48
|
+
sr/layout/variables.py,sha256=gIQv8hBR5d5n86ptS1DwgI8Nh9XCeofS0Cw1EhIopug,6413
|
|
49
|
+
sr/pdf/__init__.py,sha256=uSQFAc3cTGLCFZld7nXwDGTZJ1gsJMr1GKmI17iBjjM,1047
|
|
50
|
+
sr/pdf/document.py,sha256=RFttK6orXI9vGtHndJrLdQDeZ_-TRht7HSOLS5wHw20,23344
|
|
51
|
+
sr/pdf/draw.py,sha256=QAwnv1xCGx_ycJ3AnNpT9QeZUUdD-QQORM5B89OqiVI,18187
|
|
52
|
+
sr/pdf/images.py,sha256=THx_WnmFvjIykAlOe19MIuW_rl9FdEr2AxmJ7__Vomo,8818
|
|
53
|
+
sr/pdf/objects.py,sha256=tj58wTkQMTw1LPOOJJOmk04rY6_OIc7xE3Q6V4qEO0g,10267
|
|
54
|
+
sr/pdf/subset.py,sha256=cG4_6wAjnohX6ZsLg8cNejb1fecSlGuKF5UArTT7Axc,15398
|
|
55
|
+
sr/printout/__init__.py,sha256=bBbsfA4kIky99gu95qK_kySof08G4nDylCYtQ4xUCFY,1440
|
|
56
|
+
sr/printout/inspect.py,sha256=nm3IYtOiUfO9EhW_ilLLpNve1qGa0Sq1cNEGth9wlls,25730
|
|
57
|
+
sr/printout/model.py,sha256=1Vp-0ZR6FHzBbnNpikaEMOMSBcV1COKj4s_GtDPji1A,13715
|
|
58
|
+
sr/printout/read.py,sha256=M4EJLrIkdLQfV2oAeToSsE3Qz-uOtu--Uqpi6xOAMH4,21305
|
|
59
|
+
sr/printout/verify.py,sha256=Qg7Ai3g6YCZb1izpfrevSOF_e5OQm0desl-_fUJDbrs,22081
|
|
60
|
+
sr/printout/write.py,sha256=X2eLoDTfLM_2r9ymIXY-8fqcMgiMUBf4jxom_acLW2A,20422
|
|
61
|
+
sr/template/__init__.py,sha256=CIiqqD558WHYiDmH5oq1bq5NEwDpQrpmGeb2PaLRCuU,1161
|
|
62
|
+
sr/template/load.py,sha256=-khQu5q7NPbxOmCpCBIxPtIcuEHZmOs5h23KkxZrGEo,54722
|
|
63
|
+
sr/template/model.py,sha256=R3Iu1u2bCIsIF72C9qsf5fYtJO-MgyQjNTcGRdS7R6A,34990
|
|
64
|
+
sr/template/validate.py,sha256=lGgCEjoTG2Kyhez-diSUlU4gQbsDPJ2SX9482CpcdMY,44043
|
|
65
|
+
s_reports-0.1.0.dist-info/METADATA,sha256=fbGKgunXYRxlnfWyUi3Ye9wZYQhXY7YSv-7O927n2vg,14910
|
|
66
|
+
s_reports-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
67
|
+
s_reports-0.1.0.dist-info/entry_points.txt,sha256=kBwDOqyECSoSrpf4lQK70GdiGqMSS3wid9NNbGrxR8o,42
|
|
68
|
+
s_reports-0.1.0.dist-info/top_level.txt,sha256=XFzWuC7umCVdV-O6IuC9Rl0qehvEC-U34M9WJ2-2h3E,3
|
|
69
|
+
s_reports-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aleksandr Smyshliaev
|
|
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 @@
|
|
|
1
|
+
sr
|
sr/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""A banded report formatter.
|
|
2
|
+
|
|
3
|
+
Applies a template to a sequence of records and produces a paginated
|
|
4
|
+
document. See ``doc/`` for the specification this package implements.
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from . import meta
|
|
9
|
+
|
|
10
|
+
__version__ = meta.VERSION
|
|
11
|
+
__date__ = meta.DATE
|
|
12
|
+
|
|
13
|
+
__all__ = []
|
sr/__main__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Run the command line as ``python -m sr``.
|
|
2
|
+
|
|
3
|
+
The same program as the ``s-reports`` command an installed package
|
|
4
|
+
puts on the path, for an interpreter whose scripts directory is not
|
|
5
|
+
on it.
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import sys
|
|
12
|
+
|
|
13
|
+
from sr.cli import main
|
|
14
|
+
|
|
15
|
+
if __name__ == "__main__":
|
|
16
|
+
sys.exit(main())
|
sr/api.py
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"""The library surface: a template and records in, a printout out.
|
|
2
|
+
|
|
3
|
+
doc/cli.md opens by saying that the command line decides nothing --
|
|
4
|
+
every flag maps to a library option, every diagnostic comes from the
|
|
5
|
+
engine. This is the other side of that sentence. :func:`build`
|
|
6
|
+
takes the options the flags map to, and the command line's own work
|
|
7
|
+
is parsing arguments and choosing a stream.
|
|
8
|
+
|
|
9
|
+
The steps are the ones doc/cli.md#sr-build lists, in the order a
|
|
10
|
+
diagnostic reads best: load the template, settle the parameters,
|
|
11
|
+
resolve the fonts, read the records, lay them out. A parameter with
|
|
12
|
+
no value is an error here and not at `validate`, which is the one
|
|
13
|
+
place the two commands differ about the same template: a check asks
|
|
14
|
+
whether the document is well formed, and a build needs the values.
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import time
|
|
21
|
+
from dataclasses import dataclass, field
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import TextIO
|
|
24
|
+
|
|
25
|
+
from sr.data import read_records
|
|
26
|
+
from sr.errors import BuildError, BuildWarning, Diagnostic
|
|
27
|
+
from sr.expr import Time
|
|
28
|
+
from sr.expr.builtins import parse_time
|
|
29
|
+
from sr.expr.golayout import RFC3339
|
|
30
|
+
from sr.layout.loop import Build, Builder
|
|
31
|
+
from sr.printout.model import Printout
|
|
32
|
+
from sr.settle import blob_bytes, parameter_values, resolve_fonts
|
|
33
|
+
from sr.template import load as load_template
|
|
34
|
+
from sr.template.load import Options as LoadOptions
|
|
35
|
+
|
|
36
|
+
__all__ = ["Options", "Result", "build", "build_time_of"]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass(frozen=True)
|
|
40
|
+
class Options:
|
|
41
|
+
"""What a build takes besides the template and the data.
|
|
42
|
+
|
|
43
|
+
Attributes:
|
|
44
|
+
params: ``--param`` values, by name, as text.
|
|
45
|
+
build_time: What fixes ``BUILD_TIME``, as RFC 3339.
|
|
46
|
+
strict_fonts: Resolve only fonts the template names by path.
|
|
47
|
+
strict_names: Refuse an unknown node or property.
|
|
48
|
+
accepted: Names to take without a warning.
|
|
49
|
+
allow_overflow: Record an oversized band as a warning.
|
|
50
|
+
verbose: Collect the host font diagnostics, which are
|
|
51
|
+
about the machine rather than the document and are
|
|
52
|
+
asked for rather than produced.
|
|
53
|
+
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
params: dict[str, str] = field(default_factory=dict)
|
|
57
|
+
build_time: str | None = None
|
|
58
|
+
strict_fonts: bool = False
|
|
59
|
+
strict_names: bool = False
|
|
60
|
+
accepted: frozenset[str] = frozenset()
|
|
61
|
+
allow_overflow: bool = False
|
|
62
|
+
verbose: bool = False
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@dataclass(frozen=True)
|
|
66
|
+
class Result:
|
|
67
|
+
"""What a build produced.
|
|
68
|
+
|
|
69
|
+
Attributes:
|
|
70
|
+
printout: The document.
|
|
71
|
+
warnings: What the run had to say about the document,
|
|
72
|
+
which is what the header carries.
|
|
73
|
+
notes: What it had to say about the template,
|
|
74
|
+
which the header does not carry: a diagnostic with
|
|
75
|
+
no [kind](doc/printout.md#header-line) is about
|
|
76
|
+
the document that was written rather than about
|
|
77
|
+
the one that was read, and belongs on standard error.
|
|
78
|
+
diagnostics: What enumerating the host's fonts had to say,
|
|
79
|
+
under ``verbose`` and only where enumeration happened at all.
|
|
80
|
+
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
printout: Printout
|
|
84
|
+
warnings: tuple[BuildWarning, ...] = ()
|
|
85
|
+
notes: tuple[Diagnostic, ...] = ()
|
|
86
|
+
diagnostics: tuple[str, ...] = ()
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def build(
|
|
90
|
+
template: Path | str,
|
|
91
|
+
data: Path | str | TextIO | None = None,
|
|
92
|
+
options: Options | None = None,
|
|
93
|
+
) -> Result:
|
|
94
|
+
"""Apply a template to data and return the printout.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
template: The template file.
|
|
98
|
+
data: The records, as a path or an open stream;
|
|
99
|
+
``None`` for a template that runs over no records at all.
|
|
100
|
+
options: What the run asks for; the defaults otherwise.
|
|
101
|
+
|
|
102
|
+
Raises:
|
|
103
|
+
TemplateError: The template did not load or did not validate.
|
|
104
|
+
BuildError: A font did not resolve, a parameter has no value,
|
|
105
|
+
a record will not coerce, or a band will not fit.
|
|
106
|
+
|
|
107
|
+
"""
|
|
108
|
+
asked = options or Options()
|
|
109
|
+
loaded = load_template(
|
|
110
|
+
Path(template),
|
|
111
|
+
LoadOptions(accepted=asked.accepted, strict=asked.strict_names),
|
|
112
|
+
)
|
|
113
|
+
report = loaded.require()
|
|
114
|
+
built = build_time_of(asked.build_time)
|
|
115
|
+
parameters = parameter_values(report, asked.params, built)
|
|
116
|
+
blobs = blob_bytes(report, parameters)
|
|
117
|
+
(fonts, resolver) = resolve_fonts(report, blobs, strict=asked.strict_fonts)
|
|
118
|
+
records = read_records(data, report.records) if data is not None else ()
|
|
119
|
+
# A font's own warnings stay on its resolution: the builder carries
|
|
120
|
+
# them only for the fonts the document turns out to use.
|
|
121
|
+
warnings = tuple(carried(one) for one in loaded.warnings if one.kind is not None)
|
|
122
|
+
builder = Builder(
|
|
123
|
+
Build(
|
|
124
|
+
report=report,
|
|
125
|
+
records=tuple(records),
|
|
126
|
+
parameters=parameters,
|
|
127
|
+
fonts=fonts,
|
|
128
|
+
blobs=blobs,
|
|
129
|
+
built=built,
|
|
130
|
+
strict_fonts=asked.strict_fonts,
|
|
131
|
+
allow_overflow=asked.allow_overflow,
|
|
132
|
+
warnings=warnings,
|
|
133
|
+
resolver=resolver,
|
|
134
|
+
)
|
|
135
|
+
)
|
|
136
|
+
printout = builder.run()
|
|
137
|
+
notes = tuple(one for one in loaded.warnings if one.kind is None)
|
|
138
|
+
# Read after the build, since a subreport resolves its fonts when it runs.
|
|
139
|
+
diagnostics = resolver.diagnostics if asked.verbose else ()
|
|
140
|
+
return Result(printout, printout.warnings, notes, diagnostics)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def build_time_of(given: str | None) -> Time:
|
|
144
|
+
"""Return the run's ``BUILD_TIME``, in UTC.
|
|
145
|
+
|
|
146
|
+
The zone is not the caller's to choose. A `--build-time`
|
|
147
|
+
carrying an offset names an instant, and the instant is
|
|
148
|
+
what the run has; reading it anywhere else is what
|
|
149
|
+
``.in_location`` is for. The header's `built` field
|
|
150
|
+
is that instant written RFC 3339, so two machines in
|
|
151
|
+
different zones building one template with one
|
|
152
|
+
`--build-time` write one byte sequence.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
given: What ``--build-time`` supplied, or ``None`` for now.
|
|
156
|
+
|
|
157
|
+
Raises:
|
|
158
|
+
BuildError: The value is not an RFC 3339 timestamp.
|
|
159
|
+
|
|
160
|
+
"""
|
|
161
|
+
if given is None:
|
|
162
|
+
return Time(time.time_ns())
|
|
163
|
+
try:
|
|
164
|
+
return Time(parse_time(given, RFC3339).nanos)
|
|
165
|
+
except BuildError:
|
|
166
|
+
raise
|
|
167
|
+
except Exception as refused:
|
|
168
|
+
raise BuildError(f"--build-time: not an RFC 3339 time: {given!r}") from refused
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def carried(diagnostic: Diagnostic) -> BuildWarning:
|
|
172
|
+
"""Return a load warning as the printout header carries it.
|
|
173
|
+
|
|
174
|
+
Only a diagnostic that carries one of the four
|
|
175
|
+
[kinds](doc/printout.md#header-line) belongs in the header.
|
|
176
|
+
The rest are about the template rather than about the document --
|
|
177
|
+
a band that collapses to nothing is the example -- and they are
|
|
178
|
+
said on standard error, where the person editing the template is.
|
|
179
|
+
|
|
180
|
+
A warning raised while the template was read has no record index,
|
|
181
|
+
because no data had been read when it was found.
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
diagnostic: What the load had to say.
|
|
185
|
+
|
|
186
|
+
"""
|
|
187
|
+
where = diagnostic.location
|
|
188
|
+
assert diagnostic.kind is not None
|
|
189
|
+
return BuildWarning(
|
|
190
|
+
diagnostic.kind,
|
|
191
|
+
diagnostic.message,
|
|
192
|
+
node=str(where.path) if where.path else None,
|
|
193
|
+
prop=where.prop,
|
|
194
|
+
)
|