Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python not being resolved correctly if not in path #4864

Merged
merged 2 commits into from
May 22, 2024
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
9 changes: 6 additions & 3 deletions pkg/plugin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/stashapp/stash/pkg/plugin/hook"
"github.com/stashapp/stash/pkg/python"
"github.com/stashapp/stash/pkg/utils"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -294,16 +295,18 @@ func (c Config) getConfigPath() string {
}

func (c Config) getExecCommand(task *OperationConfig) []string {
ret := c.Exec
// #4859 - don't modify the original exec command
ret := append([]string{}, c.Exec...)

if task != nil {
ret = append(ret, task.ExecArgs...)
}

if len(ret) > 0 {
// #4859 - don't use the plugin path in the exec command if it is a python command
if len(ret) > 0 && !python.IsPythonCommand(ret[0]) {
_, err := exec.LookPath(ret[0])
if err != nil {
// change command to use absolute path
// change command to run from the plugin path
pluginPath := filepath.Dir(c.path)
ret[0] = filepath.Join(pluginPath, ret[0])
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/python/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Resolve(configuredPythonPath string) (*Python, error) {
case err == nil && !isFile:
logger.Warnf("configured python path is not a file: %s", configuredPythonPath)
case err != nil:
logger.Warnf("unable to use configured python path: %s", err)
logger.Warnf("unable to use configured python path: %v", err)
}
}

Expand All @@ -44,7 +44,7 @@ func Resolve(configuredPythonPath string) (*Python, error) {
if err != nil {
python, err := exec.LookPath("python")
if err != nil {
return nil, fmt.Errorf("python executable not in PATH: %s", err)
return nil, fmt.Errorf("python executable not in PATH: %w", err)
}
ret := Python(python)
return &ret, nil
Expand Down
Loading