@@ -262,47 +262,46 @@ def persist_versions(versions: list[BuildVersion], dry_run: bool = False) -> Non
262262 json .dump ({"versions" : version_dicts }, fp , indent = 2 )
263263
264264
265- def load_versions () -> list [ BuildVersion ]:
265+ def load_versions () -> dict [ str , BuildVersion ]:
266266 with VERSIONS_PATH .open () as fp :
267- version_dicts = json .load (fp )["versions" ]
268- return [ BuildVersion (** version ) for version in version_dicts ]
267+ versions = json .load (fp )["versions" ]
268+ return { version [ "key" ]: BuildVersion (** version ) for version in versions }
269269
270270
271271def find_new_or_updated (
272272 versions : list [BuildVersion ],
273- current_versions : list [ BuildVersion ],
273+ current_versions : dict [ str , BuildVersion ],
274274 force : bool = False ,
275275) -> list [BuildVersion ]:
276276 if force :
277277 logger .warning ("Generating full build matrix because --force is set" )
278278
279- current_versions_dict = {ver .key : ver for ver in current_versions }
280279 versions_dict = {ver .key : ver for ver in versions }
281280 new_or_updated : list [BuildVersion ] = []
282281
283282 for key , ver in versions_dict .items ():
284- current_ver = current_versions_dict .get (key )
283+ current_ver = current_versions .get (key )
285284 if current_ver is not None :
286285 current_ver .digest = "" # Ignore digest when comparing
287286
288287 # does key exist and are version dicts equal?
289288 updated = current_ver and ver != current_ver
290- new = key not in current_versions_dict
289+ new = key not in current_versions
291290 if new or updated or force :
292291 new_or_updated .append (ver )
293292
294293 return new_or_updated
295294
296295
297- def load_build_contexts (builds_dir : Path ) -> list [ BuildVersion ]:
296+ def load_build_contexts (builds_dir : Path ) -> dict [ str , BuildVersion ]:
298297 """Find JSON files with build contexts and return the corresponding BuildVersion list"""
299298 logger .info (f"Loading builds metadata from { builds_dir .as_posix ()} " )
300- versions : list [ BuildVersion ] = []
299+ versions : dict [ str , BuildVersion ] = {}
301300
302301 for build_file in builds_dir .glob ("*.json" ):
303302 with build_file .open () as fp :
304303 build_data = json .load (fp )
305304 version = BuildVersion (** build_data )
306- versions . append ( version )
305+ versions [ build_data [ "key" ]] = version
307306
308- return sorted_versions ( versions )
307+ return versions
0 commit comments