Skip to content

Commit 0ae9f64

Browse files
First stage changes made. Next step is to change the loop to reflect original design.
1 parent ffb0bab commit 0ae9f64

File tree

13 files changed

+327
-254
lines changed

13 files changed

+327
-254
lines changed

bind/bind.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,34 @@ import (
1616
type BindCfg struct {
1717
// output directory for bindings
1818
OutputDir string
19+
1920
// name of output package (otherwise name of first package is used)
2021
Name string
22+
2123
// code string to run in the go main() function in the cgo library
2224
Main string
25+
2326
// the full command args as a string, without path to exe
2427
Cmd string
28+
2529
// path to python interpreter
2630
VM string
31+
2732
// package prefix used when generating python import statements
2833
PkgPrefix string
34+
2935
// rename Go exported symbols to python PEP snake_case
3036
RenameCase bool
37+
38+
// If set, python exceptions are not thrown.
39+
NoPyExceptions bool
40+
41+
// Path to Go module, which is to be used to translate Go errors to Python exceptions.
42+
ModPathGoErr2PyEx string
43+
44+
// If set, when a Go function returns a (value, err), python returns (value, ) tuple.
45+
// By default, we return just value.
46+
UsePyTuple4VE bool
3147
}
3248

3349
// ErrorList is a list of errors

bind/gen.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ var WindowsOS = false
3838

3939
// for all preambles: 1 = name of package (outname), 2 = cmdstr
4040

41-
// 3 = libcfg, 4 = GoHandle, 5 = CGoHandle, 6 = all imports, 7 = mainstr, 8 = exe pre C, 9 = exe pre go
41+
// 3 = libcfg, 4 = GoHandle, 5 = CGoHandle, 6 = all imports, 7 = goerr2pyex Package path, 8 = mainstr,
42+
// 9 = exe pre C, 10 = exe pre go
4243
const (
4344
goPreamble = `/*
4445
cgo stubs for package %[1]s.
@@ -85,17 +86,19 @@ static inline void gopy_err_handle() {
8586
PyErr_Print();
8687
}
8788
}
88-
%[8]s
89+
%[9]s
8990
*/
9091
import "C"
9192
import (
9293
"github.com/go-python/gopy/gopyh" // handler
94+
"%[7]s" // Error Translator
95+
9396
%[6]s
9497
)
9598
9699
// main doesn't do anything in lib / pkg mode, but is essential for exe mode
97100
func main() {
98-
%[7]s
101+
%[8]s
99102
}
100103
101104
// initialization functions -- can be called from python after library is loaded
@@ -104,7 +107,7 @@ func main() {
104107
105108
//export GoPyInit
106109
func GoPyInit() {
107-
%[7]s
110+
%[8]s
108111
}
109112
110113
// type for the handle -- int64 for speed (can switch to string)
@@ -164,7 +167,7 @@ func complex128PyToGo(o *C.PyObject) complex128 {
164167
return complex(float64(v.real), float64(v.imag))
165168
}
166169
167-
%[9]s
170+
%[10]s
168171
`
169172

170173
goExePreambleC = `
@@ -430,6 +433,9 @@ var NoWarn = false
430433
// NoMake turns off generation of Makefiles
431434
var NoMake = false
432435

436+
// NoPyExceptions turns off generation of Python Exceptions
437+
var NoPyExceptions = false
438+
433439
// GenPyBind generates a .go file, build.py file to enable pybindgen to create python bindings,
434440
// and wrapper .py file(s) that are loaded as the interface to the package with shadow
435441
// python-side classes
@@ -603,7 +609,7 @@ func (g *pyGen) genGoPreamble() {
603609
exeprego = goExePreambleGo
604610
}
605611
g.gofile.Printf(goPreamble, g.cfg.Name, g.cfg.Cmd, libcfg, GoHandle, CGoHandle,
606-
pkgimport, g.cfg.Main, exeprec, exeprego)
612+
pkgimport, g.cfg.ModPathGoErr2PyEx, g.cfg.Main, exeprec, exeprego)
607613
g.gofile.Printf("\n// --- generated code for package: %[1]s below: ---\n\n", g.cfg.Name)
608614
}
609615

0 commit comments

Comments
 (0)