Pick the chunks that may run at once by predicted parts, and record each prediction beside what the merged chunk touched
CI / tests (pull_request) Successful in 2m47s
CI / tests (pull_request) Successful in 2m47s
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
"""The touch-predictions record: one entry per chunk, its prediction beside what its diff touched."""
|
||||
import re
|
||||
|
||||
from failure import Failure
|
||||
from record_store.stores import RecordStore
|
||||
from touch_predictions.prediction import rendered, Touches
|
||||
from text_files.utc_stamp import STAMPED
|
||||
|
||||
TITLE = "# Touch predictions"
|
||||
|
||||
|
||||
def entry(items: list[int], at: str, head: str, predicted: Touches | None, touched: Touches) -> str:
|
||||
"""A chunk's entry: the items it took, the UTC time at, the short commit its diff ends at, and both lists in a prediction's spelling. predicted is None where no item predicted anything."""
|
||||
return f"## Chunk {', '.join(map(str, items))}, {at}, at {head}\n\n{listed('Predicted', predicted)}\n\n{listed('Touched', touched)}\n"
|
||||
|
||||
|
||||
def listed(label: str, touches: Touches | None) -> str:
|
||||
return f"{label}:\n\n{rendered(touches)}" if touches else f"{label}: none."
|
||||
|
||||
|
||||
def append(store: RecordStore, items: list[int], text: str) -> Failure | None:
|
||||
"""Appends text, the entry of the chunk that took items, in place of each entry the record holds for the same items: a fix after the first entry changes what the chunk touched."""
|
||||
held = store.read()
|
||||
if isinstance(held, Failure):
|
||||
return held
|
||||
kept = re.sub(rf"^## Chunk {', '.join(map(str, items))}, {STAMPED},.*?(?=^## |\Z)", "", held, flags=re.M | re.S)
|
||||
return store.write(f"{kept.rstrip() or TITLE}\n\n{text}")
|
||||
Reference in New Issue
Block a user