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.
Goal
This PR aims at making config inheritance possible. To do so it makes to contributions:
is_config_file=True
optionMotivations
This is useful for instance when using a piece of software for many different configurations which can be divided into some sort of parent and children classes.
Details
As an example we could have something like
With the PR we can now specify specify something like
-my-config consumer_cars brand
for the model to have both the config or the brand and the consumer_cars_conf. The order matters as the last specified config file will take precedence of the previous ones. Alternatively you can specify it in a config file of its own:model.ini
This will pull out and parse the config for brand and that for consumer cars. The consumer_cars_conf itself could be something like:
consumer_cars_conf.ini
As such this allows the user to build a full inheritance system.
Parsing order and circular dependencies
In terms of evaluation order for the arguments we have the following:
top-speed
)In the general case, for each recursion level, the existing command_line args take precedence, then all the config files are parsed in the reversed order of appearance on the command line, and their args are added to the command line if not there already, and then we start a new recursion round with the newly parsed confs.
Note that we have put some guards to avoid circular dependencies (eg config1 pointing to config2 which points to config 1, creating an endless loop), but the first pass (the config files specified in the original command line arguments) are not registered as already parsed. This is not really an issue as the arguments from the first config file will already be in the
command_line_args
if it get parsed again and will thus not be updated.Testing
I have also added some unittest to make sure everytthing is parsed as expected and there are no infinite loop if the config files define circular dependencies.