From ed821b2f900495a24c8716db1ef37c6855c38df0 Mon Sep 17 00:00:00 2001 From: fynnbe Date: Wed, 13 Nov 2024 22:52:43 +0100 Subject: [PATCH] add uploader to collection.json --- .../collection_json.py | 6 ++++++ .../remote_collection.py | 21 +++---------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/bioimageio_collection_backoffice/collection_json.py b/bioimageio_collection_backoffice/collection_json.py index 366b513d..1b4aecf0 100644 --- a/bioimageio_collection_backoffice/collection_json.py +++ b/bioimageio_collection_backoffice/collection_json.py @@ -30,8 +30,14 @@ class TrainingData(Node, frozen=True): id: str +class Uploader(Node, frozen=True): + name: Optional[str] = None + email: str + + class CollectionEntry(Node, frozen=True): authors: Sequence[Author] + uploader: Uploader badges: Sequence[Badge] concept_doi: Optional[str] covers: Sequence[HttpUrl] diff --git a/bioimageio_collection_backoffice/remote_collection.py b/bioimageio_collection_backoffice/remote_collection.py index df657e57..dc8eab32 100644 --- a/bioimageio_collection_backoffice/remote_collection.py +++ b/bioimageio_collection_backoffice/remote_collection.py @@ -19,7 +19,6 @@ List, Literal, Mapping, - NamedTuple, Optional, Sequence, Tuple, @@ -50,6 +49,7 @@ CollectionWebsiteConfig, ConceptSummary, ConceptVersion, + Uploader, ) from .db_structure.chat import Chat, Message from .db_structure.compatibility import ( @@ -569,11 +569,6 @@ def doi(self): return None -class Uploader(NamedTuple): - email: Optional[str] - name: str - - @dataclass class RecordBase(RemoteBase, ABC): """Base class for a `RecordDraft` and `Record`""" @@ -633,18 +628,7 @@ def extend_chat( def get_uploader(self): rdf = self.get_rdf() - try: - uploader = rdf["uploader"] - email = uploader["email"] - name = uploader.get( - "name", f"{rdf.get('type', 'bioimage.io resource')} contributor" - ) - except Exception as e: - logger.error("failed to extract uploader from rdf: {}", e) - email = None - name = "bioimage.io resource contributor" - - return Uploader(email=email, name=name) + return Uploader.model_validate(rdf["uploader"]) def get_file_url(self, path: str): return self.client.get_file_url(f"{self.folder}files/{path}") @@ -1261,6 +1245,7 @@ def get_compat_tag(tool: str): return [ CollectionEntry( authors=rdf.get("authors", []), + uploader=rdf["uploader"], badges=resolve_relative_path( maybe_swap_with_thumbnail(rdf.get("badges", []), thumbnails), parsed_root,