Support for preserving flow style
ruamel.yaml is a YAML 1.2 parser/emitter for Python
Brought to you by:
anthon
If my YAML has some spacing and indentation, currently both the spacing and indentation in a flow style are reformatted:
before:
deployment: { enabled: false }
daemonset: { enabled: false }
after ruamel:
deployment: {enabled: false}
daemonset: {enabled: false}
I notice the same on arrays:
command: [ "sleep", "60" ]
becomes:
command: ["sleep", "60"]
Can support be added to respect these style via a preserve_flow_spacing = True configuration or is there another way to prevent this?
Settings:
#ruamel.yaml==0.19.0
#ruamel.yaml.clib==0.2.15
yaml = YAML(typ="rt")
yaml.preserve_quotes = True
yaml.indent(mapping=2, sequence=4, offset=2)
yaml.allow_duplicate_keys = True
yaml.width = 4096
yaml_contents = yaml.load(f)
This is by design as the extra spaces are suprefluous.
However the start, end and separator for both collections types are specified as class variables on
Emitterasflow_map_start = '{'etc. So you can have any of those "spaced" so the flow styles come out differently (but still all the same way).This request for supprot belongs on StackOverflow where the question has already been answered https://stackoverflow.com/a/76547814/1307905, and it is also mentioned in the ChangeLog
thanks for the response.