adobe / himl

A hierarchical yaml config in Python

Home Page:https://pypi.org/project/himl/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] support for custom merger with different merge strategies

oldgromit opened this issue · comments

First of all, great work! We have been using himl for a while, and it's been great in helping us to manage our configuration needs.

One recent requirement is to allow lower level configuration overriding upper level for a list, instead of the default append behavior.

i.e.
examples/simple/default.yaml

list:
 - key: key1
 - value: value1 

examples/simple/region/cluster1.yaml

list:
 - key: key1
 - value: value2

so instead of merging the two, I'd like to allow cluster1.yaml to override default.yaml value, if the keys are the same.

the deep merge pkg allows passing custom function for different merging strategies, himl ConfigGenerator is building Merger object but doesn't allow custom function to pass in to override default behavior:

merger = Merger([(list, ["append"]), (dict, ["merge"])], ["override"], ["override"])

Would it be possible to refactor the ConfigProcessor and ConfigGenerator so that a custom func can be passed to the merger, thus allowing greater flexibility on merging behavior? Maybe ConfigProcessor can be passed an optional param to allow this?

Thanks, and keep up the great work!

I have created a PR to accomplish this without refactoring. Made sure all the new parameters are optional so it doesn't break existing behavior. Please review and provide feedback. Thanks.

Lovely! himl 0.11.0 is released with this change.
Works like a charm:

himl myconfigs --list-merge-strategy=override

Thanks for the contribution, @oldgromit.