bind

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2022 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Overview

Package bind provides tools to generate bindings to use Go from Python.

Index

Constants

View Source
const (
	// GoHandle is the type to use for the Handle map key, go-side
	GoHandle = "int64"
	// CGoHandle is Handle for cgo files
	CGoHandle = "C.longlong"
	// PyHandle is within python
	PyHandle = "int64_t"
)
View Source
const (
	ModeGen   BuildMode = "gen"
	ModeBuild           = "build"
	ModeExe             = "exe"
	ModePkg             = "pkg"
)
View Source
const (
	PyBuildPreamble = `` /* 1792-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 = `` /* 524-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 = GoHandle, 5 = CGoHandle, 6 = all imports, 7 = mainstr, 8 = exe pre C, 9 = exe pre go

Variables

View Source
var NoMake = false

NoMake turns off generation of Makefiles

View Source
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.

View Source
var Packages []*Package

Packages accumulates all the packages processed

View Source
var WindowsOS = false

set this to true if OS is windows

Functions

func CmdStrToMakefile

func CmdStrToMakefile(cmdstr string) string

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, 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 BuildMode

type BuildMode string

type Const

type Const struct {
	// contains filtered or unexported fields
}

func (*Const) Doc

func (c *Const) Doc() string

func (*Const) GoName

func (c *Const) GoName() string

func (*Const) GoType

func (c *Const) GoType() types.Type

func (*Const) ID

func (c *Const) ID() string

type Enum

type Enum struct {
	// contains filtered or unexported fields
}

func (*Enum) AddConst

func (e *Enum) AddConst(p *Package, o *types.Const) (*Const, error)

func (*Enum) Doc

func (e *Enum) Doc() string

func (*Enum) GoName

func (e *Enum) GoName() string

func (*Enum) GoType

func (e *Enum) GoType() types.Type

func (*Enum) ID

func (e *Enum) ID() string

func (*Enum) SortConsts

func (e *Enum) SortConsts()

type ErrorList

type ErrorList []error

ErrorList is a list of errors

func (*ErrorList) Add

func (list *ErrorList) Add(err error)

func (*ErrorList) Error

func (list *ErrorList) Error() error

type Func

type Func struct {
	// contains filtered or unexported fields
}

Func collects information about a go func/method.

func (*Func) Doc

func (f *Func) Doc() string

func (*Func) GoFmt

func (f *Func) GoFmt() string

func (*Func) GoName

func (f *Func) GoName() string

func (*Func) GoType

func (f *Func) GoType() types.Type

func (*Func) ID

func (f *Func) ID() string

func (*Func) Obj

func (f *Func) Obj() types.Object

func (*Func) Package

func (f *Func) Package() *Package

func (*Func) Return

func (f *Func) Return() types.Type

func (*Func) Signature

func (f *Func) Signature() *Signature

type Interface

type Interface struct {
	// contains filtered or unexported fields
}

Interface collects information about a go interface.

func (*Interface) Doc

func (it *Interface) Doc() string

func (*Interface) GoName

func (it *Interface) GoName() string

func (*Interface) GoType

func (it *Interface) GoType() types.Type

func (*Interface) ID

func (it *Interface) ID() string

func (*Interface) Interface

func (it *Interface) Interface() *types.Interface

func (*Interface) Package

func (it *Interface) Package() *Package

type Map

type Map struct {
	// contains filtered or unexported fields
}

Map collects information about a go map.

func (*Map) Doc

func (it *Map) Doc() string

func (*Map) GoName

func (it *Map) GoName() string

func (*Map) GoType

func (it *Map) GoType() types.Type

func (*Map) ID

func (it *Map) ID() string

func (*Map) Map

func (it *Map) Map() *types.Map

func (*Map) Package

func (it *Map) Package() *Package

type Object

type Object interface {
	Package() *Package
	ID() string
	Doc() string
	GoName() string
}

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

func NewPackage(pkg *types.Package, doc *doc.Package) (*Package, error)

NewPackage creates a new Package, tying types.Package and ast.Package together.

func (*Package) AddPyImport

func (p *Package) AddPyImport(ipath string, extra bool)

add given path to python imports -- these packages were referenced

func (*Package) ImportPath

func (p *Package) ImportPath() string

ImportPath returns the package import path.

func (*Package) Lookup

func (p *Package) Lookup(o types.Object) (Object, bool)

Lookup returns the bind.Object corresponding to a types.Object

func (*Package) Name

func (p *Package) Name() string

Name returns the package name.

type Protocol

type Protocol int

Protocol encodes the various protocols a python type may implement

const (
	ProtoStringer Protocol = 1 << iota
)

type PyConfig

type PyConfig struct {
	Version   int
	CFlags    string
	LdFlags   string
	ExtSuffix string
}

func GetPythonConfig

func GetPythonConfig(vm string) (PyConfig, error)

GetPythonConfig returns the needed python configuration for the given python VM (python, python2, python3, pypy, etc...)

func (*PyConfig) AllFlags

func (pc *PyConfig) AllFlags() string

AllFlags returns CFlags + " " + LdFlags

type Signature

type Signature struct {
	// contains filtered or unexported fields
}

A Signature represents a (non-builtin) function or method type.

func (*Signature) Params

func (sig *Signature) Params() []*Var

func (*Signature) Recv

func (sig *Signature) Recv() *Var

func (*Signature) Results

func (sig *Signature) Results() []*Var

type Slice

type Slice struct {
	// contains filtered or unexported fields
}

Slice collects information about a go slice.

func (*Slice) Doc

func (it *Slice) Doc() string

func (*Slice) GoName

func (it *Slice) GoName() string

func (*Slice) GoType

func (it *Slice) GoType() types.Type

func (*Slice) ID

func (it *Slice) ID() string

func (*Slice) Package

func (it *Slice) Package() *Package

func (*Slice) Slice

func (it *Slice) Slice() *types.Slice

type Struct

type Struct struct {
	// contains filtered or unexported fields
}

Struct collects information about a go struct.

func (*Struct) Doc

func (s *Struct) Doc() string

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

func (*Struct) GoName

func (s *Struct) GoName() string

func (*Struct) GoType

func (s *Struct) GoType() types.Type

func (*Struct) ID

func (s *Struct) ID() string

func (*Struct) Obj

func (s *Struct) Obj() *types.TypeName

func (*Struct) Package

func (s *Struct) Package() *Package

func (*Struct) Struct

func (s *Struct) Struct() *types.Struct

type Type

type Type interface {
	Object
	GoType() types.Type
}

type Var

type Var struct {
	// contains filtered or unexported fields
}

func (*Var) CGoType

func (v *Var) CGoType() string

func (*Var) CType

func (v *Var) CType() string

func (*Var) GoType

func (v *Var) GoType() types.Type

func (*Var) Name

func (v *Var) Name() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL