-
Notifications
You must be signed in to change notification settings - Fork 154
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 and use YAML blackboxes #2037
Conversation
3d46856
to
dfaffe0
Compare
88816b3
to
20d9c4a
Compare
20d9c4a
to
5449abd
Compare
Someone's gunning for top contributor 2022 |
I wish there was a |
This maybe hard or impossible with the high-level YAML api. |
I doubt easy. Objects in |
Yeah.. that'd be the |
You're adding the |
5449abd
to
3b71077
Compare
@leonschoorl Python's dicts are insertion ordered, so I've abused that to generate YAML files with the pretty order: #!/usr/bin/env python3
import yaml
import sys
# https://github.com/yaml/pyyaml/issues/240#issuecomment-1018712495
def str_presenter(dumper, data):
if len(data.splitlines()) > 1: # check for multiline string
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|')
return dumper.represent_scalar('tag:yaml.org,2002:str', data)
yaml.add_representer(str, str_presenter)
yaml.representer.SafeRepresenter.add_representer(str, str_presenter) # to use with safe_dum
def reorder_dicts(o, order=("name", "kind", "type", "template")):
if isinstance(o, list):
return list(map(reorder_dicts, o))
if isinstance(o, dict):
# Reorder dict
new_dict = {}
for s in order:
if s in o:
new_dict[s] = o.pop(s)
new_dict.update(o)
# Traverse all values in dict and reorder _them_
reorderd = {k: reorder_dicts(v) for k, v in new_dict.items()}
return reorderd
if isinstance(o, (str, int, bool)):
return o
else:
raise TypeError(f"Unexpected type: {type(o)}")
def reorder_dicts_in_file(path):
with open(path) as fp:
prims = yaml.safe_load(fp)
prims = reorder_dicts(prims)
prims = yaml.dump(prims, sort_keys=False, line_break="\n")
with open(path, "w") as fp:
fp.write(prims)
if __name__ == '__main__':
import glob
for path in glob.glob(sys.argv[1], recursive=True):
reorder_dicts_in_file(path) Aeson should probably use insertion ordered maps too.. |
Done |
05e5f29
to
18d53e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still need:
- documentation
- changelog
- some documentation on (how to run) the upgrade tool
- the examples in Clash.Tutorial still use the old format
- maybe a test that uses the old format, so we don't accidentally break it
2de24b7
to
db31d6f
Compare
@leonschoorl All done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, seems fine. I didn't spot any, but since all the primitives are being changed it might be worth trying to see if any have obviously wrong type comments, i.e. using Undefined
instead of NFDataX
template-haskell >= 2.0.0, | ||
Cabal | ||
text, | ||
yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bounds for yaml
since it's not a boot library
[ ("name", "aaaa_really_should_be_name_but_renamed_to_get_the_sorting_we_like") | ||
, ("type", "really_should_be_type_but_renamed_to_get_the_sorting_we_like") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A masterpiece
577e12c
to
c2f3b48
Compare
+16,061 −17,015 It just gets chonkier 👀 |
:( |
|
c2f3b48
to
2dc7c69
Compare
2dc7c69
to
e2ddf73
Compare
Files ending in `.primitives.yaml` are now interpreted as YAML blackbox files. Fixes #2038
This is in preparation of converting all primitives to YAML. Doing a rename first preserves a usable history. If we don't do this, Git won't see a relation between the old and new primitive files.
This makes sure `name` is at the top and and `type` is just above `template`.
Their keys are stored in HashMaps whose order we can't predict
e2ddf73
to
ce7c318
Compare
Added support for YAML blackboxes. Clash will now pickup on files with a
.primitives.yaml
extension. While we recommend upgrading your primitive filesto the new format, old style primitives are still supported.
Depending on whether you use Stack or Cabal you can execute the following to
upgrade your primitive files:
Stack users can use:
Both commands assume you're running them in an up-to-date
(starter) project environment.