mirror-checker/projects/__init__.py

22 lines
699 B
Python
Raw Normal View History

2021-10-03 18:15:36 -04:00
"""
This file automatically imports all Classes in this directory
"""
2021-10-03 16:43:06 -04:00
from inspect import isclass
from pkgutil import iter_modules
from pathlib import Path
from importlib import import_module
# iterate through the modules in the current package
package_dir = Path(__file__).resolve().parent
2021-12-28 21:28:35 -05:00
for (_, module_name, _) in iter_modules([str(package_dir)]):
2021-10-03 16:43:06 -04:00
# import the module and iterate through its attributes
module = import_module(f"{__name__}.{module_name}")
for attribute_name in dir(module):
attribute = getattr(module, attribute_name)
if isclass(attribute):
# Add the class to this package's variables
globals()[attribute_name] = attribute