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)
| 276 | |
| 277 | |
| 278 | def 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 | |
| 306 | globalThis.python.load = load |
nothing calls this directly
no outgoing calls
no test coverage detected