You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New __include__ key to compose a config from other configs - #990
Adds an __include__ key that composes a config from other configs. It is enabled with set_parsing_settings(config_include_enabled=True) and is experimental for now.
Its value is a path or a list of paths. Relative paths resolve against the config that has the key, and nested includes resolve against their own directory.
It works wherever a config is given: config files, sub-config files, inline command-line values, parse_path, parse_string, parse_object and FromConfigMixin.from_config. It is accepted at any level and must be the first key. The keys that follow override what the included configs set.
The included configs, and then the keys that follow, merge as if given one after the other, like repeated --config. The existing rules apply: a dict is replaced, + appends to lists, and changing class_path discards the init_args the new class does not accept.
Unlike sub-config files, which replace the value of an argument, an include composes the config around it. So a sub-config can be reused with some of its values overridden in place.
Changes to the jsonschema completion:
With includes enabled, config objects accept __include__. No keys are required, since configs that include others or are included can be partial.
$defs now has the schema of the $schema key and one definition per known subclass, named by its import path, e.g. mymodule.MyModel. A config that is not the root, like an included or sub-config file, can then point to a small schema that has {"$ref": "schema.json#/$defs/mymodule.MyModel/properties/init_args"}.
Fixed: the schema used the init parameters of a class from the first argument that had that class. Arguments that skip different parameters got the wrong schema. Each distinct variant now gets its own definition, e.g. mymodule.MyModel@model.
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (1da6141) to head (08df485).
✅ All tests successful. No failed tests found.
The PR adds opt-in __include__ composition across config entry points and extends JSON Schema completion for partial configs and class variants. Since the previous review, it also refactors FromConfigMixin.from_config, changes sub-config path handling, and adds a registry for non-importable classes.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Config class_path] --> B[import_object]
B --> C{Path in local-class cache?}
C -- Yes --> D[Return cached class]
C -- No --> E[Check import-path policy]
E --> F[Resolve import]
These findings sit on lines the diff does not cover, so they could not be posted inline. Each one leaves this list once its file changes.
*  **Inline configs bypass includes** `jsonargparse/_util.py:284` [▶](https://github.com/mauvilsa/jsonargparse/blob/26580150dbdc0a825c38b82edf88c8d401a8a15e/jsonargparse/_util.py#L282-L284)
With includes enabled, an inline value such as `--config='{"__include__":"base.json","b":2}'` is parsed into a dict but never has its include resolved. The config action then treats `__include__` as an ordinary key, so the command fails instead of loading `base.json` and applying `b`. A dict passed to `parse_object` also bypasses include resolution.
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
bugSomething isn't workingenhancementNew feature or request
1 participant
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.
What does this PR do?
Closes #221.
Adds an
__include__key that composes a config from other configs. It is enabled withset_parsing_settings(config_include_enabled=True)and is experimental for now.parse_path,parse_string,parse_objectandFromConfigMixin.from_config. It is accepted at any level and must be the first key. The keys that follow override what the included configs set.--config. The existing rules apply: adictis replaced,+appends to lists, and changingclass_pathdiscards theinit_argsthe new class does not accept.Changes to the
jsonschemacompletion:__include__. No keys are required, since configs that include others or are included can be partial.$defsnow has the schema of the$schemakey and one definition per known subclass, named by its import path, e.g.mymodule.MyModel. A config that is not the root, like an included or sub-config file, can then point to a small schema that has{"$ref": "schema.json#/$defs/mymodule.MyModel/properties/init_args"}.skipdifferent parameters got the wrong schema. Each distinct variant now gets its own definition, e.g.mymodule.MyModel@model.Before submitting