@@ -9,21 +9,29 @@ import (
9
9
"strings"
10
10
)
11
11
12
- type Python struct {
12
+ type Python interface {
13
+ GetExeName () string
14
+ GetExePath () (string , error )
15
+ AddPythonPath (p string )
16
+ PythonCmd (args ... string ) (* exec.Cmd , error )
17
+ PythonCmd2 (args []string ) (* exec.Cmd , error )
18
+ }
19
+
20
+ type python struct {
13
21
pythonHome string
14
22
pythonPath []string
15
23
}
16
24
17
- type PythonOpt func (o * Python )
25
+ type PythonOpt func (o * python )
18
26
19
27
func WithPythonHome (home string ) PythonOpt {
20
- return func (o * Python ) {
28
+ return func (o * python ) {
21
29
o .pythonHome = home
22
30
}
23
31
}
24
32
25
- func NewPython (opts ... PythonOpt ) * Python {
26
- ep := & Python {}
33
+ func NewPython (opts ... PythonOpt ) Python {
34
+ ep := & python {}
27
35
28
36
for _ , o := range opts {
29
37
o (ep )
@@ -32,7 +40,7 @@ func NewPython(opts ...PythonOpt) *Python {
32
40
return ep
33
41
}
34
42
35
- func (ep * Python ) GetExeName () string {
43
+ func (ep * python ) GetExeName () string {
36
44
suffix := ""
37
45
if runtime .GOOS == "windows" {
38
46
suffix = ".exe"
@@ -42,7 +50,7 @@ func (ep *Python) GetExeName() string {
42
50
return "python" + suffix
43
51
}
44
52
45
- func (ep * Python ) GetExePath () (string , error ) {
53
+ func (ep * python ) GetExePath () (string , error ) {
46
54
if ep .pythonHome == "" {
47
55
p , err := exec .LookPath (ep .GetExeName ())
48
56
if err != nil {
@@ -63,15 +71,15 @@ func (ep *Python) GetExePath() (string, error) {
63
71
}
64
72
}
65
73
66
- func (ep * Python ) AddPythonPath (p string ) {
74
+ func (ep * python ) AddPythonPath (p string ) {
67
75
ep .pythonPath = append (ep .pythonPath , p )
68
76
}
69
77
70
- func (ep * Python ) PythonCmd (args ... string ) (* exec.Cmd , error ) {
78
+ func (ep * python ) PythonCmd (args ... string ) (* exec.Cmd , error ) {
71
79
return ep .PythonCmd2 (args )
72
80
}
73
81
74
- func (ep * Python ) PythonCmd2 (args []string ) (* exec.Cmd , error ) {
82
+ func (ep * python ) PythonCmd2 (args []string ) (* exec.Cmd , error ) {
75
83
exePath , err := ep .GetExePath ()
76
84
if err != nil {
77
85
return nil , err
0 commit comments