Skip to content

Commit 24f317a

Browse files
authored
fix: use python3 when python not presetn (#3082)
Signed-off-by: Matej Vašek <[email protected]>
1 parent b8cc37a commit 24f317a

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

pkg/functions/runner.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func runPython(ctx context.Context, job *Job) (err error) {
195195
if job.verbose {
196196
fmt.Printf("python -m venv .venv\n")
197197
}
198-
cmd := exec.CommandContext(ctx, "python", "-m", "venv", ".venv")
198+
cmd := exec.CommandContext(ctx, pythonCmd(), "-m", "venv", ".venv")
199199
cmd.Dir = job.Dir()
200200
cmd.Stderr = os.Stderr
201201
cmd.Stdout = os.Stdout
@@ -360,3 +360,11 @@ func choosePort(iface, preferredPort string) (string, error) {
360360
}
361361
return port, nil
362362
}
363+
364+
func pythonCmd() string {
365+
_, err := exec.LookPath("python")
366+
if err != nil {
367+
return "python3"
368+
}
369+
return "python"
370+
}

pkg/oci/python_builder.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (b pythonBuilder) Base(customBase string) string {
2424
if customBase != "" {
2525
return customBase
2626
}
27-
cmd := exec.Command("python", "-V")
27+
cmd := exec.Command(pythonCmd(), "-V")
2828
out, err := cmd.CombinedOutput()
2929
if err != nil {
3030
return defaultPythonBase
@@ -61,7 +61,7 @@ func (b pythonBuilder) WriteShared(job buildJob) (layers []imageLayer, err error
6161
if job.verbose {
6262
fmt.Printf("python -m venv .venv\n")
6363
}
64-
cmd := exec.CommandContext(job.ctx, "python", "-m", "venv", ".venv")
64+
cmd := exec.CommandContext(job.ctx, pythonCmd(), "-m", "venv", ".venv")
6565
cmd.Dir = job.buildDir()
6666
cmd.Stderr = os.Stderr
6767
cmd.Stdout = os.Stdout
@@ -205,3 +205,11 @@ func newPythonLibTarball(job buildJob, root, target string) error {
205205
func (b pythonBuilder) WritePlatform(ctx buildJob, p v1.Platform) (layers []imageLayer, err error) {
206206
return []imageLayer{}, nil
207207
}
208+
209+
func pythonCmd() string {
210+
_, err := exec.LookPath("python")
211+
if err != nil {
212+
return "python3"
213+
}
214+
return "python"
215+
}

0 commit comments

Comments
 (0)