Skip to content

Add the ability to recursively include config files

Aaron Liblong requested to merge aliblong/CAFCore:master into master

To my understanding, it is not currently possible to recursively include config files, i.e. to include a file which includes a file. This is due to the TEnv level chosen when reading the files: kEnvLocal. At this level, after a value is set for some key, subsequent attempts to set the value are ignored, so config.Include can be set only once.

Simply changing the TEnv level to kEnvChange will change this behaviour from 'ignore' to 'overwrite', which is enough to allow recursive inclusion. But even then, the behaviour is not, I believe, optimal; the value at the lowest-level included file will be the one taken. For example, using the following config files:

#readAnalysis.cfg
readAnalysis.a: 1
config.Include: other_config.cfg
#other_config.cfg
readAnalysis.a: 2

the value of 2 will be used.

Often, one wants to run an analysis while varying a few parameters, and the most ergonomic way to do this is to begin with (include) some baseline config file, then specify the parameters to be overwritten. I added a function that ensures the included files will be read in an order such that top-level configurations take priority.

I believe this change will allow us to greatly simplify not only the existing config files on SVN, but especially the many config files that I'm sure pop up in everyone's local codebases as they develop their analyses. And less copy-pasted code should also mean less misconfiguration.

Merge request reports