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 ruamel.yaml as a yaml decoder/encoder #15

Closed
chancez opened this issue Jan 24, 2018 · 4 comments
Closed

Support ruamel.yaml as a yaml decoder/encoder #15

chancez opened this issue Jan 24, 2018 · 4 comments

Comments

@chancez
Copy link

chancez commented Jan 24, 2018

https://bitbucket.org/ruamel/yaml is the link to the package's source code repo, it's ruamel.yaml on pypi.

ruamel.yaml is really nice because it can preserve original formatting, meaning comments, and ordering of maps, etc is preserved. If yq could support this as an optional dependency and flag that allows controlling usage, that would be great. I'd even potentially look into implementing it if it doesn't seem too hard.

@chancez
Copy link
Author

chancez commented Jan 24, 2018

Although, right after I open this, I realize yq is calling out to jq which means most of this information is lost anyways, so I guess there's no way to get the behavior I want unless the logic of jq was re-implemented in yq, so I'll just close this.

@chancez chancez closed this as completed Jan 24, 2018
@kislyuk
Copy link
Owner

kislyuk commented Jan 25, 2018

I've looked into ruamel.yaml and I definitely appreciate the fact that upstream PyYAML is on life support/nearly dead. Map ordering is preserved by both yq and jq. As you correctly point out, preservation of comments is irrelevant since JSON does not admit comments and jq does not support non-standard JSON dialects that do. The main reason to use ruamel.yaml is actually its support for YAML 1.2, which PyYAML does not support and which eliminates some annoying unused misfeatures like "sexagesimals" that interfere with reasonable YAML use cases.

With that said, I am not yet comfortable switching to ruamel.yaml because I don't consider that project to be sufficiently mature. The ideal situation would be if the key features introduced by ruamel.yaml were ported to and released in PyYAML by its new maintainers.

@chancez
Copy link
Author

chancez commented Jan 25, 2018

I didn't realize jq was preserving the map ordering, which makes me quite happy to learn. I figured it might depend, but the output had been what I was mostly hoping for, in either case, yq does most of what I want, so I'm pretty happy with what it's currently doing. Agreed on the point that it would be nice for the various python yaml libraries to try and consolidate though.

@jayvdb
Copy link

jayvdb commented Jul 12, 2019

ruamel.yaml increases to drift away from (ahead of) PyYAML in many ways. Many Python projects which are emitting yaml as a human readable config are switching to ruamel.yaml in order to have stable yaml files.

I suggest this is re-opened and a new flag like --yaml-library=(ruamel|PyYAML) is added to opt-in use of ruamel.yaml. There are also other yaml libraries with limited features but faster which could then also be added for people where those tradeoffs are ok for their needs.

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

3 participants