info-tech-canon/src/info_tech_canon/bench.py
tegwick b081d39da1
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 3s
Implement canon conformance and maintenance optimizations
Assistant: codex
Assistant-Model: gpt-6-astra
Assistant-Session: 01a06e82-3e08-7042-a79d-438ac6eed8db
2026-09-05 00:50:09 +02:00

69 lines
2.3 KiB
Python

from __future__ import annotations
import importlib.util
import sys
import types
from pathlib import Path
from types import ModuleType
from typing import Any
BENCH_PACKAGE = "_info_tech_canon_infospace_bench"
_spec = importlib.util.find_spec("infospace_bench")
if _spec is None or not _spec.submodule_search_locations:
raise RuntimeError("Install infospace-bench==0.1.0 before using the canon service")
# The upstream __init__ imports optional database/engine integrations. Resolve
# its installed location without executing that initializer; load only the
# reference-data modules needed here. No sibling checkout is assumed.
BENCH_SOURCE_ROOT = Path(next(iter(_spec.submodule_search_locations)))
def _ensure_package() -> ModuleType:
existing = sys.modules.get(BENCH_PACKAGE)
if existing is not None:
return existing
package = types.ModuleType(BENCH_PACKAGE)
package.__path__ = [str(BENCH_SOURCE_ROOT)] # type: ignore[attr-defined]
sys.modules[BENCH_PACKAGE] = package
return package
def _load_module(name: str) -> ModuleType:
_ensure_package()
module_name = f"{BENCH_PACKAGE}.{name}"
existing = sys.modules.get(module_name)
if existing is not None:
return existing
path = BENCH_SOURCE_ROOT / f"{name}.py"
if not path.is_file():
raise RuntimeError(f"Missing infospace-bench module: {path}")
spec = importlib.util.spec_from_file_location(module_name, path)
if spec is None or spec.loader is None:
raise RuntimeError(f"Unable to load infospace-bench module: {path}")
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)
return module
errors = _load_module("errors")
models = _load_module("models")
lifecycle = _load_module("lifecycle")
checks = _load_module("checks")
inspection = _load_module("inspection")
Infospace = models.Infospace
KnowledgeArtifact = models.KnowledgeArtifact
load_infospace = lifecycle.load_infospace
run_collection_checks = checks.run_collection_checks
relationship_summary = inspection.relationship_summary
export_mermaid = inspection.export_mermaid
__all__ = [
"Infospace",
"KnowledgeArtifact",
"export_mermaid",
"load_infospace",
"relationship_summary",
"run_collection_checks",
]