Loads a Python module to make variables, objects and functions available globally. The idea is to load the module using importlib, then copy the symbols to the global symbol table.
(module, globals_dict=None, symb_list=None)
| 298 | |
| 299 | |
| 300 | def _load(module, globals_dict=None, symb_list=None): |
| 301 | # type: (str, Optional[Dict[str, Any]], Optional[List[str]]) -> None |
| 302 | """Loads a Python module to make variables, objects and functions |
| 303 | available globally. |
| 304 | |
| 305 | The idea is to load the module using importlib, then copy the |
| 306 | symbols to the global symbol table. |
| 307 | |
| 308 | """ |
| 309 | if globals_dict is None: |
| 310 | globals_dict = builtins.__dict__ |
| 311 | try: |
| 312 | mod = importlib.import_module(module) |
| 313 | if '__all__' in mod.__dict__: |
| 314 | # import listed symbols |
| 315 | for name in mod.__dict__['__all__']: |
| 316 | if symb_list is not None: |
| 317 | symb_list.append(name) |
| 318 | globals_dict[name] = mod.__dict__[name] |
| 319 | else: |
| 320 | # only import non-private symbols |
| 321 | for name, sym in mod.__dict__.items(): |
| 322 | if _validate_local(name): |
| 323 | if symb_list is not None: |
| 324 | symb_list.append(name) |
| 325 | globals_dict[name] = sym |
| 326 | except Exception: |
| 327 | log_interactive.error("Loading module %s", module, exc_info=True) |
| 328 | |
| 329 | |
| 330 | def load_module(name, globals_dict=None, symb_list=None): |
no test coverage detected