MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / load

Function load

python/pythonmonkey/require.py:278–303  ·  view source on GitHub ↗

Loads a python module using the importlib machinery sourcefileloader, prefills it with an exports object and returns the module. If the module is already loaded, returns it. Args: filename (str): The filename of the python module to load. Returns: : The loaded python module

(filename: str)

Source from the content-addressed store, hash-verified

276
277
278def load(filename: str) -> Dict:
279 """
280 Loads a python module using the importlib machinery sourcefileloader, prefills it with an exports object and returns
281 the module.
282 If the module is already loaded, returns it.
283
284 Args:
285 filename (str): The filename of the python module to load.
286
287 Returns:
288 : The loaded python module
289 """
290
291 filename = os.path.normpath(filename)
292 name = os.path.basename(filename)
293 if name not in sys.modules:
294 sourceFileLoader = machinery.SourceFileLoader(name, filename)
295 spec: machinery.ModuleSpec = importlib.util.spec_from_loader(
296 sourceFileLoader.name, sourceFileLoader) # type: ignore
297 module = importlib.util.module_from_spec(spec)
298 sys.modules[name] = module
299 module.exports = {} # type: ignore
300 spec.loader.exec_module(module) # type: ignore
301 else:
302 module = sys.modules[name]
303 return module.exports
304
305
306globalThis.python.load = load

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected