From 45acf8e9dc807c68fa8541c7df1574772d9880f5 Mon Sep 17 00:00:00 2001 From: Zois Pagoulatos Date: Thu, 14 Dec 2023 22:34:05 +0200 Subject: [PATCH] Patch: Provide path as command root during virtual environment creation --- go.mod | 6 ++++-- go.sum | 18 ++++++++++++------ python/pep518.go | 4 ++-- python/pip.go | 2 ++ python/pipenv.go | 3 ++- python/poetry.go | 4 +++- python/pyflow.go | 3 ++- python/virtualenv.go | 2 +- 8 files changed, 28 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 42f3a6f..d7162c7 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,7 @@ module github.com/zoispag/go-python-runner -go 1.13 +go 1.21 -require github.com/sirupsen/logrus v1.8.1 +require github.com/sirupsen/logrus v1.9.3 + +require golang.org/x/sys v0.15.0 // indirect diff --git a/go.sum b/go.sum index 59bd790..3b670c0 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,16 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= -github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/python/pep518.go b/python/pep518.go index a6fbeaa..0d2204a 100644 --- a/python/pep518.go +++ b/python/pep518.go @@ -10,9 +10,9 @@ func pep518Proc(path string) { tomlContent := readPyProjectToml(path) if isPoetry(tomlContent) { - poetryProc() + poetryProc(path) } else if isPyFlow(tomlContent) { - pyflowProc() + pyflowProc(path) } } diff --git a/python/pip.go b/python/pip.go index 89d4c8d..76648af 100644 --- a/python/pip.go +++ b/python/pip.go @@ -15,6 +15,7 @@ func pipProc(path string) { // create virtual env cmd = exec.Command("python3", "-m", "venv", ".venv") + cmd.Dir = path out, err := cmd.CombinedOutput() if err != nil { log.Error(fmt.Sprintf("%s", err.Error())) @@ -23,6 +24,7 @@ func pipProc(path string) { // install dependencies cmd = exec.Command(filepath.Join(path, ".venv/bin/pip"), "install", "-r", "requirements.txt") + cmd.Dir = path out, err = cmd.CombinedOutput() if err != nil { log.Error(fmt.Sprintf("%s", err.Error())) diff --git a/python/pipenv.go b/python/pipenv.go index 4164c90..7e7ef47 100644 --- a/python/pipenv.go +++ b/python/pipenv.go @@ -8,7 +8,7 @@ import ( log "github.com/sirupsen/logrus" ) -func pipenvProc() { +func pipenvProc(path string) { log.Info("Found 'Pipfile'. Creating virtual environment using 'pipenv'.") // Make sure .venv will be in project @@ -16,6 +16,7 @@ func pipenvProc() { // install dependencies cmd := exec.Command("pipenv", "install") + cmd.Dir = path out, err := cmd.CombinedOutput() if err != nil { log.Error(fmt.Sprintf("%s", err.Error())) diff --git a/python/poetry.go b/python/poetry.go index 5cb7ce9..2eea9ca 100644 --- a/python/poetry.go +++ b/python/poetry.go @@ -7,12 +7,13 @@ import ( log "github.com/sirupsen/logrus" ) -func poetryProc() { +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") { 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())) @@ -22,6 +23,7 @@ func poetryProc() { // install dependencies cmd := exec.Command("poetry", "install") + cmd.Dir = path out, err := cmd.CombinedOutput() if err != nil { log.Error(fmt.Sprintf("%s", err.Error())) diff --git a/python/pyflow.go b/python/pyflow.go index 9199e83..ca2c5cd 100644 --- a/python/pyflow.go +++ b/python/pyflow.go @@ -7,11 +7,12 @@ import ( log "github.com/sirupsen/logrus" ) -func pyflowProc() { +func pyflowProc(path string) { log.Info("Found 'pyproject.toml'. Creating virtual environment using 'PyFlow'.") // install dependencies cmd := exec.Command("pyflow", "install") + cmd.Dir = path out, err := cmd.CombinedOutput() if err != nil { log.Error(fmt.Sprintf("%s", err.Error())) diff --git a/python/virtualenv.go b/python/virtualenv.go index 4e064ce..155b26b 100644 --- a/python/virtualenv.go +++ b/python/virtualenv.go @@ -35,7 +35,7 @@ func SetupVirtualEnv(path string) { // Poetry or PyFlow pep518Proc(path) } else if fileExists(filepath.Join(path, "Pipfile")) { - pipenvProc() + pipenvProc(path) } else if fileExists(filepath.Join(path, "requirements.txt")) { pipProc(path) }