admin管理员组文章数量:1295914
I need Ruamel or PyYaml or whatever Python-based YAML parser to read following lines:
TEST: &test !include test.yaml
<<: *test
Unfortunately, I cannot modify any of YAML code.
Idea is to get following result:
TEST:
content1: value1
content2: value2
content1: value1
content2: value2
As recommended in docs, I added constructor for tag !include
:
def _getConfigWithInclusions(path, inclusionHandler):
yaml = YAML()
yaml.Constructor.add_constructor('!include', inclusionHandler)
try:
with open(path) as stream:
res = yaml.load(stream)
except YAMLError as e:
raise RuntimeError(f'Most likely config file {path} is corrupted.', e)
return res
But I encountered issue:
ruamel.yaml.constructor.ConstructorError: while constructing a mapping
in ".../config/yaml/default/sim_top.yaml", line 2, column 1
expected a mapping or list of mappings for merging, but found scalar
in ".../config/yaml/default/sim_top.yaml", line 2, column 10
Is I investigated, it happens because node, containing !include test.yaml
, which was created at composition is (obviously) ScalarNode. But merging is done before invoking my inclusionHandler
, so it cannot be any different.
This seems to be legit both for ruamel.yaml and PyYaml.
Please, could you help finding some workarounds for this case?
本文标签: pythonRuamel and PyYaml fail to combine custom tag and merge operatorStack Overflow
版权声明:本文标题:python - Ruamel and PyYaml fail to combine custom tag and merge operator - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741616415a2388549.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论