MonkeyBusiness/modules/__init__.py

18 lines
472 B
Python
Raw Normal View History

2022-08-26 10:39:11 +00:00
from importlib import util
from os import path
from glob import glob
routers = []
2022-11-15 14:03:37 +00:00
for module_path in [
f
for f in glob(path.join(path.dirname(__file__), "**/*.py"), recursive=True)
if path.basename(f) != "__init__.py"
]:
spec = util.spec_from_file_location("", module_path)
2022-08-26 10:39:11 +00:00
module = util.module_from_spec(spec)
spec.loader.exec_module(module)
2022-11-15 14:03:37 +00:00
router = getattr(module, "router", None)
2022-08-26 10:39:11 +00:00
if router is not None:
routers.append(router)