Skip to content

Editing plugin blocks in the config file (M5 part 2b-1) - #244

Merged
txoof merged 8 commits into
mainfrom
238-config-edit
Oct 7, 2026
Merged

txoof merged 8 commits into
mainfrom
238-config-edit

Conversation

@txoof-bot

Copy link
Copy Markdown
Collaborator

Part of #238 (M5 part 2b-1). Built on #241 (part 2a): merge #241 first; this PR then moves to main by itself.

What changed

The code the web interface uses to change [[plugin]] blocks in the config file. The pages that use it come in part 2b-2 (next PR).

  • New src/paperpi/web/config_file.py: move a block up or down, remove it, switch it on or off, add a new one at the end of the plugin list.
  • It works on the file's text, one block at a time, not with tomlkit. tomlkit counts the comment lines just above a [[plugin]] line as part of the block before it, so they would move with the wrong plugin. Here those comments (when a blank line is above them) belong to the block below them, move with it, and are removed with it.
  • Every change is read back with Python's TOML reader and compared with the old settings plus the change. A file written in a way this code doesn't understand is never saved wrongly; it gives the message "change this in the config file itself".
  • Each change names its block by place and name, so a block that was moved or renamed by hand meanwhile is not changed by mistake.
  • Saving keeps the file's permissions (and owner when run as root), follows a link to the real file, refuses a file larger than PaperPi reads, and holds one lock from read to save. The password save (save_password_hash) now uses the same read, save and lock, so a password change and a plugin change at the same moment can't undo each other.
  • Lines are split only at \n, like TOML (Python's splitlines() also splits at U+2028 and others). Windows line endings are kept. Plugin names now also refuse U+0085, U+2028 and U+2029, which Python counts as line breaks. The config check's line numbers use the same rule.
  • docs/decisions/config-format.md: note on why plugin blocks are changed as text.

Choices I made without asking:

  • A comment on the same line as enabled = is lost when a plugin is switched on or off (switching on removes the line, since the file only holds non-defaults).
  • Moving the last block can add one blank line at the end of the file (it does not keep growing).

Area

web (src/paperpi/web/), core (src/paperpi/plugin.py name check, src/paperpi/config.py line numbers), docs.

Tests

New tests/test_web_config_file.py (16 tests): comments move with their block, [plugin.x] parts move too, other parts ([web]) stay, edge of the list, changed meanwhile, unusual headers refused, enabled inside a string or a [plugin.x] part is not the switch, Windows line endings, no last line break, U+2028 inside values, size limit, permissions. Name check test in tests/test_example.py.

  • uv run pytest passes (1139 tests on this branch)
  • uv run ruff check . passes
  • Hardware tests: not needed (no display code)

Review

  • Review agents' comments answered: four reviews (code quality, tests, security, docs) ran locally before the first push; their fixes are the second commit ("Review fixes: ..."). Nothing left open.

Only txoof approves and merges this PR.

🤖 Generated with Claude Code

txoof-bot and others added 4 commits October 7, 2026 15:46
Plugins can mark a setting as required with paperpi.plugin.setting(...,
required=True). A switched-on plugin that is missing one is not shown and
not counted as broken; the config check warns and paperpi list shows
"needs <settings>". met_no and moon_phase require lat, lon and email
(met.no's terms of service ask for a real email address); the example
config no longer fills in a made-up address.

Part of #238

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Part of #238.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	src/paperpi/plugins/default/README.md
#	src/paperpi/plugins/default/__init__.py
#	src/paperpi/scheduler.py
@txoof-bot txoof-bot mentioned this pull request Oct 7, 2026
4 tasks done
…ettings

# Conflicts:
#	src/paperpi/plugins/splash_screen/README.md
#	src/paperpi/scheduler.py
Base automatically changed from 238-required-settings to main October 7, 2026 18:38
@txoof
txoof merged commit 8615aeb into main Oct 7, 2026
4 checks passed
@txoof
txoof deleted the 238-config-edit branch October 7, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants