auto-html-report 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.
Files changed (49) hide show
  1. auto_html_report-0.1.0/LICENSE +202 -0
  2. auto_html_report-0.1.0/PKG-INFO +387 -0
  3. auto_html_report-0.1.0/README.md +355 -0
  4. auto_html_report-0.1.0/pyproject.toml +80 -0
  5. auto_html_report-0.1.0/pyproject.toml.orig +76 -0
  6. auto_html_report-0.1.0/src/auto_html_report/__init__.py +141 -0
  7. auto_html_report-0.1.0/src/auto_html_report/_naming.py +35 -0
  8. auto_html_report-0.1.0/src/auto_html_report/_version.py +29 -0
  9. auto_html_report-0.1.0/src/auto_html_report/application/__init__.py +1 -0
  10. auto_html_report-0.1.0/src/auto_html_report/application/collect_blocks.py +161 -0
  11. auto_html_report-0.1.0/src/auto_html_report/application/context.py +65 -0
  12. auto_html_report-0.1.0/src/auto_html_report/application/discovery.py +319 -0
  13. auto_html_report-0.1.0/src/auto_html_report/application/execution.py +533 -0
  14. auto_html_report-0.1.0/src/auto_html_report/application/ports.py +199 -0
  15. auto_html_report-0.1.0/src/auto_html_report/blocks/__init__.py +14 -0
  16. auto_html_report-0.1.0/src/auto_html_report/blocks/maintenance_history.py +76 -0
  17. auto_html_report-0.1.0/src/auto_html_report/blocks/wafer_map.py +64 -0
  18. auto_html_report-0.1.0/src/auto_html_report/domain/__init__.py +6 -0
  19. auto_html_report-0.1.0/src/auto_html_report/domain/block.py +98 -0
  20. auto_html_report-0.1.0/src/auto_html_report/domain/errors.py +46 -0
  21. auto_html_report-0.1.0/src/auto_html_report/domain/event.py +39 -0
  22. auto_html_report-0.1.0/src/auto_html_report/domain/report.py +126 -0
  23. auto_html_report-0.1.0/src/auto_html_report/exit_codes.py +69 -0
  24. auto_html_report-0.1.0/src/auto_html_report/generate.py +151 -0
  25. auto_html_report-0.1.0/src/auto_html_report/infrastructure/__init__.py +1 -0
  26. auto_html_report-0.1.0/src/auto_html_report/infrastructure/clock.py +27 -0
  27. auto_html_report-0.1.0/src/auto_html_report/infrastructure/factories.py +148 -0
  28. auto_html_report-0.1.0/src/auto_html_report/infrastructure/logging_setup.py +161 -0
  29. auto_html_report-0.1.0/src/auto_html_report/infrastructure/settings.py +265 -0
  30. auto_html_report-0.1.0/src/auto_html_report/infrastructure/stores/__init__.py +7 -0
  31. auto_html_report-0.1.0/src/auto_html_report/infrastructure/stores/postgres_store.py +426 -0
  32. auto_html_report-0.1.0/src/auto_html_report/infrastructure/stores/sqlite_store.py +408 -0
  33. auto_html_report-0.1.0/src/auto_html_report/infrastructure/writers/__init__.py +1 -0
  34. auto_html_report-0.1.0/src/auto_html_report/infrastructure/writers/_names.py +30 -0
  35. auto_html_report-0.1.0/src/auto_html_report/infrastructure/writers/local_writer.py +100 -0
  36. auto_html_report-0.1.0/src/auto_html_report/infrastructure/writers/s3_writer.py +136 -0
  37. auto_html_report-0.1.0/src/auto_html_report/processing.py +469 -0
  38. auto_html_report-0.1.0/src/auto_html_report/py.typed +0 -0
  39. auto_html_report-0.1.0/src/auto_html_report/registry.py +164 -0
  40. auto_html_report-0.1.0/src/auto_html_report/rendering/__init__.py +5 -0
  41. auto_html_report-0.1.0/src/auto_html_report/rendering/cells.py +170 -0
  42. auto_html_report-0.1.0/src/auto_html_report/rendering/escaping.py +64 -0
  43. auto_html_report-0.1.0/src/auto_html_report/rendering/figures.py +116 -0
  44. auto_html_report-0.1.0/src/auto_html_report/rendering/shell.py +121 -0
  45. auto_html_report-0.1.0/src/auto_html_report/rendering/templates/report.css +197 -0
  46. auto_html_report-0.1.0/src/auto_html_report/rendering/templates/report.html.j2 +54 -0
  47. auto_html_report-0.1.0/src/auto_html_report/reports/__init__.py +6 -0
  48. auto_html_report-0.1.0/src/auto_html_report/reports/manufacturing.py +67 -0
  49. auto_html_report-0.1.0/src/auto_html_report/testing.py +93 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,387 @@
