diff --git a/uni-wizard/v2/router.py b/uni-wizard/v2/router.py index 1fd4ff6..bc8bbdf 100644 --- a/uni-wizard/v2/router.py +++ b/uni-wizard/v2/router.py @@ -17,8 +17,24 @@ from typing import Dict, Any, Optional, List from pathlib import Path from dataclasses import dataclass from enum import Enum +import importlib.util -from harness import UniWizardHarness, House, ExecutionResult + +def _load_local(module_name: str, filename: str): + """Import a module from an explicit file path, bypassing sys.path resolution.""" + spec = importlib.util.spec_from_file_location( + module_name, + str(Path(__file__).parent / filename), + ) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod + + +_harness = _load_local("v2_harness", "harness.py") +UniWizardHarness = _harness.UniWizardHarness +House = _harness.House +ExecutionResult = _harness.ExecutionResult class TaskType(Enum): diff --git a/uni-wizard/v2/task_router_daemon.py b/uni-wizard/v2/task_router_daemon.py index e625641..8c5849d 100644 --- a/uni-wizard/v2/task_router_daemon.py +++ b/uni-wizard/v2/task_router_daemon.py @@ -8,13 +8,30 @@ import time import sys import argparse import os +import importlib.util from pathlib import Path from datetime import datetime from typing import Dict, List, Optional -sys.path.insert(0, str(Path(__file__).parent)) +def _load_local(module_name: str, filename: str): + """Import a module from an explicit file path, bypassing sys.path resolution. + + Prevents namespace collisions when multiple directories contain modules + with the same name (e.g. uni-wizard/harness.py vs uni-wizard/v2/harness.py). + """ + spec = importlib.util.spec_from_file_location( + module_name, + str(Path(__file__).parent / filename), + ) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod + +_harness = _load_local("v2_harness", "harness.py") +UniWizardHarness = _harness.UniWizardHarness +House = _harness.House +ExecutionResult = _harness.ExecutionResult -from harness import UniWizardHarness, House, ExecutionResult from router import HouseRouter, TaskType from author_whitelist import AuthorWhitelist