Skip to content

feat: Replace Example[T] generation with markdown-based example docs#19

Merged
EspenAlbert merged 17 commits into
mainfrom
t07-46-examples-nav-and-inline-links
Feb 24, 2026
Merged

feat: Replace Example[T] generation with markdown-based example docs#19
EspenAlbert merged 17 commits into
mainfrom
t07-46-examples-nav-and-inline-links

Conversation

@EspenAlbert

@EspenAlbert EspenAlbert commented Feb 24, 2026

Copy link
Copy Markdown
Owner

feat: Replace Example[T] generation with markdown-based example docs

What

Overhaul pkg-ext's example documentation system: remove the Example[T] Pydantic subclass generation machinery and replace it with markdown-based example docs validated by pytest-examples. Also clean up dead code left behind and add changelog tooling for rebasing and PR stacking.

Changes

t07-40: Remove Example[T] generation

  • Deleted example_gen.py module and its tests
  • Removed gen-examples CLI command
  • Removed examples_enabled, examples_exclude config fields and all associated filtering/rendering methods
  • Removed examples_file_path from PkgSettings and generate_examples_for_groups from pre_change workflow
  • Kept examples_include on GroupConfig as the source of truth for which symbols need example docs

t07-41: Add gen-example-prompt and check-examples commands

  • gen-example-prompt: builds an AI prompt from API dump data (signatures, docstrings, related types, test code) for symbols missing example docs. Copies to clipboard via pbcopy. Supports --group filter.
  • check-examples: verifies every symbol in examples_include has a corresponding .md file under docs/examples/{group}/. Exits non-zero on missing files. Skippable via SKIP_EXAMPLES_CHECK=1.
  • Business logic in examples.py, CLI wiring in cli/example_cmds.py

t07-42: Link example files from generated docs

  • Generated group index pages include example links with descriptions parsed from YAML comment headers
  • Added parse_description_comment; threaded example context through render_group_index and generate_docs

t07-43: Remove gen_tests command and test_gen module

  • Deleted test_gen.py, test_gen_test.py from generation/
  • Removed gen_tests CLI command, its registration in base_commands.py, and its re-export in generate.py
  • Removed generate_tests_for_groups() from workflow_cmds.py and filter_group_by_examples_include() from examples.py
  • Removed test_file_path() from PkgSettings
  • Cleaned .groups.yaml owned_refs and unused imports

t07-44: Auto-remap changelog SHAs after rebase

  • Stale SHA detection runs automatically at the start of add_git_changes before the commit loop
  • Auto-remap matches stale FixAction entries to new commits by exact commit message, using timestamp proximity as a tiebreaker
  • Interactive fallback for unmatched entries (squashed/amended/dropped commits)
  • Bot mode inherits raise_on_question behavior -- auto-matched SHAs are applied silently, unmatched entries trigger NoHumanRequiredError

t07-45: Add change-base command and pre-commit base-branch validation

  • change-base CLI command -- diffs .changelog/ between the new base and HEAD, finds changelog files belonging to other PRs, consolidates their actions into the current PR's file, and deletes the originals
  • Pre-commit validation -- detects foreign changelog files relative to the PR's base branch and fails with an actionable error message pointing to change-base

t07-46: Add examples to mkdocs nav and inline per-symbol links

  • Example pages now appear in the mkdocs nav sidebar under an "Examples" sub-nav within each group that has examples
  • Replaced the disconnected "Examples" table at the bottom of group index pages with per-symbol - [Example: {description}]({link}) lines rendered directly after the source link
  • Flat nav groups (no complex symbols) automatically become nested when they have examples
  • _render_nav_yaml supports 3-level nesting for the Examples sub-nav

Why

The Example[T] Pydantic subclass approach coupled code examples tightly to the generation pipeline. Replacing it with standalone markdown files validated by pytest-examples gives better authoring ergonomics, simpler tooling, and docs that link directly to example files. The changelog improvements (SHA remapping, change-base) fix real pain points when rebasing and stacking PRs.

