bazelbuild / starlark

Starlark Language
Apache License 2.0
2.44k stars 162 forks source link

Support yaml marshal/unmarshal #219

Open alexeagle opened 2 years ago

alexeagle commented 2 years ago

For all the same reasons the json module was added to starlark. Note there's an implementation over here for the Go implementation of starlark https://github.com/qri-io/starlib/tree/master/encoding/yaml but I doubt that's useful in any way.

The motivation is that the pnpm tool needs to be integrated as a repository rule, and the data needed to fetch packages in in yaml: https://pnpm.io/git#lockfiles

As a workaround we're using the yq toolchain to translate yaml to json, which starlark does know how to read: https://docs.aspect.build/aspect-build/bazel-lib/v0.9.6/docs/yq-docgen.html#yq however it's difficult in a Bazel repository rule to access a tool provided by a toolchain, and impossible under bzlmod (https://github.com/bazelbuild/bazel/issues/14445 - one module extension fetches a yq binary but another module extension wants to run it)

loeffel-io commented 1 year ago

+1

albertocavalcante commented 2 months ago

@alexeagle I'm also interested in this topic. Do you know what's required to move it forward?

alexeagle commented 2 months ago

It would require buy-in from language spec as well as the three major implementations to commit to supporting it. @laurentlb might be able to provide guidance if you care enough about this to be the champion. If you just need basic yaml parsing, @kormide wrote a partial parser in starlark used in earlier rules_js releases.