Skip to content

Commit 9e491ab

Browse files
Randall C. O'Reillysbinet
Randall C. O'Reilly
authored andcommitted
most of PR review comments addressed -- few more to tackle tmrw. haven't changed import paths yet b/c still working out of my dir -- will do that as a last step.
1 parent 603eba4 commit 9e491ab

34 files changed

+506
-289
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright ©2019 The go-python Authors. All rights reserved.
1+
Copyright ©2015 The go-python Authors. All rights reserved.
22

33
Redistribution and use in source and binary forms, with or without
44
modification, are permitted provided that the following conditions are met:

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ gopy -
5757

5858
Commands:
5959

60-
pkg generate and compile Python bindings for go, automatically including subdirs
60+
pkg generate and compile Python bindings for Go, automatically including subdirs
6161
also creates all the python files needed to install module
62-
exe like pkg but makes a standalone executable with go packages bultin
62+
exe like pkg but makes a standalone executable with Go packages bultin
6363
this is particularly useful when using -main arg to start process on
6464
gen generate (C)Python language bindings for Go
6565
build generate and compile
@@ -71,7 +71,7 @@ Use "gopy help <command>" for more information about a command.
7171
$ gopy help pkg
7272
Usage: gopy pkg <go-package-name> [other-go-package...]
7373

74-
pkg generates and compiles (C)Python language bindings for a Go package, including subdirectories, and generates python module packaging suitable for distribution. if setup.py file does not yet exist in the target directory, then it along with other default packaging files are created, using arguments. Typically you create initial default versions of these files and then edit them, and after that, only regenerate the go binding files.
74+
pkg generates and compiles (C)Python language bindings for a Go package, including subdirectories, and generates python module packaging suitable for distribution. if setup.py file does not yet exist in the target directory, then it is created along with other default packaging files, using arguments. Typically you create initial default versions of these files and then edit them, and after that, only regenerate the Go binding files.
7575

7676
ex:
7777
$ gopy pkg [options] <go-package-name> [other-go-package...]
@@ -82,7 +82,7 @@ Options:
8282
-desc="": short description of project (long comes from README.md)
8383
-email="[email protected]": author email
8484
-exclude="": comma-separated list of package names to exclude
85-
-main="": code string to run in the go GoPyInit() function in the cgo library
85+
-main="": code string to run in the Go GoPyInit() function in the cgo library
8686
-name="": name of output package (otherwise name of first package is used)
8787
-output="": output directory for root of package
8888
-symbols=true: include symbols in output
@@ -95,7 +95,7 @@ Options:
9595
$ gopy help exe
9696
Usage: gopy exe <go-package-name> [other-go-package...]
9797

98-
exe generates and compiles (C)Python language bindings for a Go package, including subdirectories, and generates a standalone python executable and associated module packaging suitable for distribution. if setup.py file does not yet exist in the target directory, then it along with other default packaging files are created, using arguments. Typically you create initial default versions of these files and then edit them, and after that, only regenerate the go binding files.
98+
exe generates and compiles (C)Python language bindings for a Go package, including subdirectories, and generates a standalone python executable and associated module packaging suitable for distribution. if setup.py file does not yet exist in the target directory, then it along with other default packaging files are created, using arguments. Typically you create initial default versions of these files and then edit them, and after that, only regenerate the Go binding files.
9999

100100
The primary need for an exe instead of a pkg dynamic library is when the main thread must be used for something other than running the python interpreter, such as for a GUI library where the main thread must be used for running the GUI event loop (e.g., GoGi).
101101

@@ -108,7 +108,7 @@ Options:
108108
-desc="": short description of project (long comes from README.md)
109109
-email="[email protected]": author email
110110
-exclude="": comma-separated list of package names to exclude
111-
-main="": code string to run in the go main() function in the cgo library -- defaults to GoPyMainRun() but typically should be overriden
111+
-main="": code string to run in the Go main() function in the cgo library -- defaults to GoPyMainRun() but typically should be overriden
112112
-name="": name of output package (otherwise name of first package is used)
113113
-output="": output directory for root of package
114114
-symbols=true: include symbols in output
@@ -127,7 +127,7 @@ ex:
127127
$ gopy gen github.com/go-python/gopy/_examples/hi
128128

129129
Options:
130-
-main="": code string to run in the go main() function in the cgo library
130+
-main="": code string to run in the Go main() function in the cgo library
131131
-name="": name of output package (otherwise name of first package is used)
132132
-output="": output directory for bindings
133133
-vm="python": path to python interpreter
@@ -142,7 +142,7 @@ ex:
142142
$ gopy build github.com/go-python/gopy/_examples/hi
143143

144144
Options:
145-
-main="": code string to run in the go main() function in the cgo library
145+
-main="": code string to run in the Go main() function in the cgo library
146146
-name="": name of output package (otherwise name of first package is used)
147147
-output="": output directory for bindings
148148
-symbols=true: include symbols in output
1.65 KB
Binary file not shown.

_examples/funcs/funcs.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ type FunStruct struct {
1515
FieldS string
1616
}
1717

