Skip to content

Allow INHERIT to list several config files - #107

Merged
shenxianpeng merged 2 commits into
mainfrom
feature/inherit-multiple
Sep 24, 2026
Merged

shenxianpeng merged 2 commits into
mainfrom
feature/inherit-multiple

Conversation

@shenxianpeng

Copy link
Copy Markdown
Member

INHERIT accepts a single parent file, so splitting a configuration into several files means chaining them, each inheriting from the next. That's hard to maintain.

INHERIT now also accepts a list:

INHERIT:
  - config/markdown_extensions.yml
  - config/plugins.yml
site_name: Foo Project

Semantics

  • Files are merged in order: each overrides the ones before it, and the file itself overrides all of them. The merge rules are unchanged: mappings are deep-merged and lists are replaced.
  • Parent files can use INHERIT too, with paths relative to themselves. A shared grandparent (diamond inheritance) is fine.
  • A file that inherits from itself, directly or indirectly, is a configuration error that shows the chain. Previously it recursed until RecursionError. Paths are compared with realpath, so cycles through symlinks are caught too.
  • A value that isn't a path or a list of paths is reported clearly.
  • The single-path form and the documented stdin trick (echo '{INHERIT: mkdocs.yml, …}' | mkdocs build -f -) are unchanged.

mkdocs serve watches inherited files

serve watched only the primary config file, so editing an inherited file didn't trigger a rebuild. That already affected single-file INHERIT, and it matters more once a configuration is split. yaml_load gets a new keyword-only inherited argument that collects the paths of inherited files. MkDocsConfig.load_file records them as _inherited_config_files, and serve watches them.

Verification

  • New tests cover: merging several files in order, a shared parent, an empty list, direct and indirect cycles, invalid values, load_config recording the inherited files, and serve watching them. All of them fail without the change.
  • Manually tested with a config split into three files: the merge result is correct, and mkdocs serve lists all three inherited files among the watched paths and rebuilds when one of them changes.

Known limitation: mkdocs get-deps loads YAML with the mkdocs-get-deps package's own loader, which only supports a single INHERIT path. With a list, it fails with a TypeError until that package is updated.

Related Issue

No issue in this repository.

Checklist

  • New tests added for new behavior (if applicable)
  • Documentation updated (if applicable)
  • Release notes docs/about/release-notes.md updated (if applicable)

🤖 Generated with Claude Code

shenxianpeng and others added 2 commits September 24, 2026 23:32
`INHERIT` accepted a single parent file, so splitting a configuration
into several files meant chaining them, each inheriting from the next.

`INHERIT` now also accepts a list of paths. The files are merged in
order, each overriding the ones before it, and the file itself overrides
all of them. Parent files can themselves use `INHERIT`. A file that
inherits from itself, directly or indirectly, is now reported as a
configuration error instead of recursing until `RecursionError`. An
`INHERIT` value that isn't a path or a list of paths is also reported
clearly.

`mkdocs serve` watched only the primary config file, so editing an
inherited file didn't trigger a rebuild. `yaml_load` can now collect the
paths of inherited files (new keyword-only `inherited` argument);
`MkDocsConfig.load_file` records them, and `serve` watches them too.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added the enhancement New feature or request label Sep 24, 2026
@codspeed

codspeed Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 28 untouched benchmarks


Comparing feature/inherit-multiple (f59c327) with main (5fd5096)

Open in CodSpeed

@shenxianpeng
shenxianpeng merged commit 0e745b4 into main Sep 24, 2026
23 checks passed
@shenxianpeng
shenxianpeng deleted the feature/inherit-multiple branch September 24, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant