diff --git a/bundle/artifacts/whl/infer.go b/bundle/artifacts/whl/infer.go index cb727de0e..604bfc449 100644 --- a/bundle/artifacts/whl/infer.go +++ b/bundle/artifacts/whl/infer.go @@ -16,12 +16,6 @@ type infer struct { func (m *infer) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { artifact := b.Config.Artifacts[m.name] - // TODO use python.DetectVEnvExecutable once bundle has a way to specify venv path - py, err := python.DetectExecutable(ctx) - if err != nil { - return diag.FromErr(err) - } - // Note: using --build-number (build tag) flag does not help with re-installing // libraries on all-purpose clusters. The reason is that `pip` ignoring build tag // when upgrading the library and only look at wheel version. @@ -36,7 +30,9 @@ func (m *infer) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { // version=datetime.datetime.utcnow().strftime("%Y%m%d.%H%M%S"), // ... //) - artifact.BuildCommand = fmt.Sprintf(`"%s" setup.py bdist_wheel`, py) + + py := python.GetExecutable() + artifact.BuildCommand = fmt.Sprintf(`%s setup.py bdist_wheel`, py) return nil } diff --git a/libs/python/detect.go b/libs/python/detect.go index ce46d6446..6343b726e 100644 --- a/libs/python/detect.go +++ b/libs/python/detect.go @@ -11,6 +11,21 @@ import ( "runtime" ) +// GetExecutable gets appropriate python binary name for the platform +func GetExecutable() string { + // On Windows when virtualenv is created, the /Scripts directory + // contains python.exe but no python3.exe. However, system python does have python3 entry + // and it is also added to PATH, so it is found first. + + // Most installers (e.g. the ones from python.org) only install python.exe and not python3.exe + + if runtime.GOOS == "windows" { + return "python" + } else { + return "python3" + } +} + // DetectExecutable looks up the path to the python3 executable from the PATH // environment variable. // @@ -26,20 +41,7 @@ func DetectExecutable(ctx context.Context) (string, error) { // // See https://github.com/pyenv/pyenv#understanding-python-version-selection - // On Windows when virtualenv is created, the /Scripts directory - // contains python.exe but no python3.exe. However, system python does have python3 entry - // and it is also added to PATH, so it is found first. - if runtime.GOOS == "windows" { - out, err := exec.LookPath("python") - if err == nil && out != "" { - return out, nil - } - if err != nil && !errors.Is(err, exec.ErrNotFound) { - return "", err - } - } - - out, err := exec.LookPath("python3") + out, err := exec.LookPath(GetExecutable()) // most of the OS'es have python3 in $PATH, but for those which don't, // we perform the latest version lookup