mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
consolidate yaml configuration
workaround ruamel.yaml issue 255,
where once an empty dict or list has been written,
'flow' style is used thereafter, using dense `{key: value}` form
instead of traditional yaml block style.
This commit is contained in:
32
tljh/yaml.py
Normal file
32
tljh/yaml.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""consolidated yaml API
|
||||
|
||||
ensures the same yaml settings for reading/writing
|
||||
throughout tljh
|
||||
"""
|
||||
from ruamel.yaml.composer import Composer
|
||||
from ruamel.yaml import YAML
|
||||
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user