Amin
Deploy: HermesFace finalized project to HF Space
2e658e7
Raw
History Blame Contribute Delete
1.59 kB
"""Assemble the same import roots used by the deployed Hermes overlay.
The Space copies this repository's ``trading`` and ``tools`` modules into a
full Hermes checkout at ``/opt/hermes``. Local tests must point
``HERMES_SOURCE_DIR`` at an actual Hermes checkout so imports such as
``tools.registry`` come from their real owner rather than from a stub.
"""
from __future__ import annotations
import os
import sys
from pathlib import Path
OVERLAY_ROOT = Path(__file__).resolve().parents[1]
PROJECT_ROOT = OVERLAY_ROOT.parent
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
HERMES_SOURCE = Path(os.environ.get("HERMES_SOURCE_DIR", "/opt/hermes"))
if HERMES_SOURCE.is_dir():
sys.path.insert(0, str(HERMES_SOURCE))
sys.path.insert(1, str(OVERLAY_ROOT))
import tools
overlay_tools = str(OVERLAY_ROOT / "tools")
if overlay_tools not in tools.__path__:
tools.__path__.insert(0, overlay_tools)
else:
# The deploy overlays these files into a full Hermes checkout. For a
# standalone source-package test run, provide only the tiny registry surface
# needed at import time; production never sees this test-only module.
import types
sys.path.insert(0, str(OVERLAY_ROOT))
class _TestRegistry:
def __init__(self):
self.registrations = []
def register(self, **kwargs):
self.registrations.append(kwargs)
registry_module = types.ModuleType("tools.registry")
registry_module.registry = _TestRegistry()
sys.modules.setdefault("tools.registry", registry_module)