mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
6.98k stars 332 forks source link

Create Python bindings #1011

Closed sisp closed 1 year ago

sisp commented 1 year ago

I've stumbled over this project because Task uses it:

Task uses mvdan.cc/sh, a native Go sh interpreter. So you can write sh/bash commands, and it will work even on Windows, where sh or bash are usually not available. Just remember any executable called must be available by the OS or in PATH.

https://taskfile.dev/usage/#getting-started

We have a similar use case in Copier where cross-platform shell commands may be declare by template creators through the tasks feature. Copier is written in Python though, so I've been wondering whether you might be open to providing Python bindings to sh since there already exists a JS package (through transpilation though). It seems possible to create Python bindings for Go libraries using gopy. I'd be happy to look into it if you agree on the general idea. :slightly_smiling_face:

mvdan commented 1 year ago

By all means go ahead :) I don't have the time to do this myself, but am happy to help on our side where needed. You might struggle with the syntax tree types, since those are trees of pointers which make use of interfaces to mimic sum types. That's ultimately why I wrote https://pkg.go.dev/mvdan.cc/sh/v3/syntax/typedjson - not just for shfmt --to-json, but also for interfacing with languages like JS so that the syntax tree can be encoded to bytes.

mvdan commented 1 year ago

I'm going to close this as there isn't anything actionable to do here. As said above, I'm happy to support the effort to do bindings, but I don't have the time to do them myself, so they won't be in this repository.