judge.score(spec, unit, candidate, * , base, python, timeout, out)
Judge a candidate module for unit against a base commit (babregen score).
The unit as recorded at base (its evaluations, unit tests and consumers) is judged: the candidate replaces the module in a scratch worktree of base, the evaluations run, then the unit tests and the dependents, each in a fresh worktree. run.toml and the outputs of every step go into out. The result is the same for the same candidate, base commit, Python and pytest.
Parameters
spec
RegenSpec
The loaded spec; its root is the repository.
required
unit
Unit
The unit.
required
candidate
Path
The module to judge.
required
base
str
A revision of the repository, for example "HEAD".
required
python
Path | None
Interpreter that runs pytest, or None for resolve_python.
required
timeout
float
Seconds each pytest run and each dependent may take; positive and finite.
required
out
Path | None
Run directory, or None for a new temporary directory.
required
Returns
int
int
0 if accept accepts the candidate, 1 if not.
Raises
ConfigurationError
If timeout is not positive and finite, candidate is not a file or base is not a commit.
ExternalToolError
If git is not installed.
SpecError
If unit does not exist at base.
Examples
import subprocess
import sys
from pathlib import Path
from tempfile import TemporaryDirectory
from babregen import load_spec, make_sample_repo, resolve_unit
from babregen.judge import score
def git(root, * args):
subprocess.run(
["git" , "-c" , "user.name=t" , "-c" , "user.email=t@example.org" , * args],
cwd= root, check= True , capture_output= True ,
)
with TemporaryDirectory() as tmp:
root = make_sample_repo(Path(tmp) / "demo" )
git(root, "init" , "-q" )
git(root, "add" , "." )
git(root, "commit" , "-q" , "-m" , "init" )
spec = load_spec(root)
unit = resolve_unit(spec, "core.calc" )
code = score(
spec, unit, root / unit.path, base= "HEAD" , python= Path(sys.executable),
timeout= 60 , out= Path(tmp) / "run" ,
)
print (code)
unit = "core.calc"
protocol = "score"
babregen_version = "0.0.1"
started = "2026-11-29T17:11:14Z"
finished = "2026-11-29T17:11:14Z"
status = "completed"
accepted = true
rule = "accept/1"
[base]
commit = "a8a8801c79301715636b2ae2781cfdf5459f2f2e"
[tool]
python = "3.14.2"
pytest = "9.2.0"
packages_sha256 = "fcd90867a70eb46d5e2907086ac6eb80fdac6148849855fd5f518435922aba9c"
scoring_timeout_s = 60
[inputs]
bundle_sha256 = "321ed6accb41cec1a1d5a5212d76e4238d591498dea4d22d9e00760344747478"
module_sha256 = "b2a0020e4c5cff711b643d4f8e5682ba96d8c9a3a498cf23fbf67eb6b62cc104"
allowed = []
allowed_sha256 = []
candidate_sha256 = "b2a0020e4c5cff711b643d4f8e5682ba96d8c9a3a498cf23fbf67eb6b62cc104"
[final]
attempt = 1
sha256 = "b2a0020e4c5cff711b643d4f8e5682ba96d8c9a3a498cf23fbf67eb6b62cc104"
unit_tests_passed = 0
unit_tests_failed = 0
unit_tests_errors = 0
dependents_passed = 1
dependents_failed = 0
[[attempt]]
n = 1
wrote_module = true
sha256 = "b2a0020e4c5cff711b643d4f8e5682ba96d8c9a3a498cf23fbf67eb6b62cc104"
evaluations_passed = 1
evaluations_failed = 0
evaluations_errors = 0
run directory: /private/var/folders/dw/pvtj6mt91znd0hftcztqb0k00000gn/T/tmpv4rkq4i4/run
0