File size: 1,394 Bytes
24aaa76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""R5 REF: checks gpu_tasks.json against LINEDET's driver code: every task must survive normalize_task (name, cmd), every `after` must name a task of the file,
every {VENV}/{REMAIN} placeholder is replaced the way the driver does it, and every file path in cmd (scripts, venv python) must exist.
Usage: python ref_check_tasks.py <gpu_tasks.json>"""
import json
import os
import sys

sys.path.insert(0, "/path/to/TURKIC_OCR_CODE/src")
from linedet import driver  # LINEDET's driver module (own project code)

spec = json.load(open(sys.argv[1]))
names = {t["name"] for t in spec["tasks"]}
bad = 0
for t in spec["tasks"]:
    nt = driver.normalize_task(t)
    if nt is None:
        print("NOT NORMALISABLE", t.get("name"))
        bad += 1
        continue
    for a in nt["after"]:
        if a not in names:
            print("UNKNOWN AFTER", nt["name"], a)
            bad += 1
    cmd = [c.replace("{PY}", driver.PY).replace("{REMAIN}", "1234") for c in nt["cmd"]]
    for c in cmd:
        if c.endswith(".py") or c.endswith("/python") or c.startswith("/shared/") and "/" in c and not c.startswith("--"):
            if not os.path.exists(c):
                print("MISSING FILE", nt["name"], c)
                bad += 1
    if any("{" in c for c in cmd):
        print("UNREPLACED PLACEHOLDER", nt["name"], cmd)
        bad += 1
print(len(spec["tasks"]), "tasks checked,", bad, "problems")