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

YAML format discussion #15

Closed
frauzufall opened this issue Dec 16, 2019 · 5 comments
Closed

YAML format discussion #15

frauzufall opened this issue Dec 16, 2019 · 5 comments

Comments

@frauzufall
Copy link
Contributor

frauzufall commented Dec 16, 2019

At the hackathon we were discussing if YAML is the format we want to go with.

@uschmidt83 had issues installing the python PyYAML. Also, the autogenerated YAML file looks weird.

There might be better options and if you are interested in discussing this, do it here :)

@emilmelnikov
Copy link
Contributor

emilmelnikov commented Dec 16, 2019

One can preserve key order if Python dicts are ordered and sort_keys=False:

import yaml
print(yaml.dump({"c": 3, "z": 2, "a": 1}, default_flow_style=False, sort_keys=False))
c: 3
z: 2
a: 1
import yaml
print(yaml.dump({"c": 3, "z": 2, "a": 1}, default_flow_style=False, sort_keys=True))
a: 1
c: 3
z: 2

PyYAML version is 5.2.

See yaml/pyyaml#110 (comment).

@constantinpape
Copy link
Collaborator

What alternatives do you have in mind?

I think we decided on yaml because it's pretty common in the python space and more readable than xml (and xml parsing in python is a bit unconvenient). From my experience pyyaml is fairly easy to install, but I almost always do it via conda.

@MartinHjelmare
Copy link

Using yaml in the config doesn't necessarily mean we have to use PyYAML. There's also ruamel.yaml.

https://pypi.org/project/ruamel.yaml/

https://yaml.readthedocs.io/en/latest/pyyaml.html#differences-with-pyyaml

@m-novikov
Copy link
Contributor

This snippet show how to control list representation in pyyaml

import yaml

class FlowStyleList(list):
    pass

def flow_representer(dumper, data):
    return dumper.represent_sequence("tag:yaml.org,2002:seq", data, flow_style=True)

yaml.add_representer(FlowStyleList, flow_representer)
print(yaml.dump({
    "a": FlowStyleList(["a", "b", "c"]),
    "b": ["a", "b", "c"],
}))

Results in following yaml:

a: [a, b, c]
b:
  - a
  - b
  - c

@FynnBe
Copy link
Member

FynnBe commented Mar 17, 2020

I suppose it's YAML for now, feel free to reopen and restart the discussion

@FynnBe FynnBe closed this as completed Mar 17, 2020
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

6 participants