blob: 1ac58abc8927b3cc73d179db3e9ebf8f280f2192 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
"""
Utility for loading all modules within a package.
"""
from __future__ import absolute_import
import importlib
import pkgutil
def load_all_modules(name, path):
"""
Dynamically loads all modules in the 'name' package.
This function is useful in combination with the registry.py module
so that any classes declared within the package are automatically
registered.
The following is the intended usage within the __init__.py file for
a package:
from utils import autoloader as _autoloader
_autoloader.load_all_modules(name=__name__, path=__path__)
"""
for (_, module, _) in pkgutil.walk_packages(path=path):
importlib.import_module("." + module, package=name)
|