Add aocpy lib to PYTHONPATH in Python runner

This commit is contained in:
akp 2021-10-22 21:37:30 +01:00
parent b8d99546a4
commit 27325316ba
No known key found for this signature in database
GPG key ID: AA5726202C8879B7

View file

@ -13,7 +13,7 @@ import (
const python3Installation = "python3"
type pythonRunner struct {
dir string
dir string
tasks []*Task
}
@ -47,8 +47,16 @@ func (p *pythonRunner) Run() chan ResultOrError {
return makeErrorChan(err)
}
cwd, err := os.Getwd()
if err != nil {
return makeErrorChan(err)
}
pythonPathVar := filepath.Join(cwd, "lib")
// Run Python and gather output
cmd := exec.Command(python3Installation, "-B", wrapperFilename) // -B prevents .pyc files from being written
cmd.Env = append(cmd.Env, "PYTHONPATH="+pythonPathVar) // this allows the aocpy lib to be imported
cmd.Dir = p.dir
cmd.Stdin = bytes.NewReader(append(taskJSON, '\n'))
@ -57,4 +65,4 @@ func (p *pythonRunner) Run() chan ResultOrError {
// Remove leftover files
_ = os.Remove(wrapperFilepath)
})
}
}