I am trying to parse a YAML input from a file:
root: {
children : { key: "test-key", version: "{{ test_version | default( '1.0.0-SNAPSHOT' ) }}"}
}
I am using ruamel.yaml, the section of code that makes the load is configured to preserve quotes and then I am adding manually a new entry:
yaml = ruamel.yaml.YAML()
yaml.preserve_quotes = True
yaml.width = 4096
yaml.indent(sequence=4, offset=2)
with open(yml_file, 'r') as file:
print("Modifying file: '%s'..." % str(file))
data = yaml.load(file)
data['root'][new_project_name.lower()] = {'key': "%s" % new_project_name.lower(),
'test_version': "{{ %s_version | default(\'1.0.0-SNAPSHOT\') }}"
% new_project_name.lower()}
with open(yml_file, 'w') as file:
yaml.dump(data, file)
The thing is that when the file gets written with the new entry, I am getting everything in the same line, so it seems not to preserve the new lines (CR LF), (it seems to be loading it without them even) do you know if there is any way to preserve them?.
output is (everything in the same line):
root: {children : { key: "test-key", version: "{{ test_version | default( '1.0.0-SNAPSHOT' ) }}"}}