_framework_import.py 623 B

12345678910111213141516171819202122
  1. """Load the packaged IM implementation from legacy standalone scripts."""
  2. from __future__ import annotations
  3. import importlib
  4. import sys
  5. from pathlib import Path
  6. from types import ModuleType
  7. def load(module_name: str) -> ModuleType:
  8. try:
  9. return importlib.import_module(module_name)
  10. except ModuleNotFoundError as exc:
  11. if exc.name != "agent":
  12. raise
  13. project_root = str(Path(__file__).resolve().parent.parent)
  14. sys.path.insert(0, project_root)
  15. try:
  16. return importlib.import_module(module_name)
  17. finally:
  18. sys.path.remove(project_root)