@@ -101,20 +101,24 @@ def from_json(cls, name: str, value: object) -> StepRecord:
101101
102102@dataclass
103103class BuildReport :
104- """The JSON build report: step states and timestamps ."""
104+ """The JSON build report: step states, timestamps, and the build's inputs ."""
105105
106106 created_at : str
107107 updated_at : str
108108 steps : dict [str , StepRecord ] = field (default_factory = dict )
109+ inputs : dict [str , str ] | None = None
109110 version : int = REPORT_VERSION
110111
111112 def to_json (self ) -> dict [str , object ]:
112- return {
113+ data : dict [ str , object ] = {
113114 "version" : self .version ,
114115 "created_at" : self .created_at ,
115116 "updated_at" : self .updated_at ,
116117 "steps" : {name : step .to_json () for name , step in self .steps .items ()},
117118 }
119+ if self .inputs is not None :
120+ data ["inputs" ] = dict (self .inputs )
121+ return data
118122
119123 @classmethod
120124 def from_json (cls , value : object ) -> BuildReport :
@@ -143,10 +147,20 @@ def from_json(cls, value: object) -> BuildReport:
143147 name : StepRecord .from_json (name , step )
144148 for name , step in _object ("report.steps" , data ["steps" ]).items ()
145149 }
150+ inputs : dict [str , str ] | None = None
151+ if data .get ("inputs" ) is not None :
152+ recorded = _object ("report.inputs" , data ["inputs" ])
153+ inputs = {}
154+ for key , item in recorded .items ():
155+ if not isinstance (item , str ):
156+ msg = f"report.inputs.{ key } : expected a string, got { item !r} "
157+ raise BuildReportError (msg )
158+ inputs [key ] = item
146159 return cls (
147160 created_at = _required_text ("report" , data , "created_at" ),
148161 updated_at = _required_text ("report" , data , "updated_at" ),
149162 steps = steps ,
163+ inputs = inputs ,
150164 version = version ,
151165 )
152166
@@ -156,23 +170,37 @@ class BuildManager:
156170
157171 Persists status and timing for each named step to a JSON file.
158172 Steps already marked ``"done"`` are skipped on subsequent runs,
159- enabling resumable builds.
173+ enabling resumable builds. When *inputs* are given and differ from
174+ the ones recorded in the report, every step starts again as pending.
160175
161176 Parameters
162177 ----------
163178 report_path : Path
164179 Path to the JSON report file (created if absent).
165180 step_names : list[str]
166181 Ordered names of build steps to track.
182+ inputs : Mapping[str, str], optional
183+ What the build's outputs depend on, such as the ITK commit and the
184+ package version. Recorded in the report under ``inputs``.
167185
168186 Attributes
169187 ----------
170188 report : BuildReport
171189 In-memory report, written to *report_path* by ``save``.
190+ changed_inputs : list[str]
191+ Names of the inputs that differ from the recorded report, or are
192+ missing from it; empty when the recorded steps were kept.
172193 """
173194
174- def __init__ (self , report_path : Path , step_names : list [str ]):
195+ def __init__ (
196+ self ,
197+ report_path : Path ,
198+ step_names : list [str ],
199+ inputs : Mapping [str , str ] | None = None ,
200+ ):
175201 self .report_path = Path (report_path )
202+ self .inputs = dict (inputs ) if inputs is not None else None
203+ self .changed_inputs : list [str ] = []
176204 self ._init_structure (step_names )
177205 self ._load_if_exists ()
178206
@@ -243,6 +271,7 @@ def _init_structure(self, step_names: list[str]) -> None:
243271 created_at = now ,
244272 updated_at = now ,
245273 steps = {name : StepRecord () for name in step_names },
274+ inputs = dict (self .inputs ) if self .inputs is not None else None ,
246275 )
247276
248277 def _load_if_exists (self ) -> None :
@@ -258,6 +287,15 @@ def _load_if_exists(self) -> None:
258287 f"Fix or delete it to continue."
259288 )
260289 raise RuntimeError (msg ) from e
290+ if self .inputs is not None :
291+ recorded = existing .inputs or {}
292+ self .changed_inputs = sorted (
293+ name
294+ for name in self .inputs .keys () | recorded .keys ()
295+ if self .inputs .get (name ) != recorded .get (name )
296+ )
297+ if self .changed_inputs :
298+ return
261299 # Merge existing with current set of steps, preserving statuses
262300 for name in self .report .steps :
263301 if name in existing .steps :
0 commit comments