# deck-it - module discovery # Copyright (C) 2026 Danilo M. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """Module discovery. Every `deckit/modules/.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)