Allow INHERIT to list several config files - #107
Merged
Merged
Conversation
`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>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
INHERITaccepts a single parent file, so splitting a configuration into several files means chaining them, each inheriting from the next. That's hard to maintain.INHERITnow also accepts a list:Semantics
INHERITtoo, with paths relative to themselves. A shared grandparent (diamond inheritance) is fine.RecursionError. Paths are compared withrealpath, so cycles through symlinks are caught too.echo '{INHERIT: mkdocs.yml, …}' | mkdocs build -f -) are unchanged.mkdocs servewatches inherited filesservewatched only the primary config file, so editing an inherited file didn't trigger a rebuild. That already affected single-fileINHERIT, and it matters more once a configuration is split.yaml_loadgets a new keyword-onlyinheritedargument that collects the paths of inherited files.MkDocsConfig.load_filerecords them as_inherited_config_files, andservewatches them.Verification
load_configrecording the inherited files, andservewatching them. All of them fail without the change.mkdocs servelists all three inherited files among the watched paths and rebuilds when one of them changes.Known limitation:
mkdocs get-depsloads YAML with themkdocs-get-depspackage's own loader, which only supports a singleINHERITpath. With a list, it fails with aTypeErroruntil that package is updated.Related Issue
No issue in this repository.
Checklist
docs/about/release-notes.mdupdated (if applicable)🤖 Generated with Claude Code