MCPcopy Create free account
hub / github.com/SplootCode/splootcode / loadPythonModule

Function loadPythonModule

packages/language-python/src/scope/python.ts:46–123  ·  view source on GitHub ↗
(scope: PythonScope, moduleSpec: PythonModuleSpec)

Source from the content-addressed store, hash-verified

44}
45
46export function loadPythonModule(scope: PythonScope, moduleSpec: PythonModuleSpec) {
47 const moduleDefinition: ModuleDefinition = {
48 category: TypeCategory.Module,
49 attributes: new Map(),
50 loaded: true,
51 }
52 for (const name in moduleSpec.values) {
53 const spec = moduleSpec.values[name]
54 if (spec.isCallable) {
55 const typeInfo: VariableTypeInfo = {
56 category: TypeCategory.Function,
57 shortDoc: spec.shortDoc,
58 arguments: [],
59 }
60 if (spec.parameters) {
61 const args = spec.parameters.map((argInfo) => {
62 const arg: FunctionArgument = {
63 name: argInfo.name,
64 type: functionArgTypeMapping[argInfo.kind],
65 }
66 if (argInfo.default) {
67 arg.defaultValue = argInfo.default
68 }
69 return arg
70 })
71 typeInfo.arguments = args
72 }
73 moduleDefinition.attributes.set(name, typeInfo)
74 } else {
75 const typeInfo: VariableTypeInfo = {
76 category: TypeCategory.Value,
77 typeName: spec.typeName,
78 shortDoc: spec.shortDoc,
79 }
80 moduleDefinition.attributes.set(name, typeInfo)
81 }
82 }
83 scope.addModuleDefinition(moduleSpec.moduleName, moduleDefinition)
84 for (const name in moduleSpec.types) {
85 const spec = moduleSpec.types[name]
86
87 const attributes: Map<string, VariableTypeInfo> = new Map()
88 Object.values(spec.attributes).forEach((attr) => {
89 if (!attr.isCallable) {
90 attributes.set(attr.name, {
91 category: TypeCategory.Value,
92 typeName: attr.typeName,
93 typeIfAttr: name,
94 })
95 } else {
96 const attrInfo: FunctionSignature = {
97 category: TypeCategory.Function,
98 shortDoc: attr.shortDoc,
99 arguments:
100 attr.parameters?.map((argInfo) => {
101 const arg: FunctionArgument = {
102 name: argInfo.name,
103 type: functionArgTypeMapping[argInfo.kind],

Callers 1

Calls 2

addModuleDefinitionMethod · 0.80
addTypeMethod · 0.80

Tested by

no test coverage detected