Skip to content

yaml roundtripping comments and whitespace #140

Open
@yaythomas

Description

@yaythomas

the yaml roundtripping filewrite/fileformat steps do not preserve comments in the source yaml on the outfile.
the ruamel in/out is correct, but the context.get_formatted_iterable doesn't deal with the special cases necessary to bring across the comment info also. . .

it'll likely need something like this:

if isinstance(n, ruamel.yaml.comments.CommentedMap):
        for k in n:
            d[k] = update(d[k], n[k]) if k in d else n[k]
            if k in n.ca._items and n.ca._items[k][2] and \
               n.ca._items[k][2].value.strip():
                d.ca._items[k] = n.ca._items[k]  # copy non-empty comment
    else:
        d = n
    return d```

with similar for Lists.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions