Fix optional dependency handling for Redis and MinIO adapters.
Lazy-load adapters at package boundaries and fail fast with install hints when extras are missing. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
co-authored by
Cursor
parent
9e4b1e2c5e
commit
c6eed43d70
@@ -4,10 +4,33 @@ Adapters for various backend repositories (e.g., Redis, Minio).
|
||||
This module exposes concrete implementations for repository interfaces.
|
||||
"""
|
||||
|
||||
from .redis_adapter import RedisAdapter
|
||||
from .minio_adapter import MinioAdapter
|
||||
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__)
|
||||
|
||||
Reference in New Issue
Block a user