1
+ Metadata-Version: 2.4
2
+ Name: auto-html-report
3
+ Version: 0.1.0
4
+ Summary: Dynamic HTML report generator: composable blocks, concurrent collection, one file.
5
+ Keywords: html,report,report-generator,matplotlib,ci
6
+ Author: hanku4u
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: Topic :: Text Processing :: Markup :: HTML
18
+ Classifier: Typing :: Typed
19
+ Requires-Dist: jinja2>=3.1,<4
20
+ Requires-Dist: matplotlib>=3.7,<4
21
+ Requires-Dist: numpy>=1.24,<3
22
+ Requires-Dist: psycopg[binary]>=3.1,<4 ; extra == 'postgres'
23
+ Requires-Dist: boto3>=1.28,<2 ; extra == 's3'
24
+ Requires-Python: >=3.11
25
+ Project-URL: Homepage, https://github.com/hanku4u/auto-html-report
26
+ Project-URL: Documentation, https://github.com/hanku4u/auto-html-report/tree/main/docs
27
+ Project-URL: Issues, https://github.com/hanku4u/auto-html-report/issues
28
+ Project-URL: Changelog, https://github.com/hanku4u/auto-html-report/blob/main/CHANGELOG.md
29
+ Provides-Extra: postgres
30
+ Provides-Extra: s3
31
+ Description-Content-Type: text/markdown
32
+
33
+ # auto_html_report
34
+
35
+ `auto_html_report` turns a set of small Python classes into **one self-contained HTML report** — a single
36
+ file you can attach to a ticket, publish from a CI job, or open on a machine with no network.
37
+
38
+ The report is one table with three columns:
39
+
40
+ | Item | Data | Check |
41
+ | --- | --- | --- |
42
+ | Deployment | Python 3.11.9, linux | |
43
+ | Maintenance history — T-104 | a table of recent maintenance events | |
44
+ | Wafer map — L1001 | an embedded PNG chart | |
45
+
46
+ Each row is contributed by a **block**: a class that knows how to gather one piece of information
47
+ (`collect()`) and how to render it as HTML (`render()`). The Check column is deliberately empty: it is a
48
+ placeholder for a human reviewer's sign-off. The document is static — nothing writes to that column,
49
+ and v1 ships no JavaScript — so you print it or annotate it outside the browser.
50
+
51
+ The framework does the parts that are tedious to get right in every job script:
52
+
53
+ - blocks run **concurrently**, each with its own timeout and retry budget;
54
+ - a block that fails becomes an **error cell**; the rest of the report still renders;
55
+ - row order is deterministic, matching the order you listed the blocks in;
56
+ - the finished document is genuinely **self-contained** — inline CSS, charts embedded as base64 PNG
57
+ data URIs, no JavaScript, no external requests.
58
+
59
+ It is a library, not a service: there is no CLI. Report definitions and job scripts are ordinary
60
+ Python, and the scheduled runner is your existing CI system.
61
+
62
+ ## Quick start
63
+
64
+ You need Python 3.11 or newer. In a checkout, [uv](https://docs.astral.sh/uv/) provisions it for you.
65
+
66
+ ```bash
67
+ git clone https://github.com/hanku4u/auto-html-report.git
68
+ cd auto-html-report
69
+ uv sync --frozen
70
+ uv run python examples/quick_start.py /tmp/report-demo
71
+ ```
72
+
73
+ That writes `quick-start__<timestamp>.html` into `/tmp/report-demo`. Open it in a browser: one row,
74
+ filled by a block that reads nothing but the local interpreter, so the example runs anywhere.
75
+
76
+ Here is the whole program ([`examples/quick_start.py`](https://github.com/hanku4u/auto-html-report/blob/main/examples/quick_start.py)):
77
+
78
+ ```python
79
+ import sys
80
+ from pathlib import Path
81
+
82
+ from auto_html_report import (
83
+ Block,
84
+ ExitCode,
85
+ LocalDirectoryWriter,
86
+ RenderContext,
87
+ ReportContext,
88
+ ReportDefinition,
89
+ Settings,
90
+ generate_report,
91
+ html_table,
92
+ new_report_context,
93
+ )
94
+
95
+
96
+ class DeploymentBlock(Block[list[tuple[str, str]]]):
97
+ """One row of facts about this machine's Python, gathered without I/O."""
98
+
99
+ display_name = "Deployment"
100
+
101
+ def collect(self, context: ReportContext) -> list[tuple[str, str]]:
102
+ return [
103
+ ("Python", sys.version.split()[0]),
104
+ ("Platform", sys.platform),
105
+ ]
106
+
107
+ def render(self, data: list[tuple[str, str]], context: RenderContext) -> str:
108
+ # html_table() escapes every cell, which is the one thing a block author must not forget.
109
+ return html_table(headers=["Key", "Value"], rows=data)
110
+
111
+
112
+ def main(output_dir: Path) -> ExitCode:
113
+ settings = Settings(output_dir=output_dir)
114
+ definition = ReportDefinition(title="Quick start", blocks=[DeploymentBlock()])
115
+ result = generate_report(
116
+ definition,
117
+ context=new_report_context(settings),
118
+ writer=LocalDirectoryWriter(settings.output_dir),
119
+ )
120
+ # A writer was supplied, so the result carries where the document landed.
121
+ assert result.location is not None
122
+ print(f"wrote {result.location.uri}")
123
+ return ExitCode.SUCCESS
124
+
125
+
126
+ if __name__ == "__main__":
127
+ sys.exit(main(Path(sys.argv[1]) if len(sys.argv) > 1 else Path("reports")))
128
+ ```
129
+
130
+ Swap that `collect()` for an HTTP call — or any other I/O — and the rest of the program is unchanged.
131
+ That is the entire extension model.
132
+
133
+ ## Installation
134
+
135
+ The distribution is named `auto-html-report`; the import name is `auto_html_report`.
136
+
137
+ ```bash
138
+ pip install auto-html-report
139
+ # or, in a uv-managed project
140
+ uv add auto-html-report
141
+ ```
142
+
143
+ Both extras are optional:
144
+
145
+ ```bash
146
+ pip install "auto-html-report[s3]"
147
+ uv add "auto-html-report[postgres,s3]"
148
+ ```
149
+
150
+ To try an unreleased commit, install from git, pinned to a tag or SHA:
151
+
152
+ ```bash
153
+ pip install "auto_html_report @ git+https://github.com/hanku4u/auto-html-report.git@<tag-or-sha>"
154
+ ```
155
+
156
+ Pin it rather than following a branch: uv and pip both cache git sources, so an unpinned `@main` can
157
+ serve a stale package. When you genuinely need a moving ref, force a refresh with `uv add --refresh ...` or
158
+ `pip install --force-reinstall --no-cache-dir ...`.
159
+
160
+ The extras select the optional backends: `s3` for uploading reports instead of writing them locally,
161
+ `postgres` for a shared event store instead of SQLite. Both are optional — the defaults need neither,
162
+ and `import auto_html_report` works without them. An S3 writer bounds its upload timeouts itself, because the
163
+ processing job does not wait for it with a deadline.
164
+
165
+ ## Writing a block
166
+
167
+ A block subclasses `auto_html_report.Block[DataT]` and implements two methods:
168
+
169
+ - **`collect(self, context: ReportContext) -> DataT`** — the I/O phase. It may call an API, read a
170
+ database, or compute something local.
171
+ - **`render(self, data: DataT, context: RenderContext) -> str`** — the pure phase. It returns the
172
+ **inner HTML of the Data cell**, not a `<td>` and not a document.
173
+
174
+ Here is the built-in maintenance block
175
+ ([`src/auto_html_report/blocks/maintenance_history.py`](https://github.com/hanku4u/auto-html-report/blob/main/src/auto_html_report/blocks/maintenance_history.py)),
176
+ trimmed to the essentials:
177
+
178
+ ```python
179
+ from dataclasses import dataclass
180
+
181
+ from auto_html_report import (
182
+ Block,
183
+ RenderContext,
184
+ ReportContext,
185
+ TransientBlockError,
186
+ html_table,
187
+ )
188
+
189
+
190
+ @dataclass(frozen=True, slots=True)
191
+ class MaintenanceRecord:
192
+ performed_at: str
193
+ engineer: str
194
+ summary: str
195
+
196
+
197
+ class MaintenanceHistoryBlock(Block[list[MaintenanceRecord]]):
198
+ display_name = "Maintenance history"
199
+ timeout_seconds = 30.0
200
+
201
+ def __init__(self, *, tool_id: str, days: int = 30, name: str | None = None) -> None:
202
+ super().__init__(name=name or f"Maintenance history — {tool_id}")
203
+ self._tool_id = tool_id
204
+ self._days = days
205
+
206
+ def collect(self, context: ReportContext) -> list[MaintenanceRecord]:
207
+ payload = context.http.get_json(
208
+ f"/maintenance/{self._tool_id}",
209
+ params={"days": self._days},
210
+ # The block's effective budget: its own override, else the setting.
211
+ timeout=self.timeout_seconds or context.settings.block_timeout_seconds,
212
+ )
213
+ if payload.get("status") == "degraded":
214
+ raise TransientBlockError("maintenance service degraded; retry later")
215
+ return [MaintenanceRecord(**row) for row in payload["records"]]
216
+
217
+ def render(self, data: list[MaintenanceRecord], context: RenderContext) -> str:
218
+ if not data:
219
+ return '<p class="ai-empty">No maintenance recorded in this window.</p>'
220
+ return html_table(
221
+ headers=["Date", "Engineer", "Summary"],
222
+ rows=[(record.performed_at, record.engineer, record.summary) for record in data],
223
+ )
224
+ ```
225
+
226
+ The rules that matter:
227
+
228
+ - **Every HTTP call goes through `context.http` and passes `timeout=`.** The framework cannot interrupt
229
+ a running thread, so a call without a timeout can outlive its own budget. Pass the block's effective
230
+ budget, as above — not the global default.
231
+ - **Classify failures.** Raise `TransientBlockError` for retryable conditions (a 503, a degraded
232
+ service) and `PermanentBlockError` for the rest (a 404, a payload shape a retry will not improve).
233
+ Anything else is treated as permanent by default.
234
+ - **`render()` is pure** — no I/O, no clock, no randomness, no logging. It gets the value its own
235
+ `collect()` returned and must not raise.
236
+ - **Escape anything from outside the process.** Use `escape()` for text,
237
+ `html_table(headers=..., rows=...)` for tables (it escapes every cell), and `figure_to_data_uri()`
238
+ for matplotlib charts. Skipping this is an HTML injection bug, not a cosmetic one.
239
+ - **Set `display_name`**, or pass `name=...` when instantiating, to fill the Item column. Names must be
240
+ unique within a report; `ReportDefinition` rejects duplicates when you build it.
241
+
242
+ Blocks run concurrently, with a per-attempt timeout, retries with backoff, and failure isolation: a
243
+ block that times out or raises produces an error cell and the other rows still render. One flaky API
244
+ does not cost you the report.
245
+
246
+ Read [`docs/02-block-authoring.md`](https://github.com/hanku4u/auto-html-report/blob/main/docs/02-block-authoring.md) for the full contract, the HTTP error
247
+ mapping, and the timeout accounting rules.
248
+
249
+ ## Reports that scale with discovered data
250
+
251
+ Generating one report is a function call. Generating *a report per failed lot, every hour* is a job —
252
+ and that is what the two-phase model is for. The two phases share only an event store (SQLite in v1),
253
+ so either can fail, be re-run, or run on a different schedule without affecting the other.
254
+
255
+ 1. **Discovery** — one or more `Discoverer` subclasses yield `Event`s from an API; `run_discovery()`
256
+ persists them. Saving is insert-only and idempotent, so re-running over a rolling API window
257
+ reports duplicates instead of redoing work.
258
+ 2. **Processing** — `run_processing()` takes pending events, looks up the report factory registered for
259
+ each event type, builds and writes one report per event, and records where it landed. An event is
260
+ marked delivered only after the write succeeds.
261
+
262
+ Both return a run object. `exit_code_for(run)` maps it to an exit code your CI job can branch on:
263
+
264
+ | Code | Meaning |
265
+ | --- | --- |
266
+ | `0` | Everything succeeded. |
267
+ | `1` | Partial failure — at least one event or block failed, but reports were produced. |
268
+ | `2` | Configuration error, e.g. a report factory for an event type was never imported. |
269
+ | `3` | The event store failed. |
270
+ | `4` | A report could not be written. |
271
+
272
+ The two demo scripts show the whole pipeline against canned fixtures:
273
+
274
+ ```bash
275
+ uv run python -m examples.discover_wafers # persists two WAFER_FAILURE events
276
+ uv run python -m examples.process_events # writes one report per event
277
+ ```
278
+
279
+ The second script's first import is load-bearing:
280
+
281
+ ```python
282
+ import auto_html_report.reports.manufacturing # importing registers the factory
283
+ ```
284
+
285
+ Importing the module registers the `WAFER_FAILURE` factory. Forget it and every event of that type is
286
+ skipped and the run exits `2` — loudly, which is the point.
287
+
288
+ Running both writes two reports, each with a wafer-map chart and a maintenance-history table, into
289
+ `./reports` by default.
290
+
291
+ `-m` rather than the script path: running the file directly puts `examples/` on `sys.path` instead of
292
+ the repository root, and the shared fixtures in `examples.demo_api` would not import.
293
+
294
+ `examples/demo_api.py` supplies the fixtures through `auto_html_report.testing.StubHttpClient`, which
295
+ answers every `get_json()` call from a fixture table. The package ships **no real HTTP client**: you write
296
+ a small adapter for the `HttpClient` protocol and pass it as `http=`, and a block that needs a client when
297
+ none was given fails in its own cell with an error saying so.
298
+ [`docs/02-block-authoring.md`](https://github.com/hanku4u/auto-html-report/blob/main/docs/02-block-authoring.md) §5.2 has a recipe.
299
+
300
+ See [`docs/05-discovery-and-processing.md`](https://github.com/hanku4u/auto-html-report/blob/main/docs/05-discovery-and-processing.md) for the job model,
301
+ throughput settings, and worked job scripts.
302
+
303
+ ## Configuration
304
+
305
+ Configuration comes from environment variables only — parsed once into a frozen `Settings` object, with
306
+ no config file and no flags. These are the ones a job normally sets:
307
+
308
+ | Variable | Default | What it does |
309
+ | --- | --- | --- |
310
+ | `AUTO_HTML_REPORT_OUTPUT_KIND` | `local` | `local` or `s3`; `s3` also needs `AUTO_HTML_REPORT_OUTPUT_S3_BUCKET`. |
311
+ | `AUTO_HTML_REPORT_OUTPUT_DIR` | `./reports` | Directory the local writer writes into. |
312
+ | `AUTO_HTML_REPORT_EVENT_STORE` | `sqlite` | `sqlite` or `postgres`; `postgres` also needs `AUTO_HTML_REPORT_POSTGRES_DSN`. |
313
+ | `AUTO_HTML_REPORT_POSTGRES_DSN` | — | The PostgreSQL DSN, password included; `sslmode=require` (or `verify-full`) for a shared database. |
314
+ | `AUTO_HTML_REPORT_OUTPUT_S3_BUCKET` | — | Bucket for `AUTO_HTML_REPORT_OUTPUT_KIND=s3`; required for S3. |
315
+ | `AUTO_HTML_REPORT_OUTPUT_S3_PREFIX` | `""` | Key prefix under the bucket. |
316
+ | `AUTO_HTML_REPORT_OUTPUT_S3_TIMEOUT_SECONDS` | `30` | S3 connect/read timeout (capped at 300). |
317
+ | `AUTO_HTML_REPORT_OUTPUT_S3_SSE` | — | `AES256`, `aws:kms` or `aws:kms:dsse`; omitted means the bucket default. |
318
+ | `AUTO_HTML_REPORT_SQLITE_PATH` | `<output_dir>/events.sqlite3` | Event store location. |
319
+ | `AUTO_HTML_REPORT_LOG_LEVEL` | `INFO` | `DEBUG`, `INFO`, `WARNING`, `ERROR` or `CRITICAL`. |
320
+ | `AUTO_HTML_REPORT_LOG_FORMAT` | `json` | `json` for log shippers, `console` for humans. |
321
+ | `AUTO_HTML_REPORT_MAX_WORKERS` | `8` | In-flight blocks per report (capped at 64). |
322
+ | `AUTO_HTML_REPORT_MAX_CONCURRENT_REPORTS` | `1` | Reports built in parallel per run (capped at 32); raises in-flight HTTP calls, so size it against the API. |
323
+ | `AUTO_HTML_REPORT_BLOCK_TIMEOUT_SECONDS` | `60` | Per-attempt budget for one block. |
324
+ | `AUTO_HTML_REPORT_BLOCK_RETRIES` | `2` | Retries after the first attempt (capped at 10). |
325
+ | `AUTO_HTML_REPORT_PROCESSING_LIMIT` | `500` | Events one processing run takes from the queue (capped at 10,000). |
326
+ | `AUTO_HTML_REPORT_FAIL_ON_BLOCK_ERROR` | `true` | Treat a failed block as a failed event, so the run exits non-zero. |
327
+
328
+ Invalid values are reported together in one `ConfigurationError`, not one typo per CI run.
329
+
330
+ The full table — every variable, its `Settings` attribute, type and bound — is
331
+ [`docs/07-configuration-and-logging.md`](https://github.com/hanku4u/auto-html-report/blob/main/docs/07-configuration-and-logging.md) §1.1.
332
+
333
+ ## Development
334
+
335
+ A checkout uses [uv](https://docs.astral.sh/uv/) for the interpreter and dependencies:
336
+
337
+ ```bash
338
+ uv sync --frozen --all-extras # install the pinned environment, extras included
339
+ uv lock --check # lockfile agrees with pyproject.toml
340
+ uv run ruff check # lint
341
+ uv run ruff format --check # formatting
342
+ uv run mypy # types, strict
343
+ uv run pytest # tests
344
+ ```
345
+
346
+ `.github/workflows/ci.yml` runs exactly these commands in this order on Python 3.11 to 3.14, so a green
347
+ local run on your interpreter is a good predictor of green CI — no service to start, and no network beyond
348
+ fetching the pinned packages. CI also runs the suite at the oldest dependency versions the package allows,
349
+ exercises the PostgreSQL store against a real server, and scans the git history for secrets.
350
+
351
+ One more check catches what a source-tree test cannot:
352
+
353
+ ```bash
354
+ ./scripts/check_install.sh
355
+ ```
356
+
357
+ It builds the wheel, installs it into a scratch environment, and runs the quick start from a directory
358
+ that is not the repository. A template missing from the wheel or a package directory the build backend
359
+ did not infer fails there instead of at first report. CI also installs the package from a git URL pinned
360
+ to the commit — the same form as the Installation section, using `file://` for the checked-out tree so a
361
+ private repository needs no token.
362
+
363
+ Runtime dependencies are declared as ranges in `pyproject.toml`, and everything is pinned in the committed
364
+ `uv.lock` for this repository's own environments. Change a dependency, run `uv lock` in the same commit, or
365
+ `uv lock --check` will fail.
366
+
367
+ ## Status
368
+
369
+ v1 is complete: stages 1–11 of [`docs/11-implementation-plan.md`](https://github.com/hanku4u/auto-html-report/blob/main/docs/11-implementation-plan.md).
370
+ Local directory output and SQLite are the defaults; the `s3` and `postgres` extras are implemented and
371
+ optional. There is no built-in API client: blocks and discoverers are written against the `HttpClient`
372
+ protocol, and you supply the implementation.
373
+
374
+ ## Where to look
375
+
376
+ | If you want to… | Read |
377
+ | --- | --- |
378
+ | Understand what the tool does and does not do | [`docs/01-overview.md`](https://github.com/hanku4u/auto-html-report/blob/main/docs/01-overview.md) |
379
+ | Write a block | [`docs/02-block-authoring.md`](https://github.com/hanku4u/auto-html-report/blob/main/docs/02-block-authoring.md) |
380
+ | Run discovery and processing jobs | [`docs/05-discovery-and-processing.md`](https://github.com/hanku4u/auto-html-report/blob/main/docs/05-discovery-and-processing.md) |
381
+ | Configure it | [`docs/07-configuration-and-logging.md`](https://github.com/hanku4u/auto-html-report/blob/main/docs/07-configuration-and-logging.md) |
382
+ | Know why a design decision was made | [`docs/10-decision-log.md`](https://github.com/hanku4u/auto-html-report/blob/main/docs/10-decision-log.md) |
383
+ | See what is built and what is next | [`docs/11-implementation-plan.md`](https://github.com/hanku4u/auto-html-report/blob/main/docs/11-implementation-plan.md) |
384
+
385
+ ## License
386
+
387
+ Apache-2.0; see [`LICENSE`](https://github.com/hanku4u/auto-html-report/blob/main/LICENSE). Release notes are in [`CHANGELOG.md`](https://github.com/hanku4u/auto-html-report/blob/main/CHANGELOG.md).