ssato / python-anyconfig

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

Loading yaml files fails when using the yaml merge syntax with PyYAML #87

Closed idanov closed 6 years ago

idanov commented 6 years ago

Yaml supports syntax for merging arrays and dictionaries. The following yaml file can be successfully loaded by using PyYAML directly:

part1: &base
  a: hello
  b: world
  c:
    obj1: ','
    obj2: ['el1', 'el2']

part2:
  <<: *base
  b: solar system

However, when I use anyconfig to load the same file, I get an exception like this one:

...
...
...
  File "/usr/local/anaconda3/envs/test/lib/python3.5/site-packages/yaml/constructor.py", line 86, in construct_object
    data = constructor(self, node)
  File "/usr/local/anaconda3/envs/test/lib/python3.5/site-packages/anyconfig/backend/yaml.py", line 97, in construct_mapping
    key = loader.construct_object(key_node, deep=deep)
  File "/usr/local/anaconda3/envs/test/lib/python3.5/site-packages/yaml/constructor.py", line 86, in construct_object
    data = constructor(self, node)
  File "/usr/local/anaconda3/envs/test/lib/python3.5/site-packages/yaml/constructor.py", line 414, in construct_undefined
    node.start_mark)
yaml.constructor.ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:merge'
  in "example.yml", line 9, column 3

A quick search revealed that several other libraries had similar issues and apparently it is a quick fix to make this work: https://github.com/yaml/pyyaml/issues/64 https://github.com/saltstack/salt/issues/2092 https://github.com/google/rekall/issues/319 https://github.com/zerwes/hiyapyco/issues/7

ssato commented 6 years ago

Thanks a lot! I've just merged your PR. If something still goes wrong, please let me know.