Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions python/pep518.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package python

import (
"io/ioutil"
"os"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
)

func pep518Proc(path string) {
tomlContent := readPyProjectToml(path)
if tomlContent == "" {
return
}

if isUv(path) {
uvProc(path)
Expand All @@ -17,12 +22,11 @@ func pep518Proc(path string) {
}

func readPyProjectToml(path string) string {
// read the whole file at once
b, err := ioutil.ReadFile(filepath.Join(path, "pyproject.toml"))
b, err := os.ReadFile(filepath.Join(path, "pyproject.toml"))
if err != nil {
panic(err)
log.Error(err.Error())
return ""
}

return string(b)
}

Expand Down
9 changes: 3 additions & 6 deletions python/pip.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package python

import (
"fmt"
"os/exec"
"path/filepath"

Expand All @@ -11,14 +10,12 @@ import (
func pipProc(path string) {
log.Info("Found 'requirements.txt'. Creating virtual environment using 'pip' & 'venv' module.")

var cmd *exec.Cmd

// create virtual env
cmd = exec.Command("python3", "-m", "venv", ".venv")
cmd := exec.Command("python3", "-m", "venv", ".venv")
cmd.Dir = path
out, err := cmd.CombinedOutput()
if err != nil {
log.Error(fmt.Sprintf("%s", err.Error()))
log.Error(err.Error())
}
log.Debug(string(out))

Expand All @@ -27,7 +24,7 @@ func pipProc(path string) {
cmd.Dir = path
out, err = cmd.CombinedOutput()
if err != nil {
log.Error(fmt.Sprintf("%s", err.Error()))
log.Error(err.Error())
}
log.Debug(string(out))
}
3 changes: 1 addition & 2 deletions python/pipenv.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package python

import (
"fmt"
"os"
"os/exec"

Expand All @@ -19,7 +18,7 @@ func pipenvProc(path string) {
cmd.Dir = path
out, err := cmd.CombinedOutput()
if err != nil {
log.Error(fmt.Sprintf("%s", err.Error()))
log.Error(err.Error())
}
log.Debug(string(out))
}
8 changes: 4 additions & 4 deletions python/poetry.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package python

import (
"fmt"
"os/exec"
"path/filepath"

log "github.com/sirupsen/logrus"
)
Expand All @@ -11,12 +11,12 @@ func poetryProc(path string) {
log.Info("Found 'pyproject.toml'. Creating virtual environment using 'Poetry'.")

// Make sure .venv will be in project
if !fileExists("poetry.toml") {
if !fileExists(filepath.Join(path, "poetry.toml")) {
cmd := exec.Command("poetry", "config", "--local", "virtualenvs.in-project", "true")
cmd.Dir = path
out, err := cmd.CombinedOutput()
if err != nil {
log.Error(fmt.Sprintf("%s", err.Error()))
log.Error(err.Error())
}
log.Debug(string(out))
}
Expand All @@ -26,7 +26,7 @@ func poetryProc(path string) {
cmd.Dir = path
out, err := cmd.CombinedOutput()
if err != nil {
log.Error(fmt.Sprintf("%s", err.Error()))
log.Error(err.Error())
}
log.Debug(string(out))
}
11 changes: 3 additions & 8 deletions python/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@ import (
func getPythonCommand(path string) string {
if dirExists(filepath.Join(path, "./.venv")) {
return filepath.Join(path, ".venv/bin/python")
} else {
return "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 {
pythonPath := getPythonCommand(path)
return exec.Command(pythonPath, scriptName)
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) {
// run python job
pythonPath := getPythonCommand(path)
cmd := exec.Command(pythonPath, scriptName)
return cmd.CombinedOutput()
return GetPythonRunCommand(path, scriptName).CombinedOutput()
}
3 changes: 1 addition & 2 deletions python/uv.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package python

import (
"fmt"
"os/exec"

log "github.com/sirupsen/logrus"
Expand All @@ -15,7 +14,7 @@ func uvProc(path string) {
cmd.Dir = path
out, err := cmd.CombinedOutput()
if err != nil {
log.Error(fmt.Sprintf("%s", err.Error()))
log.Error(err.Error())
}
log.Debug(string(out))
}
Loading