forked from violetljj/blind-assist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_research_tool.py
More file actions
53 lines (42 loc) · 2.02 KB
/
Copy pathrun_research_tool.py
File metadata and controls
53 lines (42 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Stable adapter for research tools whose implementations live below scripts/research/."""
from __future__ import annotations
import argparse
import os
import runpy
import sys
from pathlib import Path
SCRIPTS_DIR = Path(__file__).resolve().parent
REPO_ROOT = SCRIPTS_DIR.parent
DOMAINS = {
"egomotion-compensated-looming": SCRIPTS_DIR / "research" / "egomotion_compensated_looming",
"public-video": SCRIPTS_DIR / "research" / "public_video",
"candidate-event-mining": SCRIPTS_DIR / "research" / "candidate_event_mining",
"hftf": SCRIPTS_DIR / "research" / "hftf",
"hftf-d7-public-real": SCRIPTS_DIR / "research" / "hftf_d7_public_real",
"ustrf-crosscam-codex": SCRIPTS_DIR / "research" / "ustrf_crosscam_codex",
"ustrf-route-target-evidence-closure": SCRIPTS_DIR / "research" / "ustrf_route_target_evidence_closure",
"ustrf-sensor-replay": SCRIPTS_DIR / "research" / "ustrf_sensor_replay",
}
def main() -> int:
parser = argparse.ArgumentParser(
description="Run a research CLI through a stable repository entry point."
)
parser.add_argument("domain", choices=sorted(DOMAINS))
parser.add_argument("tool", help="Python filename inside the selected domain")
parser.add_argument("arguments", nargs=argparse.REMAINDER)
args = parser.parse_args()
tool_name = Path(args.tool)
if tool_name.name != args.tool or tool_name.suffix != ".py":
parser.error("tool must be one Python filename without directory components")
domain_dir = DOMAINS[args.domain].resolve()
target = (domain_dir / tool_name.name).resolve()
if target.parent != domain_dir or not target.is_file():
parser.error(f"unknown {args.domain} tool: {args.tool}")
# Keep historical sibling imports and stable root helpers behind this Adapter.
sys.path[:0] = [str(domain_dir), str(SCRIPTS_DIR), str(REPO_ROOT)]
sys.argv = [str(target), *args.arguments]
os.chdir(REPO_ROOT)
runpy.run_path(str(target), run_name="__main__")
return 0
if __name__ == "__main__":
raise SystemExit(main())