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

Add ability to custom-sort YAML-configured item lists #15

Closed
davidskalinder opened this issue Nov 20, 2019 · 6 comments
Closed

Add ability to custom-sort YAML-configured item lists #15

davidskalinder opened this issue Nov 20, 2019 · 6 comments
Assignees

Comments

@davidskalinder
Copy link
Owner

Currently, sort is automatically alphabetical.

@davidskalinder davidskalinder self-assigned this Nov 21, 2019
@davidskalinder
Copy link
Owner Author

alphabetical

Only for presets! Otherwise, random!

@davidskalinder
Copy link
Owner Author

davidskalinder commented Dec 12, 2019

I think the issue is that in our Python implementation dictionary order is randomized. Presets are explicitly sorted:

v1 = [(x, str.title(x).replace('-', ' ')) for x in sorted(preset_vars.keys())]

But for other yaml loads, I think Python is randomizing the sort (though this should be checked by hard-loading the dict from code).

yaml/pyyaml#110 makes it sound like the only way pyyaml affects this is in the yaml.dump function, which we're not using.

OrderedDict might be the sensible solution here (given than insertion order is only guaranteed to be preserved in 3.7+). Trick then is to get pyyaml to load into an OrderedDict. A possible solution is at https://stackoverflow.com/a/21912744. (Additional considerations are at https://stackoverflow.com/questions/1867861/how-to-keep-keys-values-in-same-order-as-declared)

@davidskalinder
Copy link
Owner Author

Python is randomizing the sort (though this should be checked by hard-loading the dict from code).

Confirmed.

@davidskalinder
Copy link
Owner Author

Probable fix is now committed in branch split_location, but doesn't work due to order of controller sections. So this now depends on #22.

Also, once this is tested, should move definition of ordered_load to the yamls_in_order branch

@davidskalinder
Copy link
Owner Author

So #22 won't be fixed properly for a while. The function should be shoehorned into the mess of the controller file wherever works for now.

@davidskalinder
Copy link
Owner Author

Function shoehorned effectively. This is now fixed in branch yamls-in-order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

1 participant