generated from mathias/template-go-web
fix(loop): put project root on PYTHONPATH for train.py subprocess
train.py is copied into runs/<rq-id>/ by autoresearch_start.py, so when loop.py executes it, sys.path[0] is the run dir — which has no scripts/. train.py's frozen VaR-eval block does `from scripts.var_breach import ...`, which then fails with ModuleNotFoundError: No module named 'scripts' on every loop run (CI and the documented manual launch alike). Fix in the harness, not the frozen train.py/scripts boundary: prepend the project root (loop.py's own dir, where scripts/ lives) to the subprocess PYTHONPATH. Verified red→green locally: the import fails without it and resolves with it (scripts/ is an implicit namespace package, no __init__.py).
This commit is contained in:
@@ -84,6 +84,10 @@ def run_train() -> "tuple[float | None, float, str]":
|
||||
t0 = time.time()
|
||||
env = dict(os.environ)
|
||||
env["METRICS_OUT"] = str(METRICS_JSON.resolve())
|
||||
# train.py is copied into the run dir, so sys.path[0] is that run dir — which
|
||||
# has no scripts/. Put the project root (where loop.py + scripts/ live) on
|
||||
# PYTHONPATH so train.py's `from scripts.var_breach import ...` resolves.
|
||||
env["PYTHONPATH"] = str(Path(__file__).resolve().parent) + os.pathsep + env.get("PYTHONPATH", "")
|
||||
try:
|
||||
r = subprocess.run(
|
||||
[sys.executable, str(TRAIN_PY.resolve())],
|
||||
|
||||
Reference in New Issue
Block a user