@@ -4,17 +4,11 @@ import (
44 "fmt"
55 "github.com/kluctl/go-embed-python/embed_util"
66 "github.com/kluctl/go-embed-python/python/internal/data"
7- "os"
8- "os/exec"
9- "path/filepath"
10- "runtime"
11- "strings"
127)
138
149type EmbeddedPython struct {
1510 e * embed_util.EmbeddedFiles
16-
17- pythonPath []string
11+ * Python
1812}
1913
2014// NewEmbeddedPython creates a new EmbeddedPython instance. The embedded source code and python binaries are
@@ -26,7 +20,8 @@ func NewEmbeddedPython(name string) (*EmbeddedPython, error) {
2620 return nil , err
2721 }
2822 return & EmbeddedPython {
29- e : e ,
23+ e : e ,
24+ Python : NewPython (WithPythonHome (e .GetExtractedPath ())),
3025 }, nil
3126}
3227
@@ -36,7 +31,8 @@ func NewEmbeddedPythonWithTmpDir(tmpDir string, withHashInDir bool) (*EmbeddedPy
3631 return nil , err
3732 }
3833 return & EmbeddedPython {
39- e : e ,
34+ e : e ,
35+ Python : NewPython (WithPythonHome (e .GetExtractedPath ())),
4036 }, nil
4137}
4238
@@ -47,44 +43,3 @@ func (ep *EmbeddedPython) Cleanup() error {
4743func (ep * EmbeddedPython ) GetExtractedPath () string {
4844 return ep .e .GetExtractedPath ()
4945}
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