18-
func (fs *FunStruct) CallBack(arg1 int, fun func(afs *FunStruct, a1 int, s1 string)) {
19-
fun(fs, arg1, fs.FieldS)
18+
func (fs *FunStruct) CallBack(i int, fun func(fs *FunStruct, i int, s string)) {
19+
fun(fs, i, fs.FieldS)
2020
}
2121

22-
type RecvFunc func(afs *FunStruct, a1 int, if1 interface{})
22+
type RecvFunc func(fs *FunStruct, i int, v interface{})
2323

24-
func (fs *FunStruct) CallBackIf(arg1 int, fun RecvFunc) {
25-
fun(fs, arg1, fs.FieldS)
24+
func (fs *FunStruct) CallBackIf(i int, fun RecvFunc) {
25+
fun(fs, i, fs.FieldS)
2626
}
2727

28-
func (fs *FunStruct) OtherMeth(arg1 int, args string) {
29-
fs.FieldI = arg1
30-
fs.FieldS = args
31-
fmt.Printf("arg1: %d args: %s\n", arg1, args)
28+
func (fs *FunStruct) OtherMeth(i int, s string) {
29+
fs.FieldI = i
30+
fs.FieldS = s
31+
fmt.Printf("i=%d s=%s\n", i, s)
3232
}
3333

3434
func (fs *FunStruct) ObjArg(ofs *FunStruct) {

_examples/funcs/test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def CallSelf(self):
5454
print("fs.ObjArg with fs")
5555
fs.ObjArg(fs)
5656

57-
# todo: not currently supported:
57+
# TODO: not currently supported:
5858

5959
# print("funcs.F1()...")
6060
# f1 = funcs.F1()

_examples/hi/hi.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,20 @@ func (p *Person) GetAge() int {
130130
return p.Age
131131
}
132132

133-
func (p *Person) SetName(nm string) {
134-
p.Name = nm
133+
func (p *Person) SetName(n string) {
134+
p.Name = n
135135
}
136136

137-
func (p *Person) SetAge(ag int) {
138-
p.Age = ag
137+
func (p *Person) SetAge(age int) {
138+
p.Age = age
139139
}
140140

141-
func (p *Person) SetFmS2(s2arg structs.S2) {
142-
p.Age = s2arg.Public
141+
func (p *Person) SetFmS2(s2 structs.S2) {
142+
p.Age = s2.Public
143143
}
144144

145-
func (p *Person) SetFmS2Ptr(s2arg *structs.S2) {
146-
p.Age = s2arg.Public
145+
func (p *Person) SetFmS2Ptr(s2 *structs.S2) {
146+
p.Age = s2.Public
147147
}
148148

149149
func (p *Person) ReturnS2Ptr() *structs.S2 {
@@ -178,7 +178,7 @@ type Floats []Float
178178
// Eval evals float64
179179
type Eval func(f float64) float64
180180

181-
// PersIface is an interface into the person type
181+
// PersIface is an interface into the person type.
182182
type PersIface interface {
183183
// GetName returns the name of the person
184184
GetName() string
@@ -187,7 +187,7 @@ type PersIface interface {
187187
GetAge() int
188188

189189
// SetName sets name
190-
SetName(nm string)
190+
SetName(n string)
191191

192192
// SetAge sets age
193193
SetAge(age int)

_examples/hi/test.py

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
import hi
88

9+
# NOTE: the output from python2 is different from that of 3, and test
10+
# targets python3 so it appears to fail for 2.
11+
912
print("--- doc(hi)...")
1013
print(hi.__doc__)
1114

@@ -167,6 +170,8 @@
167170

168171
## test Couple.__init__
169172
print("--- Couple.__init__")
173+
# Note: pybindgen does not automatically support varargs, so in general
174+
# all python calls need to provide the full Go signature of args.
170175
#c = hi.Couple(hi.Person("p1", 42))
171176
#print(c)
172177
c = hi.Couple(hi.Person("p1", 42), hi.Person("p2", 52))

_examples/iface/iface.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ func IfaceString(str interface{}) {
3636
cpkg.Printf("iface as string: %v\n", str)
3737
}
3838

39-
//gopy:interface=handle this magic directive says, treat it as a handle
39+
//gopy:interface=handle
40+
// this magic directive says, treat the interface arg as a handle
4041
func IfaceHandle(ifc interface{}) {
4142
cpkg.Printf("iface as handle: %v\n", ifc)
4243
}

_examples/maps/test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
print('map a[1]:', a[1])
3030
print('map a[2]:', a[2])
3131

32-
# todo: not sure why python2 doesn't just catch this error, but it doesn't seem to..
32+
# TODO: not sure why python2 doesn't just catch this error, but it doesn't seem to..
3333
# try:
3434
# v = a[4]
3535
# except Exception as err:

_examples/named/named.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// package named tests various aspects of named types.
66
package named
77

8-
// todo: not dealing with named basic types -- not very intuitive to use
8+
// TODO: not dealing with named basic types -- not very intuitive to use
99
// in python, as they have to become classes. instead anything like this
1010
// is converted to its basic type when used as an arg / return value
1111
// so you can use them in other methods, but their special type methods

_examples/unicode/test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
bytestr = b"Python byte string"
2222
unicodestr = u"Python Unicode string 🐱"
2323

24-
# todo: need conversion from bytestr to string -- not sure pybindgen can do it?
24+
# TODO: need conversion from bytestr to string -- not sure pybindgen can do it?
2525
#bytestr_ret = encoding.HandleString(bytestr)
2626
unicodestr_ret = encoding.HandleString(unicodestr)
2727

0 commit comments

Comments
 (0)