Set PYTHONPATH environment variable for Python script scrapers (#4372)

* Set PYTHONPATH environment variable for Python script scrapers
* Convert PYTHONPATH to absolute
* Generalise and apply to plugins

---------

Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
Maista
2023-12-20 03:32:19 +01:00
committed by GitHub
parent 8c922ed9e1
commit e8af3c8e98
3 changed files with 21 additions and 0 deletions

15
pkg/python/env.go Normal file
View File

@@ -0,0 +1,15 @@
package python
import (
"fmt"
"os"
"os/exec"
)
func AppendPythonPath(cmd *exec.Cmd, path string) {
// Respect the users PYTHONPATH if set
if currentValue, set := os.LookupEnv("PYTHONPATH"); set {
path = fmt.Sprintf("%s%c%s", currentValue, os.PathListSeparator, path)
}
cmd.Env = append(os.Environ(), fmt.Sprintf("PYTHONPATH=%s", path))
}