mirror of https://github.com/stashapp/stash.git
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:
parent
8c922ed9e1
commit
e8af3c8e98
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
|
@ -52,6 +53,9 @@ func (t *rawPluginTask) Start() error {
|
|||
logger.Warnf("%s", err)
|
||||
} else {
|
||||
cmd = p.Command(context.TODO(), command[1:])
|
||||
|
||||
envVariable, _ := filepath.Abs(filepath.Dir(filepath.Dir(t.plugin.path)))
|
||||
python.AppendPythonPath(cmd, envVariable)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
|
@ -44,6 +44,8 @@ func (s *scriptScraper) runScraperScript(ctx context.Context, inString string, o
|
|||
logger.Warnf("%s", err)
|
||||
} else {
|
||||
cmd = p.Command(context.TODO(), command[1:])
|
||||
envVariable, _ := filepath.Abs(filepath.Dir(filepath.Dir(s.config.path)))
|
||||
python.AppendPythonPath(cmd, envVariable)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue