#!/usr/bin/env python3 """The project's second judge (the check `improves`, which informs and does not gate a merge): for each dimension the pushed route has a snake for, its longest snake against the longest the default branch holds (constructions/ and routes/ of the check's own checkout, the approved version) and against the public record. A dimension improves when the route's snake has at least one edge more; it is a new record when it has at least one edge more than the record. Passes when some dimension improves. On the default branch itself it reports what it holds and passes.""" import os import pathlib import sys from snake import INSTANCES, best_of, card, is_record, scan main_dir = pathlib.Path(sys.argv[2]) held = best_of(scan([main_dir / "constructions", main_dir / "routes"])) if os.environ.get("SS_ROUTE_DIR", "") == "routes": new = [k for k in INSTANCES if k in held and is_record(k, held[k][0])] holds = ", ".join(f"{k}: {held[k][0]}" for k in INSTANCES if k in held) or "no snake" print(f"the default branch holds {holds}; " + (f"new records: {', '.join(new)}" if new else "no new record")) sys.exit(0) route = best_of(scan([pathlib.Path(sys.argv[1])])) if not route: print("no snake in this route to compare") sys.exit(1) better, new = [], [] for k in (k for k in INSTANCES if k in route): length, name = route[k] h = held.get(k) up = h is None or length > h[0] better += [k] if up else [] new += [k] if is_record(k, length) else [] against = f"the default branch's {h[0]}, {length - h[0]:+d}" if h else "nothing on the default branch" print(f"{k}: {length} edges ({name}) against {against}{': improves' if up else ''}; " + (f"a new record, above {card(k)}" if is_record(k, length) else f"the record is {card(k)}")) if not better: print("no improvement on the default branch") sys.exit(1) print(f"improves on the default branch: {', '.join(better)}; " + (f"new records: {', '.join(new)}" if new else "no new record"))