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
Consider adding a yaml library #263
Comments
Do you have a specific Clojure YAML library in mind that we should add? I'm not that familiar with using YAML from Clojure myself. |
SnakeYAML is probably the defacto on the JVM. |
This sounds useful to me as well. Can only say that we're using https://github.com/owainlewis/yaml which is also based on snakeyaml. |
https://github.com/retrogradeorbit/bootleg also uses the lib that @mk mentioned. These are notes from a chat with @retrogradeorbit, the author. bootleg is also based on sci and compiled with GraalVM. In summary, I think it would be good to add the YAML lib that @mk mentioned in the same way as bootleg does it. A PR is welcome. I'm interested in how much this would add to the binary size. 9:15 AM So, I wrote my own YAML wrapper to SnakeYAML 2.0. You can see it here: Feel free to either reference this or copy it into your own lib. |
I've also used https://github.com/owainlewis/yaml Works fine for simple use cases. More complicated yaml files (e.g. with custom tags) are more troublesome if i remember correctly. I've never been able to convert cloudformation yaml to json and edn. I still use online converters for this 🙈 owainlewis/yaml#27 (comment) (edited) |
I am personally using the clj-yaml with GraalVM with out any issue. The library is maintained by the community and I think that is a big plus. |
From a conversation on Slack with @slipset:
|
I'm not reading or writing YAML that much myself, but if there is a library that is well maintained, I can defer any issues with it to that repo and update to the newest version in the future. Since |
Conversation on Slack:
I'm not sure how this would work with babashka? |
Just for reference, here's a project which can deal with Cloudformation yaml: |
Interesting comment here about the differences between lancepantz/clj-yaml#28 (comment)
|
FYI, I'm trying to include cfn-yaml in a native library. While trying this, I noticed that at least the cfn-yaml code relies on duck typing (i.e. two different classes both have a |
What yaml CLI tools are available in this space? I can image there are some tools that allow you to convert yaml into JSON? This JSON could then be processed by bb. |
After working around the issue owainlewis/yaml#35 and ploughing through the type warnings I got an integration with For regular YAML it seems to work fine though |
To add my $0.02 from Slack: My primary use-case for needing In the interim I wrote up a very quick edn->yaml parser that could work for some simple cases. It's moderately opinionated but doesn't include any extra java classes that |
To my understanding, the parser local tags (used by CloudFormation for example) always require custom implementation from the parser. The snakeyaml documentation puts this nicely: https://bitbucket.org/asomov/snakeyaml/wiki/Documentation#markdown-header-tags
cfn-yaml is just a very specific parser for CloudFormation YAML. So I think we'd be better off by using a generic snakeyaml wrapper. |
I'll try going ahead with the community maintained https://github.com/clj-commons/clj-yaml, unless there are very good reasons to choose a different library. Any features that are missing in clj-yaml can then be requested at the community maintained repo and will eventually end up in babashka. Good idea? |
Sounds good to me :) |
Why does clj-yaml pull in all these dependencies?
That seems quite a lot for some simple back and forth transformation library? |
Hmm, seems that org.flatland/ordered pulls org.flatland/useful, which then pulls a couple more. I wonder if we could have a version that uses https://github.com/frankiesardo/linked, which seems to have no dependencies. clj-yaml uses ordered set/hashmap for preserving the order of items read from yaml, when read into Clojure data. |
@viesti Tried swapping it out with frankiesardo/linked and that worked: https://github.com/borkdude/clj-yaml, as in: the test worked. Also roundtripped .github/workflows/build.yml with the old version and the one with linked and they yield the same result. At the same time, @slipset is looking into making flatland/ordered not depend on flatland/useful: When that is in place, we can have a look at including it in bb again. |
I have tried with the newest clj-yaml (0.7.1).
It seems it cannot roundtrip that yaml file: |
Re: roundtrip, might this be a YAML thing, Python's PyYAML behaves the same way:
|
So how does one write a Github-actions like YAML file using this library? |
Not helping here, but try roundtripping with "Norway" or "NO" :) |
:flag-no: So I guess roundtripping the built-in boolean type as string would require dropping into snakeyaml Java interop, in similar style as to pyyaml, with a custom constructor & representer. Re: ordered vs clj-yaml patched with linked, I was thinking what the implications would be. They have different tagged literals, but this might not be a user-visible thing? |
Yaml is messy but it would be nice to have it included if possible. It look like it puts snakeyaml puts on: in single quotes 'on': and that makes it legal. Funny how the first thing that was tried looked broken :) |
Here are links to binaries with clj-yaml included: Linux: macOS: I propose folks interested in yaml support test these binaries and report back whether this works as expected in their scripts. |
I wrote a script to assist in migrating my blog from octopress to hugo. Had to run it under clojure because bb didn't have yaml at the time. I just re-ran my migration with bb instead of clojure and it worked the first time. Code I ran: https://github.com/justone/endot-hugo/blob/master/src/cleanup.clj |
Thanks y'all. I merged clj-commons/yaml now into master. When something is missing from that library that you would like to see in bb, go contribute over there. |
Is your feature request related to a problem? Please describe.
I'd like to be able to handle yaml as well as json and edn
Describe the solution you'd like
A yaml library included and exposed in the same way the csv and json are.
The text was updated successfully, but these errors were encountered: