Keep lazy loading in adapters/__init__.py as the single place to register new adapters. Co-authored-by: Cursor <[email protected]>
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
"""
|
|
Adapters for various backend repositories (e.g., Redis, Minio).
|
|
|
|
This module exposes concrete implementations for repository interfaces.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
from typing import TYPE_CHECKING
|
|
|
|
# Adapters are imported only for static type checkers; runtime loading is deferred below.
|
|
if TYPE_CHECKING:
|
|
from .minio_adapter import MinioAdapter
|
|
from .redis_adapter import RedisAdapter
|
|
|
|
# Map public adapter names to their defining module and class.
|
|
# Each adapter module fails fast with an install hint if its extra is missing.
|
|
# When adding a new adapter, update this dict and __all__ only.
|
|
_LAZY_EXPORTS = {
|
|
"RedisAdapter": (".redis_adapter", "RedisAdapter"),
|
|
"MinioAdapter": (".minio_adapter", "MinioAdapter"),
|
|
}
|
|
|
|
__all__ = [
|
|
"RedisAdapter",
|
|
"MinioAdapter",
|
|
]
|
|
|
|
|
|
def __getattr__(name: str) -> object:
|
|
"""Load an adapter on first access so the base package installs without backend clients."""
|
|
if name in _LAZY_EXPORTS:
|
|
module_path, attr = _LAZY_EXPORTS[name]
|
|
module = importlib.import_module(module_path, __package__)
|
|
return getattr(module, attr)
|
|
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
|
|
|
|
def __dir__() -> list[str]:
|
|
"""Expose lazy adapter names in tab completion and dir()."""
|
|
return sorted(__all__)
|