If I have said yaml file:
org-lists:
ea-orgs: [
1, # test-org
]
ga-orgs: [
2, # customer-2
3, # customer-3
4, # customer-4
]
It completely removes the comments after I do a simple load and dump:
import ruamel.yaml
def format_yaml(filename: str) -> None:
yaml = ruamel.yaml.YAML()
yaml.preserve_quotes = True
yaml.indent(mapping=2, sequence=4, offset=2)
with open(filename, "r") as file:
data = yaml.load(file)
with open(filename, "w") as file:
yaml.dump(data, file)
Has anyone ran into a similar issue, and how did you work around it?
I tried changing the list structure to look like:
org-lists:
ea-orgs:
- 1 # test-org
and that will preserve the comments, but I prefer the square brackets.
I’ve also tried:
yaml.default_flow_style = None