Skip to content

Settings foundation: Context model + build_context() - #161

Merged
coordt merged 6 commits into
mainfrom
156-settings-context-model
Aug 16, 2026
Merged

Settings foundation: Context model + build_context()#161
coordt merged 6 commits into
mainfrom
156-settings-context-model

Conversation

@coordt

@coordt coordt commented Aug 16, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds Context (pydantic-settings-backed) and build_context() to wiki_toolkit/settings.py, resolving docs_dir, repo_root, branch_prefix, batch_byte_cap, batch_file_cap through a five-tier precedence chain: CLI flag > WIKI_TOOLKIT_<UPPER_SNAKE> env var > dedicated .wiki-toolkit.toml > pyproject.toml's [tool.wiki_toolkit] table > built-in default, with per-field source tracking.
  • Resolution never raises: a malformed file, a missing table, or an invalid field value (non-positive batch cap, empty branch_prefix) falls through to the next tier — and a bad field no longer takes its valid siblings in the same tier down with it (found and fixed during code review; BaseSettings.model_validate() was re-triggering the source pipeline instead of validating a plain dict).
  • resolve_docs_dir() is left in place unchanged; cli.py/doctor.py/write_gate.py/batches.py are untouched — later tickets swap callers over.

Closes #156, part of #154.

Test plan

  • uv run pytest — 256 passed
  • uv run ruff check / uv run mypy clean
  • Manually exercised flag/env/dedicated-file/pyproject/default precedence and malformed/invalid-value fallback paths

coordt added 2 commits August 16, 2026 06:24
Adds a five-tier precedence chain (flag > env > .wiki-toolkit.toml >
pyproject.toml > default) for docs_dir, repo_root, branch_prefix,
batch_byte_cap, and batch_file_cap, with per-field source tracking.
Resolution never raises: malformed files or invalid field values fall
through to the next tier. resolve_docs_dir() is left in place for
existing callers; later tickets swap them over.

Part of #154, closes #156.
model_validate() on a BaseSettings subclass re-triggers its full source
pipeline (env/pyproject), so a partial dict with the bad field dropped
was still getting the original invalid value merged back in from the
live environment/file. Each per-tier settings class now restricts
settings_customise_sources to init kwargs only, since the raw dict is
already fetched explicitly via the source objects beforehand.

Addresses a code-review finding on 156-settings-context-model.
@github-actions

Copy link
Copy Markdown
Contributor

Version hint: minor
Current version: 0.27.0
New version (when merged): 0.28.0

Comment ID: Display version hint-auto-generated

@github-actions

github-actions Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://callowayproject.github.io/wiki-toolkit/pr-preview/pr-161/

Built to branch gh-pages at 2026-08-16 12:17 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

coordt added 4 commits August 16, 2026 06:52
Relative env-tier paths (docs_dir/repo_root) now resolve against cwd
like every other tier, unreadable config files fall through instead
of crashing, and a spurious pydantic-settings warning is suppressed.
Also consolidates the duplicated pyproject/dedicated-file resolution
logic that resolve_docs_dir() and build_context() had drifted apart
on, and removes several smaller code duplications flagged in review.
@coordt
coordt merged commit a74a956 into main Aug 16, 2026
7 checks passed
@coordt
coordt deleted the 156-settings-context-model branch August 16, 2026 12:19
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.

Settings foundation: Context model + build_context()

1 participant