ssato / python-anyconfig

Python library provides common APIs to load and dump configuration files in various formats
MIT License
277 stars 31 forks source link

Preserve merge strategy with include #81

Closed retr0h closed 6 years ago

retr0h commented 6 years ago

Is there a way merge strategy can be applied to include? When executing the following code:

import anyconfig
f1 = anyconfig.load("a.yml", ac_template=True)
f2 = anyconfig.load("b.yml", ac_template=True)

anyconfig.merge(f1, f2, ac_merge=anyconfig.MS_DICTS)
print f1

a.yml

---
{% include 'included.yml' %}
a: 1
b:
   - c: 3
d:
   e: "bbb"

b.yml

---

included.yml

b:
   - c: 0
   - c: 2
d:
   e: "aaa"
   f: 3

The result should be:

{'a': 1, 'b': [{'c': 3}], 'd': {'e': "bbb", 'f': 3}}

However, the result is:

{'a': 1, 'b': [{ 'c': 3}], 'd': {'e': 'bbb'}}

ssato commented 6 years ago

I don't think it's possible because templates are rendered before load and it cannot be changed because templates may not be valid format, e.g. YAML in this case.

ssato commented 6 years ago

Related: #49

retr0h commented 6 years ago

@ssato thanks!