From f2c8082407632e575cea192da5f87ccf640cb26f Mon Sep 17 00:00:00 2001 From: fynnbe Date: Tue, 11 Jun 2024 01:31:37 +0200 Subject: [PATCH] add versions_sha256 --- bioimageio_collection_backoffice/collection_json.py | 2 +- bioimageio_collection_backoffice/remote_collection.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bioimageio_collection_backoffice/collection_json.py b/bioimageio_collection_backoffice/collection_json.py index 9a9092bd..87401670 100644 --- a/bioimageio_collection_backoffice/collection_json.py +++ b/bioimageio_collection_backoffice/collection_json.py @@ -54,7 +54,7 @@ class CollectionEntry(Node, frozen=True): type: Literal["application", "model", "notebook", "dataset"] versions: Sequence[str] """available versions of this resource. newest first""" - versions_sha256: Sequence[str] + versions_sha256: Sequence[Optional[str]] """SHA-256 of each versioned RDF""" dois: Sequence[Optional[str]] """version specific dois of the available versions. newest first""" diff --git a/bioimageio_collection_backoffice/remote_collection.py b/bioimageio_collection_backoffice/remote_collection.py index 8cee1ecf..778b2cdc 100644 --- a/bioimageio_collection_backoffice/remote_collection.py +++ b/bioimageio_collection_backoffice/remote_collection.py @@ -1071,7 +1071,9 @@ def maybe_swap_with_thumbnail( if ( this_version_id := f"{concept_doi}/{version_record_id}" ) not in entry_versions: - entry_versions.append(this_version_id) + entry_versions.insert(0, this_version_id) + + versions_sha256: List[Optional[str]] = [None] * (len(entry_versions) - 1) entry_dois = [f"10.5281/zenodo.{v}" for v in entry_versions] else: @@ -1079,6 +1081,10 @@ def maybe_swap_with_thumbnail( entry_id = rdf["id"] legacy_download_count = 0 entry_versions = [v.id for v in versions] + versions_sha256 = [ + None if d is None else hashlib.sha256(d).hexdigest() + for d in [v.client.load_file(v.rdf_path) for v in versions] + ] entry_dois = [v.doi for v in versions] if "/" in rdf["id"]: @@ -1126,6 +1132,7 @@ def maybe_swap_with_thumbnail( training_data=rdf["training_data"] if "training_data" in rdf else None, type=rdf["type"], versions=entry_versions, + versions_sha256=versions_sha256, dois=entry_dois, ) ]