euporie.core.utils.import_submodules
- euporie.core.utils.import_submodules(root: ModuleType, names: tuple[str]) list[ModuleType]
Import all submodules with a specific name within a root module’s package hierarchy.
This function walks through all packages under the given root module and imports any submodules that match the specified name. It handles various module types including regular packages, single file modules, and frozen modules.
- Parameters:
root – The root module object to search within
names – The specific submodule name to search for
- Returns:
A list of imported module objects matching the specified name
Example
>>> root = import_module("django") >>> admin_modules = import_submodules(root, "admin") >>> print([m.__name__ for m in admin_modules]) ['django.contrib.admin', 'django.contrib.gis.admin']
Note
The function is cached using lru_cache to improve performance for repeated imports
For packages, it searches through __path__
For single file modules, it uses __file__
For frozen modules, it uses the module specification’s origin