Skip to content

Yaml / json file aggrigation

Dan Guest requested to merge dguest/athena:combconf into main

I've been using code that allows us to reuse some fragments of json / yaml files in a few projects for a while now. I figure this would make sense to consider in the current effort to write yaml configuration. It would also just be nice to have all the projects that use this aggregation share a single implementation.

This is a less ambitious version of !66914 (closed): I'm only including the file merging here.

I've copied the contents of the README below, to explain how this works:


Combining Configuration Files

Configuration files contain with one special key: include. If this appears in a yaml object, the parser will assume the key gives a path relative to the current file. Any entries in the file will be imported at the same scope where the include key appears. If local keys conflict with imported ones they will be merged, giving local keys precedence over those imported from the file.

Conflicting keys are merged as follows:

  • If the keys point objects (i.e. a dict or map), the union of all keys and values within the objects is taken, and conflicting keys are merged recursively.
  • If the keys point lists, the lists are concatenated.
  • If the keys point to anything else (i.e. numbers or strings), the local key overwrites the key from the file.

This gives a useful way to specify default values, since any values imported via file will be overwritten by local ones.

Edited by Dan Guest

Merge request reports