28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
"""Execute anonymous coding answers in the existing disposable offline sandbox."""
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
base = Path(__file__).resolve().parent
|
|
stage = Path(sys.argv[1])
|
|
cases = {c['id']: c for c in json.loads((base / 'cases.json').read_text())}
|
|
answers = json.loads((stage / 'blind-answers.json').read_text())
|
|
image = subprocess.check_output(['docker', 'inspect', '-f', '{{.Image}}', 'athena-deck-dev'], text=True).strip()
|
|
directory = stage / 'blind-code-checks'
|
|
directory.mkdir(exist_ok=False)
|
|
results = {}
|
|
for answer in answers:
|
|
case = cases[answer['case_id']]
|
|
if 'function' not in case:
|
|
continue
|
|
identity = answer['answer_id']
|
|
cpath, apath = directory / (identity + '-case.json'), directory / (identity + '-answer.json')
|
|
cpath.write_text(json.dumps(case))
|
|
apath.write_text(json.dumps(answer))
|
|
checked = subprocess.run([sys.executable, str(base / 'check_code.py'), str(cpath), str(apath), image],
|
|
text=True, capture_output=True, timeout=40, check=True)
|
|
results[identity] = json.loads(checked.stdout)
|
|
print(identity, json.dumps(results[identity]), flush=True)
|
|
(stage / 'blind-code-results.json').write_text(json.dumps(results, indent=2) + '\n')
|