readwright 0.3.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.
@@ -0,0 +1,21 @@
1
+ {% block header %}{% include "partials/header.md.j2" %}{% endblock %}
2
+
3
+ {% block badges %}{% include "partials/badges.md.j2" %}{% block badges_extra %}{% endblock +%}
4
+ {% endblock %}
5
+
6
+ {% block donate %}{% include "partials/donate.md.j2" %}{% block donate_extra %}{% endblock +%}
7
+ {% endblock %}
8
+
9
+ {% block toc %}{% endblock %}
10
+
11
+ {% block screenshots %}{% include "partials/screenshots.md.j2" %}{% endblock %}
12
+
13
+ {% block install %}{% include "partials/install.md.j2" %}{% endblock %}
14
+
15
+ {% block usage %}{% include "partials/usage.md.j2" %}{% endblock %}
16
+
17
+ {% block extra %}{% endblock %}
18
+
19
+ {% block contributing %}{% include "partials/contributing.md.j2" %}{% endblock %}
20
+
21
+ {% block license %}{% include "partials/license.md.j2" %}{% endblock %}
@@ -0,0 +1 @@
1
+ {{ badges() -}}
@@ -0,0 +1,7 @@
1
+ ## Contributing
2
+
3
+ {% if project.url %}
4
+ Issues and pull requests are welcome at [{{ project.owner }}/{{ project.repo }}]({{ project.url }}).
5
+ {% else %}
6
+ Issues and pull requests are welcome.
7
+ {% endif %}
@@ -0,0 +1 @@
1
+ {{ donate_badges() -}}
@@ -0,0 +1,10 @@
1
+ {% set hero = banner() %}
2
+ {% if hero %}
3
+ {{ hero }}
4
+
5
+ {% endif %}
6
+ # {{ project.name }}
7
+
8
+ {% if project.tagline %}
9
+ {{ project.tagline }}
10
+ {% endif %}
@@ -0,0 +1,46 @@
1
+ ## Installation
2
+
3
+ {% if project.project_type == "python" and project.pypi %}
4
+ ```sh
5
+ pip install {{ project.pypi }}
6
+ ```
7
+
8
+ Or with [uv](https://docs.astral.sh/uv/):
9
+
10
+ ```sh
11
+ uv tool install {{ project.pypi }}
12
+ ```
13
+ {% elif project.project_type == "node" and project.npm %}
14
+ ```sh
15
+ npm install {{ project.npm }}
16
+ ```
17
+ {% elif project.project_type == "rust" and project.crate %}
18
+ ```sh
19
+ cargo install {{ project.crate }}
20
+ ```
21
+ {% elif project.project_type == "go" and project.go_module %}
22
+ ```sh
23
+ go install {{ project.go_module }}@latest
24
+ ```
25
+ {% elif project.project_type == "dotnet" and project.nuget %}
26
+ ```sh
27
+ dotnet tool install --global {{ project.nuget }}
28
+ ```
29
+ {% elif project.project_type == "minecraft-mod" %}
30
+ Download the latest release from the [releases page]({{ project.url ~ "/releases/latest" if project.url else "#" }})
31
+ and drop the jar into your `mods` folder{% if project.minecraft_version %} (Minecraft {{ project.minecraft_version }}){% endif %}.
32
+ {% elif project.project_type == "flow-plugin" %}
33
+ In [Flow Launcher](https://www.flowlauncher.com/), type:
34
+
35
+ {{ flow_install_cmd() }}
36
+ {% elif project.project_type == "hacs" %}
37
+ Install through [HACS](https://hacs.xyz/){% if project.url %} by adding `{{ project.owner }}/{{ project.repo }}` as a custom repository{% endif %},
38
+ then add the resource to your dashboard.
39
+ {% elif project.url %}
40
+ ```sh
41
+ git clone {{ project.url }}.git
42
+ cd {{ project.repo }}
43
+ ```
44
+ {% else %}
45
+ Clone the repository and follow the instructions in the source tree.
46
+ {% endif %}
@@ -0,0 +1,5 @@
1
+ {% if project.license %}
2
+ ## License
3
+
4
+ {{ project.license }}
5
+ {% endif %}
@@ -0,0 +1,5 @@
1
+ {% if has_screenshots() %}
2
+ ## Screenshots
3
+
4
+ {{ screenshots() }}
5
+ {% endif %}
@@ -0,0 +1,5 @@
1
+ {% if vars.usage is defined %}
2
+ ## Usage
3
+
4
+ {{ vars.usage }}
5
+ {% endif %}
readwright/toc.py ADDED
@@ -0,0 +1,60 @@
1
+ """Table-of-contents generation from rendered markdown headings."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ from collections import Counter
7
+
8
+ TOC_PREFIX = "<!-- readwright:toc"
9
+ TOC_TOKEN = f"{TOC_PREFIX} -->"
10
+ TOC_ANY = re.compile(r"<!-- readwright:toc(?: (?P<min>\d) (?P<max>\d))? -->")
11
+ HEADING = re.compile(r"^(#{1,6})\s+(.+?)\s*#*\s*$")
12
+ FENCE = re.compile(r"^\s*(```|~~~)")
13
+ SLUG_STRIP = re.compile(r"[^\w\- ]", re.UNICODE)
14
+
15
+
16
+ def toc_token(min_level: int = 2, max_level: int = 3) -> str:
17
+ return f"{TOC_PREFIX} {min_level} {max_level} -->"
18
+
19
+
20
+ def github_slug(title: str) -> str:
21
+ cleaned = SLUG_STRIP.sub("", title.strip().lower())
22
+ return cleaned.replace(" ", "-")
23
+
24
+
25
+ def _headings(markdown: str) -> list[tuple[int, str]]:
26
+ found: list[tuple[int, str]] = []
27
+ in_fence = False
28
+ for line in markdown.splitlines():
29
+ if FENCE.match(line):
30
+ in_fence = not in_fence
31
+ continue
32
+ if in_fence:
33
+ continue
34
+ if match := HEADING.match(line):
35
+ found.append((len(match.group(1)), match.group(2).strip()))
36
+ return found
37
+
38
+
39
+ def build_toc(markdown: str, min_level: int = 2, max_level: int = 3) -> str:
40
+ seen: Counter[str] = Counter()
41
+ lines = []
42
+ for level, title in _headings(markdown):
43
+ if not min_level <= level <= max_level:
44
+ continue
45
+ slug = github_slug(title)
46
+ count = seen[slug]
47
+ seen[slug] += 1
48
+ anchor = f"{slug}-{count}" if count else slug
49
+ lines.append(f"{' ' * (level - min_level)}- [{title}](#{anchor})")
50
+ return "\n".join(lines)
51
+
52
+
53
+ def insert_toc(markdown: str) -> str:
54
+ match = TOC_ANY.search(markdown)
55
+ if not match:
56
+ return markdown
57
+ min_level = int(match["min"]) if match["min"] else 2
58
+ max_level = int(match["max"]) if match["max"] else 3
59
+ before, after = markdown[: match.start()], markdown[match.end() :]
60
+ return before + build_toc(after, min_level, max_level) + after
@@ -0,0 +1,188 @@
1
+ Metadata-Version: 2.5
2
+ Name: readwright
3
+ Version: 0.3.0
4
+ Summary: Render GitHub READMEs from Jinja2 templates with badge and screenshot helpers
5
+ Project-URL: Homepage, https://github.com/Garulf/readwright
6
+ Project-URL: Issues, https://github.com/Garulf/readwright/issues
7
+ Author-email: Garulf <535299+Garulf@users.noreply.github.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: badges,jinja2,markdown,readme,shields
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: Topic :: Documentation
16
+ Classifier: Topic :: Software Development :: Documentation
17
+ Requires-Python: >=3.11
18
+ Requires-Dist: jinja2>=3.1
19
+ Requires-Dist: pydantic>=2.7
20
+ Requires-Dist: pyyaml>=6.0
21
+ Requires-Dist: rich>=13.0
22
+ Requires-Dist: tomli-w>=1.2.0
23
+ Requires-Dist: typer>=0.12
24
+ Requires-Dist: watchfiles>=1.2.0
25
+ Description-Content-Type: text/markdown
26
+
27
+ <!-- generated by readwright from README.md.j2; edit the template, not this file -->
28
+ # readwright
29
+
30
+ Render GitHub READMEs from Jinja2 templates with badge and screenshot helpers.
31
+
32
+ [![PyPI](https://img.shields.io/pypi/v/readwright)](https://pypi.org/project/readwright/) [![Python](https://img.shields.io/pypi/pyversions/readwright)](https://pypi.org/project/readwright/) [![License](https://img.shields.io/github/license/Garulf/readwright)](https://github.com/Garulf/readwright/blob/main/LICENSE) [![CI](https://img.shields.io/github/actions/workflow/status/Garulf/readwright/ci.yml)](https://github.com/Garulf/readwright/actions/workflows/ci.yml) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
33
+
34
+ - [Installation](#installation)
35
+ - [Quick start](#quick-start)
36
+ - [Template helpers](#template-helpers)
37
+ - [Configuration](#configuration)
38
+ - [pre-commit and GitHub Actions](#pre-commit-and-github-actions)
39
+ - [Contributing](#contributing)
40
+ - [License](#license)
41
+
42
+ ## Installation
43
+
44
+ ```sh
45
+ pip install readwright
46
+ ```
47
+
48
+ Or with [uv](https://docs.astral.sh/uv/):
49
+
50
+ ```sh
51
+ uv tool install readwright
52
+ ```
53
+
54
+ ## Quick start
55
+
56
+ ```sh
57
+ cd my-repo
58
+ readwright init # writes readme.yaml + README.md.j2 (autodetects owner/repo, name, license, ...)
59
+ readwright render # writes README.md (--watch to re-render on change, -o - for stdout)
60
+ readwright check # exit 1 with a diff if README.md is stale (use as a pre-commit hook / in CI)
61
+ readwright badges # list badge presets
62
+ readwright blocks # list overridable blocks and partials
63
+ readwright show partials/install.md.j2 # print a packaged template to copy and tweak
64
+ ```
65
+
66
+ Already have a README? `readwright init --from-readme` moves its body into the template so nothing is
67
+ lost, then takes over `README.md`. Prefer `pyproject.toml`? `readwright init --pyproject` writes the config
68
+ to `[tool.readme]`.
69
+
70
+ `README.md.j2` extends the packaged `base.md.j2` and overrides only what it needs:
71
+
72
+ ```jinja
73
+ {% extends "base.md.j2" %}
74
+
75
+ {% block usage %}
76
+ ## Usage
77
+
78
+ {{ screenshot("main", width=600) }}
79
+
80
+ Run `{{ project.name }} --help`.
81
+ {% endblock %}
82
+ ```
83
+
84
+ See [`examples/`](https://github.com/Garulf/readwright/tree/main/examples) for a kitchen-sink project using every helper,
85
+ plus Minecraft mod, HACS card and Flow Launcher plugin examples.
86
+
87
+ ## Template helpers
88
+
89
+ | Helper | Result |
90
+ | --- | --- |
91
+ | `badge("pypi")`, `badge("ci", workflow="test.yml")` | Preset badge built from repo metadata |
92
+ | `shield("Discord", "chat", "5865F2", link=...)` | Custom shields.io static badge |
93
+ | `badges()` / `donate_badges()` | All badges from `badges:` / `donate:` in config |
94
+ | `screenshot("main", alt=..., width=...)` | Finds `docs/screenshots/main.{png,jpg,gif,webp,svg}`; `main-dark.*` + `main-light.*` become a theme-aware pair |
95
+ | `screenshots(columns=2)` | Gallery table of every image in the screenshots dir |
96
+ | `image("path/or/url", "alt", width=...)` | Explicit image, no discovery |
97
+ | `screenshots(order=[...], captions={...}, subdir=...)` | Control gallery order/captions (or drop a `captions.yaml` in the folder) |
98
+ | `toc()`, `toc(1, 2)` | Table of contents from the headings below it (min/max level) |
99
+ | `changelog(n=1)` | Newest `n` entries of `CHANGELOG.md` |
100
+ | `project.*`, `vars.*` | Repo metadata and free-form config values |
101
+ | `cli_help("mytool --help")` | Runs the command and fences its output (needs `allow_exec: true`) |
102
+ | `include_file(path)`, `code_block(path)`, `snippet(path, start, end)` | Pull a file, a fenced file, or a marked region into the README |
103
+ | `config_table(path, section=...)`, `env_table(".env.example")`, `entry_points_table()` | Markdown tables from YAML/TOML/JSON, env files, `[project.scripts]` |
104
+ | `gh_link("issues", "Issues")`, `spdx_link()`, `my_ha_link("hacs_repository", owner=..., repository=...)` | Repo-relative GitHub links, SPDX license link, My Home Assistant buttons |
105
+ | `callout("tip", text)`, `details(summary, body)`, `center(html)`, `columns([...])` | GitHub alerts, collapsibles, centered blocks, side-by-side cells |
106
+ | `logo(width=120)`, `video("demo")`, `contributors([...])` | Theme-aware logo from `docs/logo.*`, video/gif embed, avatar grid |
107
+ | `unsplash("photo-1518…", credit="Name", user="handle", width=1000, height=280)` | Hero image from Unsplash's CDN with the required attribution line; `banner:` in config puts one above the title |
108
+ | `flow_install_cmd()`, `mc_versions()`, `mod_dependencies()`, `related_repos()` | Flow Launcher / Minecraft mod / related-repo tables |
109
+ | `git_sha()`, `git_tag()`, `today()` | Build metadata (these change between renders, so `check` will flag them) |
110
+
111
+ To add a badge to the top row without touching the config list, fill the `badges_extra` hook (there is a
112
+ `donate_extra` too):
113
+
114
+ ```jinja
115
+ {% block badges_extra %} {{ shield("docs", "latest", "success", link=gh_link("wiki")) }}{% endblock %}
116
+ ```
117
+
118
+ Badge presets: `pypi`, `pypi-downloads`, `python`, `license`, `ci`, `codecov`, `npm`, `github-release`,
119
+ `github-stars`, `pre-commit`, `ruff`, `version`, `modrinth`, `curseforge`, `hacs`, `ha-version`, plus donation presets `kofi`, `buymeacoffee`, `github-sponsors`,
120
+ `patreon`, `paypal`. Add your own under `badges_custom`; set `badges_style: flat-square` (or pass
121
+ `style=` to any badge helper) to restyle them all.
122
+
123
+ Blocks in `base.md.j2`: `header`, `badges`, `donate`, `toc`, `screenshots`, `install`, `usage`, `extra`,
124
+ `contributing`, `license`. Any packaged partial can be shadowed by a file of the same name under
125
+ `templates/partials/` in the repo (or `~/.config/readwright/templates/` for all your repos).
126
+
127
+ Image helpers emit plain markdown by default (dark/light pairs use GitHub's
128
+ `#gh-light-mode-only`/`#gh-dark-mode-only` fragments instead of `<picture>`), and only fall back to HTML
129
+ when you ask for something markdown can't do, like a `width=`. Set `screenshots.style: html` to always
130
+ get `<img>`/`<picture>`/`<table>` output, or pass `html=True` to `unsplash()`/`banner:`.
131
+
132
+ ## Configuration
133
+
134
+ `readme.yaml` in the repo root (or `[tool.readme]` in `pyproject.toml`); see
135
+ [`examples/config-only/readme.yaml`](https://github.com/Garulf/readwright/blob/main/examples/config-only/readme.yaml) for every key,
136
+ annotated. Everything is optional;
137
+ metadata is autodetected from the git remote, the `LICENSE` file and whichever manifest the project
138
+ has: `pyproject.toml`, `package.json`, `Cargo.toml`, `go.mod`, `*.csproj`, Gradle (`gradle.properties`
139
+ mod metadata for Minecraft mods), `hacs.json` or a Flow Launcher `plugin.json`. The install section
140
+ adapts to the project type.
141
+
142
+ ```yaml
143
+ template: README.md.j2
144
+ templates: [../shared-readme-templates, "pkg:my_org_templates"] # extra template search paths
145
+ output: README.md
146
+ strict: false # missing screenshot -> error instead of warning
147
+ allow_exec: false # let cli_help() run commands during render
148
+ badges_style: flat-square # optional shields.io style for every badge
149
+ related: [{repo: other-tool, description: Sibling project}] # for related_repos()
150
+ banner: {unsplash: photo-1518770660439-4636190af475, credit: Alexandre Debiève, user: alexkixa}
151
+ screenshots: {dir: docs/screenshots, width: 720, style: markdown} # style: html for width/alignment
152
+ badges: [pypi, python, license, {preset: ci, workflow: test.yml}, {shield: {label: Docs, message: latest, color: success}}]
153
+ badges_custom:
154
+ discord: {label: Discord, message: chat, color: 5865F2, link: https://discord.gg/xyz}
155
+ donate: [kofi, github-sponsors]
156
+ donate_handles: {kofi: yourname, github-sponsors: yourname}
157
+ project: {name: ..., owner: ..., repo: ..., tagline: ..., pypi: ..., npm: ..., license: ..., ci_workflow: ...}
158
+ vars: {anything: you like}
159
+ ```
160
+
161
+ Put the values you repeat across repos (donation handles, owner, custom badges) in
162
+ `~/.config/readwright/config.yaml`; `readwright init` bakes them into each new `readme.yaml` so rendering
163
+ stays reproducible in CI. `readwright render --user-config` merges them ad hoc.
164
+
165
+ ## pre-commit and GitHub Actions
166
+
167
+ ```yaml
168
+ # .pre-commit-config.yaml
169
+ - repo: https://github.com/Garulf/readwright
170
+ rev: v0.3.0
171
+ hooks:
172
+ - id: readwright-check
173
+ ```
174
+
175
+ ```yaml
176
+ # .github/workflows/ci.yml
177
+ - uses: Garulf/readwright@v0.3.0
178
+ with:
179
+ mode: check # or render
180
+ ```
181
+
182
+ ## Contributing
183
+
184
+ Issues and pull requests are welcome at [Garulf/readwright](https://github.com/Garulf/readwright).
185
+
186
+ ## License
187
+
188
+ MIT
@@ -0,0 +1,25 @@
1
+ readwright/__init__.py,sha256=HaXVzfv6KcWFsLaJPHypg_mZeISc5A7ydYsxQA2XXjI,214
2
+ readwright/badges.py,sha256=vE4cXgI3Zau19rhM-qgcKJoKve_71AypZzpm_WgYF1Y,9898
3
+ readwright/changelog.py,sha256=O48rB0pQD1Mh3kEHDbalOEIAl-3SNXpOVR7aNRip2t8,1529
4
+ readwright/cli.py,sha256=FfPLfzuStjt4NvSJiBs4_KHCISUz94Zk_lLdsvBDwe0,13401
5
+ readwright/config.py,sha256=-L8OC_knksAGG3ORZ8TMTZSzYr4SXP26OhZs_4I-jl4,7226
6
+ readwright/helpers.py,sha256=R0RJDWFtn0ncqG8n6BtZeRL0jJQdggbDteKyp-tP-pY,19458
7
+ readwright/images.py,sha256=curlWYn4Xo7Nbg_h-pNKxldVuxy5NkJOZyv2Fmy90uM,8251
8
+ readwright/metadata.py,sha256=QQM8mjNsjUp6ehwkEOZvhaKd9kbl3gV0Gk9Pqb3y-DA,8903
9
+ readwright/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ readwright/renderer.py,sha256=4iVMQKvzfUdDv0gJBB0t2aWPglp38Cj0PSqLkufJgfo,6307
11
+ readwright/toc.py,sha256=oGsWLbmtif-M3yZQs1abtGXaXbqaCKTOsF-4Olu8R5g,1952
12
+ readwright/templates/base.md.j2,sha256=ch8eH2sFAArMTDUi1F5rKUuGW9YSYl2oP9swtCSroSE,735
13
+ readwright/templates/partials/badges.md.j2,sha256=m6Z1_q9jEm8eJ81Gx74pGJttYLNA8wHUJ4wybYvDDbo,16
14
+ readwright/templates/partials/contributing.md.j2,sha256=8853IRNvgBERHkmYQhZBdSRjtIb3c2laFdaJPDSocWA,200
15
+ readwright/templates/partials/donate.md.j2,sha256=K1TbEtzJ4LhcHAEam5tyi4ssjSDvISWoq82g7kczsSI,23
16
+ readwright/templates/partials/header.md.j2,sha256=OVQ1li9nLUFx3reJJwT1pVIQPQ3fZzni3XxYHq6HQy4,145
17
+ readwright/templates/partials/install.md.j2,sha256=Ae7K12msy0JHLKkkRBovPpyg2nTaRVYF4pcH-EBFGSw,1484
18
+ readwright/templates/partials/license.md.j2,sha256=sUzggovdgtZOtjHAHjLtBVQjL7aPjwwA05q5dL5pb6U,71
19
+ readwright/templates/partials/screenshots.md.j2,sha256=nprlIDKHyenVS81cajlbIOH1GXzgV_0gAsC4kdDw01E,75
20
+ readwright/templates/partials/usage.md.j2,sha256=Hq5j8xjkRVf2DnEsYZldLSEyF7z4HOyAjKHmt6y7Hzs,70
21
+ readwright-0.3.0.dist-info/METADATA,sha256=ru5zN8OKG-_RgxwOvc3e2Mj9_OQ8WDhqDuW2X0iQK4g,9536
22
+ readwright-0.3.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
23
+ readwright-0.3.0.dist-info/entry_points.txt,sha256=0ZMlTqX7wSLP9IJQWCxeGHapWofxf-yQAYpEHtn7pVY,50
24
+ readwright-0.3.0.dist-info/licenses/LICENSE,sha256=xeDKZZcHQHHbqoXnQ-2V__i7DdZGKhlpCOiVmPDTauE,1063
25
+ readwright-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ readwright = readwright.cli:app
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Garulf
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.