bind

package
v0.4.9 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: BSD-3-Clause Imports: 19 Imported by: 6

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 added in v0.3.0

func CmdStrToMakefile(cmdstr string) string

CmdStrToMakefile does what is needed to make the command string suitable for makefiles * removes -output

func GenPyBind added in v0.3.0

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 added in v0.3.0

func ResetPackages()

ResetPackages resets any accumulated packages -- needed when doing tests

Types

type BindCfg added in v0.3.5

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 added in v0.3.0

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 added in v0.3.2

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

func (*Enum) AddConst added in v0.3.2

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

func (*Enum) Doc added in v0.3.2

func (e *Enum) Doc() string

func (*Enum) GoName added in v0.3.2

func (e *Enum) GoName() string

func (*Enum) GoType added in v0.3.2

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

func (*Enum) ID added in v0.3.2

func (e *Enum) ID() string

func (*Enum) SortConsts added in v0.3.2

func (e *Enum) SortConsts()

type ErrorList

type ErrorList []error

ErrorList is a list of errors

func (*ErrorList) Add added in v0.3.0

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 added in v0.3.0

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 added in v0.3.0

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 added in v0.3.0

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

Interface collects information about a go interface.

func (*Interface) Doc added in v0.3.0

func (it *Interface) Doc() string

func (*Interface) GoName added in v0.3.0

func (it *Interface) GoName() string

func (*Interface) GoType added in v0.3.0

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

func (*Interface) ID added in v0.3.0

func (it *Interface) ID() string

func (*Interface) Interface added in v0.3.0

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

func (*Interface) Package added in v0.3.0

func (it *Interface) Package() *Package

type Map added in v0.3.0

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

Map collects information about a go map.

func (*Map) Doc added in v0.3.0

func (it *Map) Doc() string

func (*Map) GoName added in v0.3.0

func (it *Map) GoName() string

func (*Map) GoType added in v0.3.0

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

func (*Map) ID added in v0.3.0

func (it *Map) ID() string

func (*Map) Map added in v0.3.0

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

func (*Map) Package added in v0.3.0

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 added in v0.3.2

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 added in v0.3.3

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

func GetPythonConfig added in v0.3.3

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 added in v0.3.3

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 added in v0.3.0

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

Slice collects information about a go slice.

func (*Slice) Doc added in v0.3.0

func (it *Slice) Doc() string

func (*Slice) GoName added in v0.3.0

func (it *Slice) GoName() string

func (*Slice) GoType added in v0.3.0

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

func (*Slice) ID added in v0.3.0

func (it *Slice) ID() string

func (*Slice) Package added in v0.3.0

func (it *Slice) Package() *Package

func (*Slice) Slice added in v0.3.0

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 added in v0.3.0

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 added in v0.3.0

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