Skip to content

support yaml tag preservation? #12

@clux

Description

@clux

python-yq supports "yaml roundtripping" and allows them to somehow preserve tags (which we support from #11)
by keeping track of them and re-injecting them back as yaml (when using -y as output).

python-yq setup

documented with https://kislyuk.github.io/yq/#preserving-tags-and-styles-using-the-y-yaml-roundtrip-option

they have this warning:

The -Y option is incompatible with jq filters that do not expect the extra information injected into the document to preserve the YAML formatting. For example, a jq filter that counts entries in the Instances array will come up with 4 entries instead of 2. A filter that expects all array entries to be mappings may break due to the presence of string metadata keys. Check your jq filter for compatibility/semantic validity when using the -Y option.
they seem to do it by keeping track of anchors and such in a dict via: https://github.com/kislyuk/yq/blob/ee87412fa89add226d263ec7885193e07243aa4c/yq/loader.py#L141-L155 and swapping back when serializing in https://github.com/kislyuk/yq/blob/ee87412fa89add226d263ec7885193e07243aa4c/yq/dumper.py#L33-L82 which seems super painful and hacky (internal __yq_alias__ keys for transport).

they also have the wildest regex based resolver system in there so not sure how viable this all is to a more closed down system like serde without writing your own serializer

Status

personally, don't particlarly care about this, but i also don't have use cases that need it atm.
if anyone has good ideas or want this. lemme know why or what. or post suggestions as to how to do it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is neededquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions