|
1 | | -import importlib.util |
2 | | -import pkgutil |
3 | | -from inspect import getmembers |
4 | | -from inspect import isclass |
| 1 | +if __name__ == "__main__": # pragma: no cover |
| 2 | + import importlib.util |
| 3 | + import pkgutil |
| 4 | + from inspect import getmembers, isclass |
| 5 | + from ingest_classes.base_class import BaseClass |
5 | 6 |
|
6 | | -from ingest_classes.base_class import BaseClass |
| 7 | + class_dict = {} |
7 | 8 |
|
8 | | -class_dict = {} |
| 9 | + parent_package = __name__ |
9 | 10 |
|
10 | | -parent_package = __name__ |
| 11 | + for module_finder, module_name, is_pkg in pkgutil.walk_packages(__path__): |
| 12 | + if module_name == "base_class": |
| 13 | + continue |
11 | 14 |
|
12 | | -for module_finder, module_name, is_pkg in pkgutil.walk_packages(__path__): |
| 15 | + full_module_name = f"{parent_package}.{module_name}" |
13 | 16 |
|
14 | | - if module_name == "base_class": |
15 | | - continue |
| 17 | + spec = importlib.util.find_spec(full_module_name) |
| 18 | + if spec is not None and spec.loader is not None: |
| 19 | + _module = importlib.util.module_from_spec(spec) |
| 20 | + spec.loader.exec_module(_module) |
16 | 21 |
|
17 | | - full_module_name = f"{parent_package}.{module_name}" |
18 | | - |
19 | | - spec = importlib.util.find_spec(full_module_name) |
20 | | - if spec is not None and spec.loader is not None: |
21 | | - _module = importlib.util.module_from_spec(spec) |
22 | | - spec.loader.exec_module(_module) |
23 | | - |
24 | | - for _cname, _cls in getmembers(_module, isclass): |
25 | | - if issubclass(_cls, BaseClass) and _cls is not BaseClass: |
26 | | - class_dict[_cname] = _cls |
| 22 | + for _cname, _cls in getmembers(_module, isclass): |
| 23 | + if issubclass(_cls, BaseClass) and _cls is not BaseClass: |
| 24 | + class_dict[_cname] = _cls |
0 commit comments