| 12345678910111213141516171819202122 |
- """Load the packaged IM implementation from legacy standalone scripts."""
- from __future__ import annotations
- import importlib
- import sys
- from pathlib import Path
- from types import ModuleType
- def load(module_name: str) -> ModuleType:
- try:
- return importlib.import_module(module_name)
- except ModuleNotFoundError as exc:
- if exc.name != "agent":
- raise
- project_root = str(Path(__file__).resolve().parent.parent)
- sys.path.insert(0, project_root)
- try:
- return importlib.import_module(module_name)
- finally:
- sys.path.remove(project_root)
|