Lazy-load adapters at package boundaries and fail fast with install hints when extras are missing. Co-authored-by: Cursor <[email protected]>
37 lines
881 B
Python
37 lines
881 B
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
|
|
|
|
if TYPE_CHECKING:
|
|
from .minio_adapter import MinioAdapter
|
|
from .redis_adapter import RedisAdapter
|
|
|
|
_LAZY_EXPORTS = {
|
|
"RedisAdapter": (".redis_adapter", "RedisAdapter"),
|
|
"MinioAdapter": (".minio_adapter", "MinioAdapter"),
|
|
}
|
|
|
|
__all__ = [
|
|
"RedisAdapter",
|
|
"MinioAdapter",
|
|
]
|
|
|
|
|
|
def __getattr__(name: str) -> object:
|
|
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]:
|
|
return sorted(__all__)
|