Reviewer notes

  • Breaking: gen-examples and gen_tests CLI commands are removed. No known callers outside manual use.
  • Breaking: examples_enabled and examples_exclude config fields in pyproject.toml are no longer recognized. Migrate to examples_include only.
  • Docs rendering change: SymbolContext.has_examples is removed -- symbols that previously got their own page solely because they had examples will now be inlined on the group index page (unless they have env vars or meaningful changelog changes).
  • Docs rendering change (t07-46): The bottom-of-page "Examples" table (render_examples_section) is removed. Example links now appear inline next to each symbol's source link, with the description from the example file's YAML comment header.
  • Nav type change (t07-46): NavItem children can now contain nested lists (for the Examples sub-nav). _render_nav_yaml handles 3-level YAML indentation. NavChildItem type alias added.
  • Example file paths use the symbol name as-is (CommentConfig.md), not snake_case.
  • clipboard.py duplicates the pbcopy pattern from adoc to avoid a cross-package dependency.
  • YAML changelog files are updated via regex-based string replacement to avoid re-serialization side effects. CHANGELOG.md regenerates from YAML at release time.
  • find_changelog_files_in_diff shells out to git diff --name-only {base}...HEAD -- requires the base ref to be locally available. In CI this is always true; locally it may need a git fetch first.
  • Pre-commit validation only runs when gh pr view returns PR info (CI context). Local dev without an active PR skips the check.

@EspenAlbert EspenAlbert changed the title feat: Add examples to mkdocs nav and replace table with per-symbol links feat: Replace Example[T] generation with markdown-based example docs Feb 24, 2026
@EspenAlbert EspenAlbert marked this pull request as ready for review February 24, 2026 23:06
@codecov-commenter

codecov-commenter commented Feb 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.02190% with 78 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.84%. Comparing base (3b5fd97) to head (2c37386).
⚠️ Report is 59 commits behind head on main.

Files with missing lines Patch % Lines
pkg_ext/_internal/changelog/committer.py 44.44% 25 Missing ⚠️
pkg_ext/_internal/cli/workflow_cmds.py 23.33% 23 Missing ⚠️
pkg_ext/_internal/cli/example_cmds.py 37.50% 20 Missing ⚠️
pkg_ext/_internal/examples.py 92.62% 9 Missing ⚠️
pkg_ext/_internal/changelog/change_base.py 97.22% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #19      +/-   ##
==========================================
+ Coverage   77.77%   79.84%   +2.07%     
==========================================
  Files          76       80       +4     
  Lines        4818     4982     +164     
==========================================
+ Hits         3747     3978     +231     
+ Misses       1071     1004      -67     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@EspenAlbert EspenAlbert enabled auto-merge (squash) February 24, 2026 23:29
@EspenAlbert EspenAlbert merged commit 55889c4 into main Feb 24, 2026
16 checks passed
EspenAlbert added a commit that referenced this pull request Feb 24, 2026
…19)

* refactor(pkg-ext): remove Example[T] generation machinery

* refactor(pkg-ext): remove test generation from pre_change workflow

* feat(pkg-ext): add gen-example-prompt and check-examples commands

* chore: gen docs

* refactor(examples): reuse format_signature and extract shared filter function

* feat(docs): link example files in generated group documentation

* refactor(examples): rename ExampleMetadata, add missing tests, tighten PR description

* chore: regen

* refactor(pkg-ext): remove gen_tests command and test_gen module

* feat(changelog): add change-base command and pre-commit base-branch validation

* chore: regen docs

* feat(changelog): auto-remap stale SHAs after rebase

* feat(docs): add examples to mkdocs nav and replace table with per-symbol inline links

* fix(docs): update example link paths in generated documentation

* chore: updates changelog files

* chore: self review

* chore: regen
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