Skip to main content

review.runs.candidate_file

review.runs.candidate_file(run, n)

The kept module of attempt n (<stem>-<n>.py), or None.

Parameters

Name Type Description Default
run Run The run. required
n int The attempt. required

Returns

Name Type Description
Path | None Path | None: The file, if exactly one *-<n>.py exists in the directory.

Examples

from pathlib import Path
from tempfile import TemporaryDirectory

from babregen.review.runs import read_run

record = (
    'unit = "calc"\nprotocol = "score"\nstatus = "completed"\n'
    '[base]\ncommit = "' + "a" * 40 + '"\n[final]\nattempt = 1\n'
    "[[attempt]]\nn = 1\nwrote_module = true\n"
)
from babregen.review.runs import candidate_file

with TemporaryDirectory() as tmp:
    (Path(tmp) / "run.toml").write_text(record)
    (Path(tmp) / "calc-1.py").write_text("X = 1\n")
    print(candidate_file(read_run(Path(tmp)), 1).name)
calc-1.py