|
3 | 3 | # Re-exports the full chronomemory v0.1.1 public surface under the |
4 | 4 | # specsmith.esdb namespace so internal modules can use a single import |
5 | 5 | # path and never import chronomemory directly in more than one place. |
| 6 | +# |
| 7 | +# chronomemory is a git-URL dependency stripped from the PyPI wheel. |
| 8 | +# If it is not installed, all symbols are stubbed with a class that |
| 9 | +# raises a clear ImportError with install instructions rather than |
| 10 | +# crashing silently at module import time. |
| 11 | +# |
| 12 | +# Install the missing dep: |
| 13 | +# pipx inject specsmith "chronomemory @ git+https://github.com/layer1labs/chronomemory.git@v0.1.1" |
6 | 14 |
|
7 | | -# Re-export query and metrics as module references so callers can do: |
8 | | -# from specsmith.esdb import query, metrics |
9 | | -from chronomemory import ( |
10 | | - RUST_BACKEND, |
11 | | - # Core store |
12 | | - ChronoRecord, |
13 | | - ChronoStore, |
14 | | - # Phase 2: context pack compiler |
15 | | - ContextPack, |
16 | | - ContextPackCompiler, |
17 | | - ContextPackEntry, |
18 | | - DependencyEdge, |
19 | | - # Phase 2: dependency graph |
20 | | - DepGraph, |
21 | | - # Bridge (backward-compat with .specsmith/*.json) |
22 | | - EsdbBridge, |
23 | | - EsdbRecord, |
24 | | - EsdbStatus, |
25 | | - # Phase 2: epistemic rollback |
26 | | - RollbackReport, |
27 | | - # Phase 3: optional Rust acceleration (None / False when not compiled) |
28 | | - RustChronoStore, |
29 | | - RustRecord, |
30 | | - WalEvent, |
31 | | - invalidate, |
32 | | - metrics, # noqa: F401 — module re-export |
33 | | - open_store, |
34 | | - query, # noqa: F401 — module re-export |
| 15 | +_INSTALL_HINT = ( |
| 16 | + "chronomemory is not installed.\n" |
| 17 | + "Run: pipx inject specsmith " |
| 18 | + '"chronomemory @ git+https://github.com/layer1labs/chronomemory.git@v0.1.1"' |
35 | 19 | ) |
36 | 20 |
|
| 21 | +try: |
| 22 | + # Re-export query and metrics as module references so callers can do: |
| 23 | + # from specsmith.esdb import query, metrics |
| 24 | + from chronomemory import ( |
| 25 | + RUST_BACKEND, |
| 26 | + # Core store |
| 27 | + ChronoRecord, |
| 28 | + ChronoStore, |
| 29 | + # Phase 2: context pack compiler |
| 30 | + ContextPack, |
| 31 | + ContextPackCompiler, |
| 32 | + ContextPackEntry, |
| 33 | + DependencyEdge, |
| 34 | + # Phase 2: dependency graph |
| 35 | + DepGraph, |
| 36 | + # Bridge (backward-compat with .specsmith/*.json) |
| 37 | + EsdbBridge, |
| 38 | + EsdbRecord, |
| 39 | + EsdbStatus, |
| 40 | + # Phase 2: epistemic rollback |
| 41 | + RollbackReport, |
| 42 | + # Phase 3: optional Rust acceleration (None / False when not compiled) |
| 43 | + RustChronoStore, |
| 44 | + RustRecord, |
| 45 | + WalEvent, |
| 46 | + invalidate, |
| 47 | + metrics, # noqa: F401 — module re-export |
| 48 | + open_store, |
| 49 | + query, # noqa: F401 — module re-export |
| 50 | + ) |
| 51 | + |
| 52 | + CHRONO_AVAILABLE: bool = True |
| 53 | + |
| 54 | +except ImportError: |
| 55 | + CHRONO_AVAILABLE = False |
| 56 | + |
| 57 | + class _Stub: # type: ignore[no-redef] |
| 58 | + """Placeholder that raises a clear error on instantiation or call.""" |
| 59 | + |
| 60 | + def __init__(self, *_: object, **__: object) -> None: |
| 61 | + raise ImportError(_INSTALL_HINT) |
| 62 | + |
| 63 | + def __call__(self, *_: object, **__: object) -> "_Stub": |
| 64 | + raise ImportError(_INSTALL_HINT) |
| 65 | + |
| 66 | + def __class_getitem__(cls, _: object) -> "type[_Stub]": |
| 67 | + return cls |
| 68 | + |
| 69 | + # Stub every exported name so `from specsmith.esdb import X` doesn't fail. |
| 70 | + ChronoRecord = ChronoStore = EsdbBridge = EsdbRecord = EsdbStatus = _Stub # type: ignore[misc] |
| 71 | + ContextPack = ContextPackCompiler = ContextPackEntry = _Stub # type: ignore[misc] |
| 72 | + DepGraph = DependencyEdge = RollbackReport = _Stub # type: ignore[misc] |
| 73 | + RustChronoStore = RustRecord = WalEvent = invalidate = open_store = _Stub # type: ignore[misc] |
| 74 | + RUST_BACKEND: bool = False # type: ignore[misc] |
| 75 | + |
| 76 | + class _StubModule: |
| 77 | + """Stub module reference so 'from specsmith.esdb import query, metrics' works.""" |
| 78 | + |
| 79 | + def __getattr__(self, name: str) -> "_Stub": |
| 80 | + raise ImportError(_INSTALL_HINT) |
| 81 | + |
| 82 | + query = _StubModule() # type: ignore[assignment] |
| 83 | + metrics = _StubModule() # type: ignore[assignment] |
| 84 | + |
37 | 85 | __all__ = [ |
38 | 86 | # Core |
39 | 87 | "ChronoStore", |
|
0 commit comments