Import Utils
reload(module)
Reload an existing module or import it if not already imported.
If the specified module is already present in the global namespace, it will be reloaded. Otherwise, the module will be imported.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module
|
str
|
The name of the module to reload or import. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in mbodied/utils/import_utils.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
smart_import(name, mode=None)
Import a module with optional lazy loading.
This function imports a module by name. If the module is already
present in the global namespace, it will return the existing module.
If the mode
is set to "lazy", the module will be loaded lazily,
meaning that the module will only be fully loaded when an attribute
or function within the module is accessed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the module to import. |
required |
mode
|
Literal['lazy'] | None
|
If "lazy", the module will be imported using a lazy loader. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
ModuleType |
ModuleType
|
The imported module. |
Raises:
Type | Description |
---|---|
NameError
|
If the module cannot be found or imported. |
Source code in mbodied/utils/import_utils.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|