Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@

## Unreleased

- **Fixed:** a failed build in `ddtools golden check` or `golden update` now prints
`error: Build failed in <script>:` on stderr, like `build`, instead of `Build failed in ...`
on stdout. The 0.3.0 notes already said this. Scripts that read stdout for it need to read stderr.

- **Fixed:** repos made by `ddtools init` no longer tell you to install `fonts-dejavu-core`,
and their CI no longer installs it. The fonts have come with the package since 0.3.0.
- **Fixed:** the README install line, the `--json` note, the `check --pdf-dir` flag and the
must-pass checks (`mypy` was missing) now match the code.

## 0.3.0

- **Deprecated:** `config.stamp`, `config.date_stamp` and `config.present` now warn with
`DeprecationWarning` and name the function that replaces them; they go in 1.0.
- **Changed:** `config.is_gone(member)` is the one test for a teammate who has left; `Document.audience`
is typed `Audience` (`private`, `party` or `dm`).
- **Fixed:** `ddtools preview --pages` with a bad value (`x`, `0`, `3-1`) is now a usage
error (exit 2), not a traceback. `ddtools watch` reports a sheet that is not an object
in its errors, as it does for other odd shapes.
error (exit 2), not a traceback.
- **Changed:** the last per-command error handlers are gone: `main()` reports every
`DdtoolsError` and `OSError` as `error: <message>` on stderr. A failed `build` now reads
`DdtoolsError` and `OSError` once, as `error: <message>` on stderr (exit code 1).
Messages that used to go to stdout (bad snapshots, missing folders, `Build failed in ...`
from `build` and `golden`, `sheet-text` problems, unknown blueprint) are now on stderr, so
scripts that read stdout for them need to read stderr. A failed `build` reads
`error: Build failed in <script>:` followed by the script's output. The `golden capture`
usage message goes to stderr (still exit 2). `report.run_watch` raises `ConfigError`
for a bad character folder instead of printing it.
Expand All @@ -30,8 +39,6 @@
and they use `level_updated_label` instead of `stamp`. The PDFs are the same. The
`dnd-campaign-template` repo's copies change to match `ddtools init`.
- **Removed:** `ddtools.sheettext.status`. Use `field_status`.
- **Deprecated:** `stamp`, `date_stamp` and `present` in `ddtools.config` will be removed in
1.0. Use `level_updated_label`, `updated_label` and `is_present`.
- **Changed:** the secrets code (`Secret`, `SpoilerHit`, `clean`, `load_secrets`,
`find_spoilers`) moved from `ddtools.checks` to a new `ddtools.secrets`, which imports no
PDF code, so `sheettext` and `lifecycle` no longer load PDF rendering. A missing secrets
Expand All @@ -43,10 +50,6 @@
types, and a `script` that stays inside the character folder) and the `retired:` block,
and raises `ConfigError` naming the entry, not a `TypeError`. `add_party_member` raises
`ConfigError` for an entry without a name, not a `KeyError`.
- **Changed:** every command prints a `DdtoolsError` once, as `error: <message>` on stderr
(exit code 1), caught in `main()`. Messages that used to go to stdout (bad snapshots,
missing folders, `Build failed in ...`, `sheet-text` problems, unknown blueprint) are now on
stderr, so scripts that read stdout for them need to read stderr.
- **Changed:** `DuplicateCommandError` is a `DdtoolsError` (still a `ValueError`).
- **Fixed:** `watch` reports a sheet with an unexpected shape, or a bad `party.json`, in its
errors list instead of raising.
Expand Down Expand Up @@ -82,7 +85,8 @@
traceback. A party member's `name` must be text: write `name: "1984"` (or `"No"`) in
quotes, or `load_character` reports which `campaign.party` entry is wrong.
- **Changed:** clearer names in `ddtools.config` for build scripts. The old names still
work, so existing build scripts need no change.
work, so existing build scripts need no change, but they now warn with
`DeprecationWarning` and name the function that replaces them.

