@@ -4,17 +4,11 @@ import (
4
4
"fmt"
5
5
"github.com/kluctl/go-embed-python/embed_util"
6
6
"github.com/kluctl/go-embed-python/python/internal/data"
7
- "os"
8
- "os/exec"
9
- "path/filepath"
10
- "runtime"
11
- "strings"
12
7
)
13
8
14
9
type EmbeddedPython struct {
15
10
e * embed_util.EmbeddedFiles
16
-
17
- pythonPath []string
11
+ * Python
18
12
}
19
13
20
14
// NewEmbeddedPython creates a new EmbeddedPython instance. The embedded source code and python binaries are
@@ -26,7 +20,8 @@ func NewEmbeddedPython(name string) (*EmbeddedPython, error) {
26
20
return nil , err
27
21
}
28
22
return & EmbeddedPython {
29
- e : e ,
23
+ e : e ,
24
+ Python : NewPython (WithPythonHome (e .GetExtractedPath ())),
30
25
}, nil
31
26
}
32
27
@@ -36,7 +31,8 @@ func NewEmbeddedPythonWithTmpDir(tmpDir string, withHashInDir bool) (*EmbeddedPy
36
31
return nil , err
37
32
}
38
33
return & EmbeddedPython {
39
- e : e ,
34
+ e : e ,
35
+ Python : NewPython (WithPythonHome (e .GetExtractedPath ())),
40
36
}, nil
41
37
}
42
38
@@ -47,44 +43,3 @@ func (ep *EmbeddedPython) Cleanup() error {
47
43
func (ep * EmbeddedPython ) GetExtractedPath () string {
48
44
return ep .e .GetExtractedPath ()
49
45
}
50
-
51
- func (ep * EmbeddedPython ) GetBinPath () string {
52
- if runtime .GOOS == "windows" {
53
- return ep .GetExtractedPath ()
54
- } else {
55
- return filepath .Join (ep .GetExtractedPath (), "bin" )
56
- }
57
- }
58
-
59
- func (ep * EmbeddedPython ) GetExePath () string {
60
- suffix := ""
61
- if runtime .GOOS == "windows" {
62
- suffix = ".exe"
63
- } else {
64
- suffix = "3"
65
- }
66
- return filepath .Join (ep .GetBinPath (), "python" + suffix )
67
- }
68
-
69
- func (ep * EmbeddedPython ) AddPythonPath (p string ) {
70
- ep .pythonPath = append (ep .pythonPath , p )
71
- }
72
-
73
- func (ep * EmbeddedPython ) PythonCmd (args ... string ) * exec.Cmd {
74
- return ep .PythonCmd2 (args )
75
- }
76
-
77
- func (ep * EmbeddedPython ) PythonCmd2 (args []string ) * exec.Cmd {
78
- exePath := ep .GetExePath ()
79
-
80
- cmd := exec .Command (exePath , args ... )
81
- cmd .Env = os .Environ ()
82
- cmd .Env = append (cmd .Env , fmt .Sprintf ("PYTHONHOME=%s" , ep .GetExtractedPath ()))
83
-
84
- if len (ep .pythonPath ) != 0 {
85
- pythonPathEnv := fmt .Sprintf ("PYTHONPATH=%s" , strings .Join (ep .pythonPath , string (os .PathListSeparator )))
86
- cmd .Env = append (cmd .Env , pythonPathEnv )
87
- }
88
-
89
- return cmd
90
- }
0 commit comments