add GetExecutable(); don't use DetectExecutable() in whl/infer

This commit is contained in:
Denis Bilenko 2024-12-19 14:15:12 +01:00
parent 640de90ba2
commit 2b89625728
2 changed files with 19 additions and 21 deletions

View File

@ -16,12 +16,6 @@ type infer struct {
func (m *infer) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { func (m *infer) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
artifact := b.Config.Artifacts[m.name] 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 // 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 // libraries on all-purpose clusters. The reason is that `pip` ignoring build tag
// when upgrading the library and only look at wheel version. // 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"), // 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 return nil
} }

View File

@ -11,6 +11,21 @@ import (
"runtime" "runtime"
) )
// GetExecutable gets appropriate python binary name for the platform
func GetExecutable() string {
// On Windows when virtualenv is created, the <env>/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 // DetectExecutable looks up the path to the python3 executable from the PATH
// environment variable. // environment variable.
// //
@ -26,20 +41,7 @@ func DetectExecutable(ctx context.Context) (string, error) {
// //
// See https://github.com/pyenv/pyenv#understanding-python-version-selection // See https://github.com/pyenv/pyenv#understanding-python-version-selection
// On Windows when virtualenv is created, the <env>/Scripts directory out, err := exec.LookPath(GetExecutable())
// 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")
// most of the OS'es have python3 in $PATH, but for those which don't, // most of the OS'es have python3 in $PATH, but for those which don't,
// we perform the latest version lookup // we perform the latest version lookup