Open Jackenmen opened 4 years ago
Thanks for raising this. When I wrote this I was focused almost exclusively on deterministic roundtripping (i.e. the ordering out should match the ordering in), and believe it or not I've yet to try reordering keys.
I am somewhat concerned that it might not be possible to fix this without first doing #56 but I'll take a look.
Hi, I've been using this project for short time, and recently I figured that after loading the yaml with provided schema, I also want to sort keys in the data and output it back to file so that it always stays in same order. I thought it's gonna be easy at first, but unfortunately it only seemed that way. I tried to do this in 2 ways:
Edit the YAML object which at first seemed like the way docs intended me to use:
The second line immediately failed because the keys and values in the dict are in fact
YAML
objects and doing this fails with serialization error.Get
YAML.data
, modify the returned dict and serialize it withas_document
:yaml = load(yaml_input, SCHEMA) data = yaml.data data["repo"] = OrderedDict(sorted(yaml["repo"].items(), key=lambda tup: tup[0])) document = as_document(data, SCHEMA)
repo: install_msg: >- Thanks for using RepoName. If you have any issues, check for more information in my repo: