Documentation
¶
Overview ¶
Package bind provides tools to generate bindings to use Go from Python.
Index ¶
- Constants
- Variables
- func CmdStrToMakefile(cmdstr string) string
- func GenPyBind(mode BuildMode, libext, extragccargs string, lang int, dynamicLink bool, ...) error
- func ResetPackages()
- type BindCfg
- type BuildMode
- type Const
- type Enum
- type ErrorList
- type Func
- type Interface
- type Map
- type Object
- type Package
- type Protocol
- type PyConfig
- type Signature
- type Slice
- type Struct
- type Type
- type Var
Constants ¶
const ( // GoGopyvar is the type to use for the Gopyvar map key, go-side GoGopyvar = "int64" // CGoGopyvar is Gopyvar for cgo files CGoGopyvar = "C.longlong" // PyGopyvar is within python PyGopyvar = "int64_t" )
const ( ModeGen BuildMode = "gen" ModeBuild = "build" ModeExe = "exe" ModePkg = "pkg" )
const ( PyBuildPreamble = `` /* 1795-byte string literal not displayed */ // 3 = specific package name, 4 = spec pkg path, 5 = doc, 6 = imports PyWrapPreamble = `` /* 725-byte string literal not displayed */ // exe version of preamble -- doesn't need complex code to load _ module // 3 = specific package name, 4 = spec pkg path, 5 = doc, 6 = imports PyWrapExePreamble = `` /* 514-byte string literal not displayed */ GoPkgDefs = `` /* 525-byte string literal not displayed */ // 3 = gencmd, 4 = vm, 5 = libext 6 = extraGccArgs, 7 = CFLAGS, 8 = LDLFAGS, // 9 = windows special declspec hack MakefileTemplate = `` /* 1154-byte string literal not displayed */ // exe version of template: 3 = gencmd, 4 = vm, 5 = libext MakefileExeTemplate = `` /* 1160-byte string literal not displayed */ )
3 = libcfg, 4 = GoGopyvar, 5 = CGoGopyvar, 6 = all imports, 7 = mainstr, 8 = exe pre C, 9 = exe pre go
Variables ¶
var NoMake = false
NoMake turns off generation of Makefiles
var NoWarn = false
NoWarn turns off warnings -- this must be a global as it is relevant during initial package parsing before e.g., thePyGen is present.
var Packages []*Package
Packages accumulates all the packages processed
var WindowsOS = false
set this to true if OS is windows
Functions ¶
func CmdStrToMakefile ¶
CmdStrToMakefile does what is needed to make the command string suitable for makefiles * removes -output
func GenPyBind ¶
func GenPyBind(mode BuildMode, libext, extragccargs string, lang int, dynamicLink bool, cfg *BindCfg) error
GenPyBind generates a .go file, build.py file to enable pybindgen to create python bindings, and wrapper .py file(s) that are loaded as the interface to the package with shadow python-side classes mode = gen, build, pkg, exe
func ResetPackages ¶
func ResetPackages()
ResetPackages resets any accumulated packages -- needed when doing tests
Types ¶
type BindCfg ¶
type BindCfg struct { // output directory for bindings OutputDir string // name of output package (otherwise name of first package is used) Name string // code string to run in the go main() function in the cgo library Main string // the full command args as a string, without path to exe Cmd string // path to python interpreter VM string // package prefix used when generating python import statements PkgPrefix string // rename Go exported symbols to python PEP snake_case RenameCase bool }
BindCfg is a configuration used during binding generation
type Enum ¶
type Enum struct {
// contains filtered or unexported fields
}
func (*Enum) SortConsts ¶
func (e *Enum) SortConsts()
type Func ¶
type Func struct {
// contains filtered or unexported fields
}
Func collects information about a go func/method.
type Interface ¶
type Interface struct {
// contains filtered or unexported fields
}
Interface collects information about a go interface.
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map collects information about a go map.
type Package ¶
type Package struct {
// contains filtered or unexported fields
}
Package ties types.Package and ast.Package together. Package also collects information about specific types (structs, ifaces, etc)
func NewPackage ¶
NewPackage creates a new Package, tying types.Package and ast.Package together.
func (*Package) AddPyImport ¶
add given path to python imports -- these packages were referenced
func (*Package) ImportPath ¶
ImportPath returns the package import path.
type Protocol ¶
type Protocol int
Protocol encodes the various protocols a python type may implement
type PyConfig ¶
type PyConfig struct { Version int CFlags string LdFlags string LdDynamicFlags string ExtSuffix string }
func GetPythonConfig ¶
GetPythonConfig returns the needed python configuration for the given python VM (python, python2, python3, pypy, etc...)
type Signature ¶
type Signature struct {
// contains filtered or unexported fields
}
A Signature represents a (non-builtin) function or method type.
type Slice ¶
type Slice struct {
// contains filtered or unexported fields
}
Slice collects information about a go slice.
type Struct ¶
type Struct struct {
// contains filtered or unexported fields
}
Struct collects information about a go struct.
func (*Struct) FirstEmbed ¶
func (s *Struct) FirstEmbed() *symbol
FirstEmbed returns the first field if it is embedded, supporting convention of placing embedded "parent" types first