| Old | New |
|---|---|
Expand Down Expand Up @@ -114,7 +118,6 @@
Registering a taken name directly raises `DuplicateCommandError`.
- **Changed:** `ddtools.plugins` no longer imports `ddtools.cli`. The private
`ddtools.cli._COMMANDS` list is gone; use `ddtools.registry.COMMANDS`.
- **Changed:** `ddtools.sheettext.status` is now `field_status`. The old name still works.

## 0.2.0

Expand Down
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

## Rules

- **TDD.** Write the failing test first. `pytest` and `ruff check . && ruff format --check .`
must pass before any push.
- **TDD.** Write the failing test first. `pytest`, `ruff check . && ruff format --check .`
and `mypy` must pass before any push.
- **Tests use made-up characters** (`tests/conftest.py`, `make_campaign`) and
`tests/fixtures/`. Never a real character's sheet, secrets or names, and never a call
to D&D Beyond.
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- Write the test first, then the change (`pytest`).
- Tests use made-up characters and `tests/fixtures/`. Never a real character, and never a
call to D&D Beyond.
- `ruff check .` and `ruff format --check .` must be clean.
- `ruff check .`, `ruff format --check .` and `mypy` must be clean.
- A change to `ddtools.pdfstyle` changes every campaign's PDFs: say so in the PR.
- Update `README.md` and `CHANGELOG.md` if needed.

Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ secret and a spell that isn't on the sheet into the party handout, and `check` f
Python 3.12 or later. The DejaVu fonts the documents use come with the package.

```bash
pip install "ddtools @ git+https://github.com/modem7/ddtools.git@v0.2.0"
pip install "ddtools @ git+https://github.com/modem7/ddtools.git@v0.3.0"
ddtools --version
```

Every command has `--help`. Commands that report data take `--json`.
Every command has `--help`. `list`, `diff` and `watch` also take `--json`.

## Start a campaign repo

Expand All @@ -68,7 +68,7 @@ Every command has `--help`. Commands that report data take `--json`.
| Command | What it does |
|---|---|
| `ddtools build <dir> [--out DIR]` | Runs each document script listed in `<dir>/character.yaml`. Writes the PDFs (and a `.txt` copy of each) to `<dir>/pdf/`, or to `--out`. Stops at the first failing script, names it and prints its error. |
| `ddtools check <dir>` | Checks every `audience: party` document. **Spoilers:** any entry from `secrets.txt`, ignoring case and curly quotes, even if it's split across lines. **Spells:** any spell not on the latest snapshot, unless its sentence has a level label ("at level 4", "(level 8+)"), it sits under a `future_sections` heading, or it's in `spell_ignore`. Exits 1 if it finds anything. |
| `ddtools check <dir> [--pdf-dir DIR]` | Checks every `audience: party` document, reading the PDFs in `--pdf-dir` instead of `<dir>/pdf` if given. **Spoilers:** any entry from `secrets.txt`, ignoring case and curly quotes, even if it's split across lines. **Spells:** any spell not on the latest snapshot, unless its sentence has a level label ("at level 4", "(level 8+)"), it sits under a `future_sections` heading, or it's in `spell_ignore`. Exits 1 if it finds anything. |
| `ddtools preview <dir> [--pdf NAME] [--pages A-B]` | Renders pages to `tmp/preview-<name>.png` so the layout can be checked by eye. |
| `ddtools golden update <dir>` | Rebuilds and records a new golden baseline in `tests/golden/<dir>/`. Only use it when a change was intended, and commit it with that change. |
| `ddtools golden check <dir>` | Rebuilds and compares with the baseline. Exits 1 on any difference. |
Expand Down Expand Up @@ -237,12 +237,13 @@ Unknown top-level keys in `character.yaml` are kept in `Character.extra` for plu

![desloppify scorecard](docs/images/scorecard.png)

