blob: 09c66056f03f578fe86a55481462df3b7dde1e12 (
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# deck-it - module discovery
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
#
# 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/<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)
|