s365b.modules.registry ====================== .. py:module:: s365b.modules.registry .. autoapi-nested-parse:: Finding, loading and validating modules. Modules register under the ``s365b.modules`` entry point group, e.g. in a module package's ``pyproject.toml``:: [project.entry-points."s365b.modules"] exchange = "s365b.modules.exchange:ExchangeModule" Two layers decide whether a module runs: * **Allowed** (this file): the ``S365B_MODULES`` allow-list. A module not on the list is never imported. * **Enabled** (database, toggled in the UI): checked by the core before it schedules work. A module that is allowed but disabled is still loaded so its existing backups can be browsed and restored. Attributes ---------- .. autoapisummary:: s365b.modules.registry.ENTRY_POINT_GROUP s365b.modules.registry.log Exceptions ---------- .. autoapisummary:: s365b.modules.registry.RegistryError Classes ------- .. autoapisummary:: s365b.modules.registry.ModuleInfo s365b.modules.registry.ModuleRegistry Functions --------- .. autoapisummary:: s365b.modules.registry.validate_module_class Module Contents --------------- .. py:data:: ENTRY_POINT_GROUP :value: 's365b.modules' .. py:data:: log .. py:exception:: RegistryError Bases: :py:obj:`Exception` Raised when a module is invalid or cannot be found. .. py:class:: ModuleInfo Summary of a module for the API and UI. :ivar id: Module ID. :ivar display_name: Name shown in the UI. :ivar description: One-line description. :ivar version: Module version. .. py:attribute:: id :type: str .. py:attribute:: display_name :type: str .. py:attribute:: description :type: str .. py:attribute:: version :type: str .. py:function:: validate_module_class(cls: type[s365b.modules.sdk.BackupModule], expected_id: str | None = None) -> None Check that a class meets the module contract's static rules. :param cls: The module class. :param expected_id: Entry point name it was registered under, if any. :raises RegistryError: Describing the first problem found. .. py:class:: ModuleRegistry(modules: dict[str, type[s365b.modules.sdk.BackupModule]]) The set of modules this process may use. :param modules: Module classes, keyed by ID. .. py:method:: from_entry_points(allowed: collections.abc.Iterable[str] = ()) -> ModuleRegistry :classmethod: Load modules from installed entry points. Invalid modules are logged and skipped, so one broken third-party module cannot stop the whole application. :param allowed: Allow-list of module IDs; empty allows all installed. :returns: The registry. .. py:method:: from_classes(classes: collections.abc.Iterable[type[s365b.modules.sdk.BackupModule]]) -> ModuleRegistry :classmethod: Build a registry from classes directly (tests, embedding). :param classes: Module classes. :returns: The registry. :raises RegistryError: If a class is invalid or IDs collide. .. py:method:: ids() -> list[str] Return the IDs of all loaded modules, sorted. :returns: Module IDs. .. py:method:: get(module_id: str) -> s365b.modules.sdk.BackupModule Return the (shared) instance of a module. :param module_id: Module ID. :returns: The module instance. :raises RegistryError: If the module is not loaded. .. py:method:: info(module_id: str) -> ModuleInfo Return a module's summary. :param module_id: Module ID. :returns: The summary. .. py:method:: parse_config(module_id: str, raw: dict[str, object] | None) -> pydantic.BaseModel Validate stored settings against a module's config model. :param module_id: Module ID. :param raw: Stored settings; ``None`` means defaults. :returns: The config model instance. .. py:method:: required_permissions(enabled: dict[str, pydantic.BaseModel], *, restore: bool) -> dict[str, set[str]] Return the Graph permissions needed by the enabled modules. :param enabled: Enabled module IDs mapped to their config. :param restore: Restore-app permissions instead of backup-app ones. :returns: Permission name mapped to the IDs of the modules that need it, so the UI can explain why each permission is requested.