Code health as scored by desloppify at 0.3.0 (strict 78.6 of 100).
Code health of ddtools 0.3.0, as scored by desloppify v1.0 (strict 78.6 of 100).

```bash
pip install -r requirements-dev.txt
pytest
ruff check . && ruff format --check .
mypy
```

- Tests use made-up characters (`tests/conftest.py`) and `tests/fixtures/`. They never
Expand Down
23 changes: 8 additions & 15 deletions src/ddtools/golden.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,16 @@ def compare(
def record_character(ch: Character, dest: PathLike, rebuild: bool) -> int:
"""Capture a baseline for every document, from a fresh build or the committed PDFs.

Prints one line per document (and a warning per heading not found). Returns 1 if
the build fails, else 0.
Prints one line per document (and a warning per heading not found). A failed build
raises ``BuildError``, which ``main`` prints once on stderr and turns into exit 1.
"""
from ddtools.build import BuildError, build_character
from ddtools.build import build_character

with tempfile.TemporaryDirectory() as tmp:
pdf_dir = ch.dir / "pdf"
if rebuild:
pdf_dir = Path(tmp)
try:
build_character(ch.dir, pdf_dir)
except BuildError as err:
print(f"Build failed in {err.script}:\n{err.stderr}")
return 1
build_character(ch.dir, pdf_dir)
for doc in ch.documents:
stem = Path(doc.file).stem
data = capture(pdf_dir / f"{stem}.pdf", doc.source(ch.dir), dest, name=stem)
Expand All @@ -233,10 +229,11 @@ def record_character(ch: Character, dest: PathLike, rebuild: bool) -> int:
def check_character(ch: Character, dest: PathLike) -> int:
"""Rebuild into a temporary folder and compare every document with its baseline.

Prints one line per document. Returns 1 if the build fails or anything differs.
Prints one line per document. Returns 1 if anything differs. A failed build raises
``BuildError``, which ``main`` prints once on stderr and turns into exit 1.
No baseline folder yet is not a failure.
"""
from ddtools.build import BuildError, build_character
from ddtools.build import build_character

dest = Path(dest)
if not dest.is_dir():
Expand All @@ -246,11 +243,7 @@ def check_character(ch: Character, dest: PathLike) -> int:
)
return 0
with tempfile.TemporaryDirectory() as tmp:
try:
build_character(ch.dir, Path(tmp))
except BuildError as err:
print(f"Build failed in {err.script}:\n{err.stderr}")
return 1
build_character(ch.dir, Path(tmp))
failed = False
for doc in ch.documents:
stem = Path(doc.file).stem
Expand Down
2 changes: 1 addition & 1 deletion src/ddtools/repo_template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ddtools import-workbook filled.pdf Name
ddtools build Name && ddtools check Name
```

DejaVu fonts are required (`sudo apt-get install fonts-dejavu-core`). Every command:
The DejaVu fonts come with ddtools. Every command:
`ddtools --help`.

## Layout
Expand Down
2 changes: 0 additions & 2 deletions src/ddtools/repo_template/dot-github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ jobs:
- uses: actions/setup-python@v7.1.0
with:
python-version: "3.15"
- name: Install fonts
run: sudo apt-get update && sudo apt-get install -y fonts-dejavu-core
- name: Install ddtools
run: pip install -r requirements.txt
- name: Build, check and compare every active character
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ def test_golden_check_matches_and_differs(golden_char, monkeypatch, capsys):
def test_golden_build_failure(golden_char, monkeypatch, capsys, action):
_run(capsys, ["golden", "capture", str(golden_char), "--from-committed"])
_fake_build(monkeypatch, fail=True)
want = "Build failed in src/build_doc.py:\nboom\n"
assert _run(capsys, ["golden", action, str(golden_char)]) == (1, want, "")
want = "error: Build failed in src/build_doc.py:\nboom\n"
assert _run(capsys, ["golden", action, str(golden_char)]) == (1, "", want)


def test_golden_bad_folder(tmp_path, capsys):
Expand Down
Loading