aboutsummaryrefslogtreecommitdiffstats
path: root/deckit/modules/__init__.py
blob: 76fc9c51a99a7dc6eaf57663b18f536fb92e89a5 (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
"""Module discovery.

Every `deckit/modules/<name>.py` exporting `make(cfg) -> Module` is a module.
Discovery is lazy and file-based, so a new module is a new file: nothing here
lists the modules, and a not-yet-written one simply stays absent.
"""

import importlib
from pathlib import Path

from ..module import Registry


def build(cfg: dict) -> Registry:
    enabled = cfg.get("modules", {})
    modules = []
    for path in sorted(Path(__file__).parent.glob("*.py")):
        name = path.stem
        if name == "__init__" or not enabled.get(name, True):
            continue
        try:
            mod = importlib.import_module(f"{__name__}.{name}")
        except ImportError:
            continue
        modules.append(mod.make(cfg))
    return Registry(modules)