File size: 2,264 Bytes
2c199f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import importlib
import sys
from pathlib import Path
import yaml

ROOT = Path(__file__).parent.parent
OPENENV = ROOT / "openenv.yaml"

# Ensure repo root is on sys.path so imports like `server.graders` work when run from scripts/
sys.path.insert(0, str(ROOT))

if not OPENENV.exists():
    print(f"openenv.yaml not found at {OPENENV}")
    sys.exit(2)

with OPENENV.open("r", encoding="utf-8") as f:
    cfg = yaml.safe_load(f)

tasks = cfg.get("tasks", [])
if not tasks:
    print("No tasks found in openenv.yaml")
    sys.exit(2)

print(f"Found {len(tasks)} tasks. Validating grader importability...")

failed = []
for t in tasks:
    tid = t.get("id") or t.get("name") or "<unknown>"
    grader_spec = t.get("grader")
    grader_dot = t.get("grader_import")
    print(f"\n- Task: {tid}")

    tried = []
    ok = False

    for spec in (grader_spec, grader_dot):
        if not spec:
            continue
        tried.append(spec)
        # Support both "module:callable" and "module.callable"
        module = None
        attr = None
        if ":" in spec:
            module, attr = spec.split(":", 1)
        elif "." in spec:
            parts = spec.rsplit(".", 1)
            if len(parts) == 2:
                module, attr = parts
            else:
                module = spec
                attr = None
        else:
            module = spec
            attr = None

        try:
            m = importlib.import_module(module)
            if attr:
                if hasattr(m, attr):
                    print(f"  OK: imported {module} and found attribute '{attr}'")
                    ok = True
                    break
                else:
                    print(f"  ERROR: imported {module} but attribute '{attr}' not found")
            else:
                print(f"  OK: imported module {module}")
                ok = True
                break
        except Exception as e:
            print(f"  ERROR importing {module}: {e}")

    if not ok:
        failed.append((tid, tried))

print("\nSummary:")
if not failed:
    print("All graders importable ✅")
    sys.exit(0)
else:
    print(f"{len(failed)} task(s) failed to import graders:")
    for tid, tried in failed:
        print(f" - {tid}: tried {tried}")
    sys.exit(1)