Files
id_configurator/id_configurator/modules/base.py
T
2026-08-28 16:52:07 +02:00

37 lines
989 B
Python

"""Base class and registry for configuration modules.
Each module inspects the configuration and the source filesystem (via the
`Context`) to decide whether it applies, then writes the resulting files to
the destination directory.
"""
from __future__ import annotations
from abc import ABC, abstractmethod
from id_configurator.context import Context
_REGISTRY: list[type[Module]] = []
class Module(ABC):
name: str
@abstractmethod
def is_relevant(self, context: Context) -> bool:
"""Return True if this module has something to do for the given configuration."""
@abstractmethod
def apply(self, context: Context) -> None:
"""Write the module's changes to the destination directory."""
def register(module_cls: type[Module]) -> type[Module]:
"""Class decorator registering a module so it is picked up by the CLI."""
_REGISTRY.append(module_cls)
return module_cls
def all_modules() -> list[type[Module]]:
return list(_REGISTRY)