Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /dislovelhl_enhanced-agent-bus /_compat /utilities /dependency_registry.py
| """Shim for src.core.shared.utilities.dependency_registry.""" | |
| from __future__ import annotations | |
| from typing import TYPE_CHECKING, Any, ClassVar | |
| if TYPE_CHECKING: | |
| from src.core.shared.utilities.dependency_registry import DependencyRegistry, FeatureFlag | |
| else: | |
| try: | |
| from src.core.shared.utilities.dependency_registry import * # noqa: F403 | |
| except ImportError: | |
| from enum import Enum, auto | |
| class FeatureFlag(Enum): | |
| METRICS = auto() | |
| OTEL = auto() | |
| AUDIT = auto() | |
| REDIS = auto() | |
| KAFKA = auto() | |
| OPA = auto() | |
| MACI = auto() | |
| DELIBERATION = auto() | |
| CIRCUIT_BREAKER = auto() | |
| CRYPTO = auto() | |
| PQC = auto() | |
| CACHING = auto() | |
| PERSISTENCE = auto() | |
| SWARM = auto() | |
| LANGGRAPH = auto() | |
| CONTEXT_MEMORY = auto() | |
| RUST = auto() | |
| METERING = auto() | |
| LLM = auto() | |
| IMPACT_SCORER = auto() | |
| class DependencyRegistry: | |
| """Standalone stub for the centralized dependency registry.""" | |
| _dependencies: ClassVar[dict[str, Any]] = {} | |
| _feature_status: ClassVar[dict[FeatureFlag, bool]] = {} | |
| _initialized: bool = False | |
| def register( | |
| cls, | |
| name: str, | |
| module_path: str = "", | |
| import_name: str = "", | |
| feature_flag: FeatureFlag | None = None, | |
| fallback_paths: list[str] | None = None, | |
| factory: Any = None, | |
| singleton: bool = False, | |
| ) -> None: | |
| cls._dependencies[name] = { | |
| "name": name, | |
| "module_path": module_path, | |
| "import_name": import_name, | |
| "feature_flag": feature_flag, | |
| "factory": factory, | |
| "singleton": singleton, | |
| } | |
| def get(cls, name: str, default: Any = None, create: bool = True) -> Any: | |
| dep = cls._dependencies.get(name) | |
| if dep and create and dep.get("factory"): | |
| return dep["factory"]() | |
| return default | |
| def resolve(cls, name: str) -> Any: | |
| return cls.get(name) | |
| def is_available(cls, feature: FeatureFlag) -> bool: | |
| return cls._feature_status.get(feature, False) | |
| def set_available(cls, feature: FeatureFlag, available: bool = True) -> None: | |
| cls._feature_status[feature] = available | |
| def has(cls, name: str) -> bool: | |
| return name in cls._dependencies | |
| def clear(cls) -> None: | |
| cls._dependencies.clear() | |
| cls._feature_status.clear() | |
| cls._initialized = False | |
| def all(cls) -> dict[str, Any]: | |
| return dict(cls._dependencies) | |
| def initialize_defaults(cls) -> None: | |
| """No-op in standalone mode — monorepo registers real defaults.""" | |
| cls._initialized = True | |
| def get_status_report(cls) -> dict[str, Any]: | |
| return { | |
| "initialized": cls._initialized, | |
| "dependencies": len(cls._dependencies), | |
| "features": {f.name: v for f, v in cls._feature_status.items()}, | |
| } | |
| _registry: DependencyRegistry | None = None | |
| def get_dependency_registry() -> DependencyRegistry: | |
| """Return a process-local dependency registry singleton. | |
| The shared source module exposes the ``DependencyRegistry`` class but not a | |
| convenience accessor. This compatibility shim preserves the legacy | |
| ``enhanced_agent_bus._compat.utilities`` API expected by package imports. | |
| """ | |
| global _registry # noqa: PLW0603 | |
| if _registry is None: | |
| _registry = DependencyRegistry() | |
| return _registry | |
| __all__ = ["DependencyRegistry", "FeatureFlag", "get_dependency_registry"] | |
Xet Storage Details
- Size:
- 4.32 kB
- Xet hash:
- 5794084d193e1a0460469129e1ab466893e4cd7aebb3bc40fe2fd45b32b13eee
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.