Skip to content

Commit

Permalink
Use python if python3 is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
pgavlin committed Apr 4, 2024
1 parent d1a20f6 commit b2f2d0d
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 14 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install sphinx
run: pip install sphinx sphinx-rtd-theme sphinx-tabs
- name: Checkout code
uses: actions/checkout@v4
- name: Bootstrap
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install sphinx
run: pip install sphinx sphinx-rtd-theme
- name: Checkout code
uses: actions/checkout@v4
- name: Run GoReleaser
Expand Down
5 changes: 3 additions & 2 deletions docs/BUILD.dawn
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ def venv():
Creates a venv for the docs build.
"""

sh.exec("python3 -m venv venv")
sh.exec(". venv/bin/activate && python3 -m pip install -r requirements.txt")
python = "python3" if os.look_path("python3") != None else "python"
sh.exec(f"{python} -m venv venv")
sh.exec(f". venv/bin/activate && {python} -m pip install -r requirements.txt")

@target(deps=[venv], sources=os.glob(["../README.rst", "source/**", "conf.py"]), generates=["build"])
def site():
Expand Down
12 changes: 12 additions & 0 deletions docs/source/modules/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
the process environment. This mapping is captured at startup time.


.. py:function:: look_path(file)
Search for an executable named file in the directories named by
the PATH environment variable. If file contains a slash, it is
tried directly and the PATH is not consulted. Otherwise, on
success, the result is an absolute path.

:param file: the name of the executable to find

:returns: the absolute path to file if found or None if not found.


.. py:function:: exec(command, cwd=None, env=None, try_=None)
Run an executable. If the process fails, the calling module will
Expand Down
30 changes: 30 additions & 0 deletions lib/os/builtins.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions lib/os/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@ import (
"go.starlark.net/starlark"
)

// def look_path(file):
// """
// Search for an executable named file in the directories named by
// the PATH environment variable. If file contains a slash, it is
// tried directly and the PATH is not consulted. Otherwise, on
// success, the result is an absolute path.
//
// :param file: the name of the executable to find
//
// :returns: the absolute path to file if found or None if not found.
// """
//
//starlark:builtin factory=NewLookPath,function=LookPath
func lookPath(
thread *starlark.Thread,
fn *starlark.Builtin,
file string,
) (starlark.Value, error) {
path, err := exec.LookPath(file)
if err != nil {
return starlark.None, nil
}
return starlark.String(path), nil
}

// def exec(command, cwd=None, env=None, try_=None):
// """
// Run an executable. If the process fails, the calling module will
Expand Down
21 changes: 13 additions & 8 deletions lib/os/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import (
// def environ():
// pass
//
// @function("lookPath")
// def look_path():
// pass
//
// @function("execf")
// def exec():
// pass
Expand Down Expand Up @@ -58,13 +62,14 @@ var Module = &starlarkstruct.Module{
Members: starlark.StringDict{
"path": path.Module,

"environ": NewEnviron(),
"exec": NewExec(),
"output": NewOutput(),
"exists": NewExists(),
"getcwd": NewGetcwd(),
"glob": NewGlob(),
"mkdir": NewMkdir(),
"makedirs": NewMakedirs(),
"environ": NewEnviron(),
"look_path": NewLookPath(),
"exec": NewExec(),
"output": NewOutput(),
"exists": NewExists(),
"getcwd": NewGetcwd(),
"glob": NewGlob(),
"mkdir": NewMkdir(),
"makedirs": NewMakedirs(),
},
}

0 comments on commit b2f2d0d

Please sign in to comment.