Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support yaml tag preservation? #12

Open
clux opened this issue Sep 15, 2023 · 0 comments
Open

support yaml tag preservation? #12

clux opened this issue Sep 15, 2023 · 0 comments

Comments

@clux
Copy link
Owner

clux commented Sep 15, 2023

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.

@clux clux added wontfix This will not be worked on and removed wontfix This will not be worked on labels Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant