-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.go
More file actions
23 lines (19 loc) · 728 Bytes
/
run.go
File metadata and controls
23 lines (19 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package python
import (
"os/exec"
"path/filepath"
)
func getPythonCommand(path string) string {
if dirExists(filepath.Join(path, "./.venv")) {
return filepath.Join(path, ".venv/bin/python")
}
return "python"
}
// GetPythonRunCommand Returns an *exec.Cmd to be handled with the provided "scriptName.py" using the python binary from virtual environment
func GetPythonRunCommand(path string, scriptName string) *exec.Cmd {
return exec.Command(getPythonCommand(path), scriptName)
}
// ExecutePython Executes the provided "scriptName.py" using the python binary from virtual environment
func ExecutePython(path string, scriptName string) ([]byte, error) {
return GetPythonRunCommand(path, scriptName).CombinedOutput()
}