__init__.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. """Remote config backend: ``HERMES_CONFIG_BACKEND=remote`` serves each profile's config from the
  2. config plane (config-config) instead of ``config.yaml``. See ``backend.py``."""
  3. from __future__ import annotations
  4. import threading
  5. from typing import Optional
  6. from .backend import RemoteBackend
  7. _BACKEND: Optional[RemoteBackend] = None
  8. _LOCK = threading.Lock()
  9. def get_remote_backend() -> RemoteBackend:
  10. """The process-wide instance (one poller and one in-memory layer per profile home)."""
  11. global _BACKEND
  12. if _BACKEND is None:
  13. with _LOCK:
  14. if _BACKEND is None:
  15. _BACKEND = RemoteBackend()
  16. return _BACKEND
  17. def get_backend() -> RemoteBackend:
  18. """The entry point ``hermes_cli.config_backend`` resolves ``HERMES_CONFIG_BACKEND=remote`` to."""
  19. return get_remote_backend()
  20. def _reset_for_tests() -> None:
  21. global _BACKEND
  22. with _LOCK:
  23. if _BACKEND is not None:
  24. _BACKEND._stop.set()
  25. _BACKEND = None
  26. __all__ = ["RemoteBackend", "get_backend", "get_remote_backend"]