Documentation
¶
Overview ¶
Package python implements a tree-sitter based Python parser for extracting Cog predictor signatures. It walks the concrete syntax tree to extract imports, class definitions, function parameters with type annotations and default values, and Input() call keyword arguments.
This parser is Python-specific. Future languages (e.g. Node.js) would get their own parser package under pkg/schema/.
Index ¶
- func AllChildren(n *sitter.Node) []*sitter.Node
- func CollectImports(root *sitter.Node, source []byte) *schema.ImportContext
- func Content(n *sitter.Node, source []byte) string
- func InheritsFromBaseModel(classNode *sitter.Node, source []byte, imports *schema.ImportContext) bool
- func NamedChildren(n *sitter.Node) []*sitter.Node
- func ParsePredictor(source []byte, predictRef string, mode schema.Mode, sourceDir string) (*schema.PredictorInfo, error)
- func UnwrapClass(node *sitter.Node) *sitter.Node
- func UnwrapFunction(node *sitter.Node) *sitter.Node
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllChildren ¶ added in v0.19.0
AllChildren returns all children (named and anonymous) of a node.
func CollectImports ¶ added in v0.19.0
func CollectImports(root *sitter.Node, source []byte) *schema.ImportContext
func InheritsFromBaseModel ¶ added in v0.19.0
func NamedChildren ¶ added in v0.19.0
NamedChildren returns all named children of a node.
func ParsePredictor ¶
func ParsePredictor(source []byte, predictRef string, mode schema.Mode, sourceDir string) (*schema.PredictorInfo, error)
ParsePredictor parses Python source and extracts predictor information. predictRef is the class or function name (e.g. "Predictor" or "predict"). mode controls whether we look for predict or train method. sourceDir is the project root for resolving cross-file imports. Pass "" if unknown.
Types ¶
This section is empty.