Skip to content

Commit

Permalink
feat(CLI): Add go API to support LSP (#302)
Browse files Browse the repository at this point in the history
* feat: Add go api package

Signed-off-by: Ce Gao <cegao@tensorchord.ai>

* fix: Update

Signed-off-by: Ce Gao <cegao@tensorchord.ai>
  • Loading branch information
gaocegege committed Jun 20, 2022
1 parent 5da153f commit 6bd547e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
3 changes: 3 additions & 0 deletions envd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Our documentation generation framework doesn't properly handle __file__,
# so we call it __file__ and edit it later.
file__: str = ""
54 changes: 54 additions & 0 deletions envd/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package envd

import (
"bytes"
"embed"
"fmt"
"io/fs"
"os"
"path/filepath"
)

//go:embed api/*.py api/**/*.py
var api embed.FS

const autoGeneratedHeader = `### AUTO-GENERATED ###
# To make changes, modify the following file in the envd repository:
# envd/%s
`

func ApiStubs() fs.FS {
f, err := fs.Sub(api, "api")
if err != nil {
panic(err)
}
return f
}

func WalkApiStubs(fn fs.WalkDirFunc) error {
return fs.WalkDir(api, "api", fn)
}

func DumpApiStubs(dir string, callback func(string, error)) error {
return WalkApiStubs(func(path string, d fs.DirEntry, e error) error {
if e != nil {
return e
}
var err error
dest := filepath.Join(dir, path)
if d.IsDir() {
err = os.MkdirAll(dest, 0755)
} else {
buf := bytes.NewBufferString(fmt.Sprintf(autoGeneratedHeader, path))
var bytes []byte
bytes, err = api.ReadFile(path)
if err != nil {
return err
}
buf.Write(bytes)
err = os.WriteFile(dest, buf.Bytes(), 0644)
}
callback(path, err)
return err
})
}
4 changes: 2 additions & 2 deletions envd/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def base(os: str, language: str):


def shell(name: str):
"""Interactive shell
"""Interactive shell
Args:
name (str): shell name(i.e. `zsh`)
"""
Expand All @@ -50,4 +50,4 @@ def git_config(name: Optional[str] = None,
email (optional, str): User email
editor (optional, str): Editor for git operations
"""
pass
pass
File renamed without changes.
File renamed without changes.

0 comments on commit 6bd547e

Please sign in to comment.