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

Emitting julia objects to YAML. #29

Closed
montyvesselinov opened this issue Feb 28, 2016 · 23 comments
Closed

Emitting julia objects to YAML. #29

montyvesselinov opened this issue Feb 28, 2016 · 23 comments

Comments

@montyvesselinov
Copy link

Are there plans to add an option to write YAML files soon?

@femtotrader
Copy link

femtotrader commented Oct 8, 2016

YAML.yaml(...) will be great!
(like JSON.json(...))

@sglyon sglyon closed this as completed Oct 8, 2016
@trans
Copy link

trans commented Nov 9, 2016

Why was this closed without an answer?

@sglyon
Copy link
Collaborator

sglyon commented Nov 9, 2016

Not sure, that was my mistake. Sorry about that

@sglyon sglyon reopened this Nov 9, 2016
@trans
Copy link

trans commented Nov 22, 2016

I wish I had the time/knowledge to whip this out myself, but at this point I do not -- it would be much easier for someone else with the right knowledge to do it. Yet I really would like to have this functionality, so I am willing to kick in $20 to start a bounty in hopes that it will incentivize the right person. Maybe a few others can kick in as well.

@jdlangs
Copy link
Contributor

jdlangs commented Nov 22, 2016

I'll have lots of time available for open-source come mid-December and was planning to devote some of it here so I won't mind working on an implementation for this around then if no one else has done it. No need for a bounty on my end.

Before that though, it would be good to clear up why no development has happened on this package in over a year even though multiple pull requests are open.

@sglyon
Copy link
Collaborator

sglyon commented Nov 22, 2016

@jdlangs that'd be great.

I think the long break since this has been actively worked on is due to two main things: @dcjones (the author of this package) getting working on his PhD and the YAML parsing routines being stable.

@dcjones has given me permissions for this repo, so I can manage it going forward. I don't have much time to implement new features myself, but will be able to view/merge pull requests.

@jdlangs
Copy link
Contributor

jdlangs commented Nov 22, 2016

Sounds good, and thanks for stepping up to manage the development. It provides a lot of assurance to potential contributors that there's an active maintainer, even if they aren't able to add features themself.

On the same note, aren't there a few pull requests that should have been merged quite a while ago? I'll point out #32 in particular.

@dreammaker
Copy link

@jdlangs, did you (or anyone else) make progress on this?

@montyvesselinov
Copy link
Author

montyvesselinov commented Feb 23, 2017 via email

@chakravala
Copy link

It would be great if this could be implemented

@mlhetland
Copy link
Contributor

I've had a look at this, and I guess the amount of effort involved would be closely correlated with the level of ambition.

On the one hand, a simple YAML-emitting mechanism mirroring that of JSON.jl could probably be done in a matter of hours. On the other hand, there is a spectrum of stretch-goals, here. For example, one might want to let the user determine which syntax variants are used to serialize different components, and perhaps include line wrapping as part of the pretty-printing (taking indentation, etc., into account). And, perhaps more usefully, one might want to be able to preserve metadata when parsing, so that one could emit the same syntax forms, and even include the same insignificant whitespace, comments, etc., so that round-tripping via YAML.jl does not modify the YAML file, and any modifications are local to what is modified, leaving the rest of the file (including comments, etc.) intact. As far as I know, there are tools that do this – but that would require quite a bit more work. I guess one could have a list of features, and see if it's possible to map out an incremental path from the simple emitter to the more integrated library where parser and emitter cooperate, using the same data model (including non-significant information about order, whitespace, comments, syntax variants…).

Another thing I've thought about now and then is whether it might be useful to go the PyYAML route, and simply wrap LibYAML. Of course, that introduces a black box, which is sort of un-Julian, and the conversion to/from Julia types would still have to be there. So maybe it's not that much more useful.

@mirkobunse
Copy link
Contributor

mirkobunse commented Jan 11, 2019

I did make a Julia implementation of writing YAML files: https://github.com/mirkobunse/ComfyCommons.jl/blob/master/src/yaml.jl

If there is still interest and a maintainer willing to review, I'll prepare a pull request from this sketch.

What it already does:

  • Write Dicts and Vectors
  • Write Strings, Numbers, and so on
  • Correct and nice intendation
  • A prefix string with comments can be written along with the config

What is currently missing:

  • The order of the Dict entries in the written file is arbitrary. Keeping the order of an existing file would require YAML.jl to use ordered dictionaries, which will be easy to do in a PR.
  • Comments at arbitrary positions

EDIT: Of course, the Dicts and Vectors can be nested.

@mlhetland
Copy link
Contributor

Using ordered dictionaries would be very useful, I think – even though the YAML spec specifically doesn't care about ordering, in applications it can be quite useful if a library supports it. (Specifically having round-tripping, i.e., reading and then writing, not modify things too much. Ideally, it would preserve comments etc., as well, but I guess that requires a richer internal model.)

@babaq
Copy link

babaq commented Sep 1, 2019

is there any plans or progress to implement Yaml writing, or just try to incorporate the code @mirkobunse have write?

@mlhetland
Copy link
Contributor

If @mirkobunse's code is to be used, I guess it would have to be released under some other license, or contributed directly to the YAML.jl project (by @mirkobunse)? At present, it's licensed under GPL 3, and YAML.jl is under MIT.

@mirkobunse
Copy link
Contributor

Sure, I can open a PR on YAML.jl to make a direct contribution. Thank you, @mlhetland, for keeping an eye on the licenses.

@mirkobunse
Copy link
Contributor

The PR is open

@peng1999
Copy link

peng1999 commented Feb 3, 2020

@kescobo This issue can be closed since #68 has merged.

@peng1999
Copy link

peng1999 commented Feb 3, 2020

And maybe maintainer of this package should bump a new release.

@CiaranOMara
Copy link

@mirkobunse, regarding the ordering, TOML has an option to sort when printing.

@mirkobunse
Copy link
Contributor

Thanks for the hint!

However, TOML seems to sort lexicographically. The order in a YAML file can be any order. The preservation of such requires some kind of an ordered dictionary. DataStructures.jl has one, by the way.

@CiaranOMara
Copy link

I think ordered dictionaries were split off into OrderedCollections.jl.

@mirkobunse
Copy link
Contributor

Hi everyone,

with the release v0.4.2 it is now possible to read and write arbitrary subtypes of AbstractDict. With this feature, you can maintain the order of YAML files in a load-save-load roundtrip. All you need to do is to use the new dicttype argument while reading, which is documented in the README.

@kescobo kescobo closed this as completed Aug 28, 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