-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathembedded_python.go
More file actions
45 lines (39 loc) · 1.24 KB
/
embedded_python.go
File metadata and controls
45 lines (39 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package python
import (
"fmt"
"github.com/kluctl/go-embed-python/embed_util"
"github.com/kluctl/go-embed-python/python/internal/data"
)
type EmbeddedPython struct {
e *embed_util.EmbeddedFiles
Python
}
// NewEmbeddedPython creates a new EmbeddedPython instance. The embedded source code and python binaries are
// extracted on demand using the given name as the base for the temporary directory. You should ensure that the chosen
// name does collide with other consumers of this library.
func NewEmbeddedPython(name string) (*EmbeddedPython, error) {
e, err := embed_util.NewEmbeddedFiles(data.Data, fmt.Sprintf("python-%s", name))
if err != nil {
return nil, err
}
return &EmbeddedPython{
e: e,
Python: NewPython(WithPythonHome(e.GetExtractedPath())),
}, nil
}
func NewEmbeddedPythonWithTmpDir(tmpDir string, withHashInDir bool) (*EmbeddedPython, error) {
e, err := embed_util.NewEmbeddedFilesWithTmpDir(data.Data, tmpDir, withHashInDir)
if err != nil {
return nil, err
}
return &EmbeddedPython{
e: e,
Python: NewPython(WithPythonHome(e.GetExtractedPath())),
}, nil
}
func (ep *EmbeddedPython) Cleanup() error {
return ep.e.Cleanup()
}
func (ep *EmbeddedPython) GetExtractedPath() string {
return ep.e.GetExtractedPath()
}