2018-11-01 11:34:16 +01:00
|
|
|
"""consolidated yaml API
|
|
|
|
|
|
|
|
|
|
ensures the same yaml settings for reading/writing
|
|
|
|
|
throughout tljh
|
|
|
|
|
"""
|
2024-02-05 20:29:32 +00:00
|
|
|
|
2018-11-01 11:34:16 +01:00
|
|
|
from ruamel.yaml import YAML
|
2023-05-15 08:51:35 +00:00
|
|
|
from ruamel.yaml.composer import Composer
|
2018-11-01 11:34:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class _NoEmptyFlowComposer(Composer):
|
|
|
|
|
"""yaml composer that avoids setting flow_style on empty
|
|
|
|
|
containers.
|
|
|
|
|
|
|
|
|
|
workaround ruamel.yaml issue #255
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def compose_mapping_node(self, anchor):
|
|
|
|
|
node = super().compose_mapping_node(anchor)
|
|
|
|
|
if not node.value:
|
|
|
|
|
node.flow_style = False
|
|
|
|
|
return node
|
|
|
|
|
|
|
|
|
|
def compose_sequence_node(self, anchor):
|
|
|
|
|
node = super().compose_sequence_node(anchor)
|
|
|
|
|
if not node.value:
|
|
|
|
|
node.flow_style = False
|
|
|
|
|
return node
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# create the global yaml object:
|
|
|
|
|
yaml = YAML(typ="rt")
|
|
|
|
|
yaml.Composer = _NoEmptyFlowComposer
|