Documentation
¶
Overview ¶
Package gen implements Python module introspection and Go code generation.
Index ¶
- func GoFuncName(pyName string) string
- func GoParamName(pyName string) string
- func ScaffoldInit(modules []string, pythonConstraint string) error
- func ScaffoldSync() error
- type ClassInfo
- type Config
- type EnumInfo
- type EnumMember
- type FuncInfo
- type Generator
- type Introspector
- type Mapper
- type ModuleInfo
- type ParamInfo
- type PropInfo
- type TypeInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GoFuncName ¶
GoFuncName converts snake_case to PascalCase. Also strips module prefixes (dots) and handles PascalCase input.
func GoParamName ¶
GoParamName converts snake_case to camelCase, escaping Go reserved words.
func ScaffoldInit ¶
ScaffoldInit generates pyproject.toml and pyffi-gen.yaml.
Types ¶
type ClassInfo ¶
type ClassInfo struct {
PythonName string
GoName string
Init *FuncInfo // __init__ → NewXxx; nil if absent
Methods []FuncInfo
Properties []PropInfo
Doc string
}
ClassInfo describes a Python class.
type Config ¶
type Config struct {
Module string `yaml:"module"`
Package string `yaml:"package"`
Out string `yaml:"out"`
Include []string `yaml:"include"`
Exclude []string `yaml:"exclude"`
TypeOverrides map[string]string `yaml:"type_overrides"`
DocStyle string `yaml:"doc_style"`
Test bool `yaml:"test"`
Python string `yaml:"python"`
Dependencies []string `yaml:"dependencies"`
}
Config represents the pyffi-gen.yaml configuration.
func LoadConfig ¶
LoadConfig reads a YAML config file.
type EnumInfo ¶
type EnumInfo struct {
PythonName string
GoName string
Members []EnumMember
}
EnumInfo describes a Python Enum class.
type EnumMember ¶
EnumMember is a single enum value.
type FuncInfo ¶
type FuncInfo struct {
PythonName string
GoName string // PascalCase
Params []ParamInfo
Returns TypeInfo
Doc string
}
FuncInfo describes a Python function or method.
type Generator ¶
Generator orchestrates code generation.
func NewGenerator ¶
NewGenerator creates a generator from config.
type Introspector ¶
type Introspector struct {
// contains filtered or unexported fields
}
Introspector runs Python to extract module metadata.
func NewIntrospector ¶
func NewIntrospector(opts ...pyffi.Option) (*Introspector, error)
NewIntrospector creates a Python runtime and loads helper functions.
func (*Introspector) Close ¶
func (i *Introspector) Close() error
Close releases the Python runtime.
func (*Introspector) Introspect ¶
func (i *Introspector) Introspect(moduleName string, include, exclude []string, mapper *Mapper) (*ModuleInfo, error)
Introspect extracts metadata from the named Python module.
type Mapper ¶
Mapper converts Python type annotations to Go types.
type ModuleInfo ¶
type ModuleInfo struct {
PythonModule string
GoPackage string
Functions []FuncInfo
Classes []ClassInfo
Enums []EnumInfo
Doc string
ClassNames map[string]bool // set of Go class names generated in this package
}
ModuleInfo holds the complete introspection result for a Python module.
type ParamInfo ¶
type ParamInfo struct {
PythonName string
GoName string // camelCase
Type TypeInfo
HasDefault bool
IsKwOnly bool
}
ParamInfo describes a function parameter.