vpython: make sure that venv falls before system python in path when executing vpython. Bug: b/491263752 Change-Id: I48995ea1118dd1346bf6d7422fab616a6a6a6964 Reviewed-on: https://chromium-review.googlesource.com/c/infra/luci/luci-go/+/7929928 Commit-Queue: Alex Ovsienko <ovsienko@google.com> Reviewed-by: Richard Wang <richardwa@google.com>
diff --git a/vpython/application/application.go b/vpython/application/application.go index ddb28dd..0c3a8ab 100644 --- a/vpython/application/application.go +++ b/vpython/application/application.go
@@ -447,6 +447,17 @@ env := environ.New(a.Environments) python.IsolateEnvironment(&env) + // Prepend venv path in the path to make sure system python + // will not get executed. + if a.PythonExecutable != "" { + venvDir := filepath.Dir(a.PythonExecutable) + if curPath, ok := env.Lookup("PATH"); ok { + env.Set("PATH", strings.Join([]string{venvDir, curPath}, string(os.PathListSeparator))) + } else { + env.Set("PATH", venvDir) + } + } + cl := a.PythonCommandLine.Clone() cl.AddSingleFlag("s")