Skip to content

Commit

Permalink
add uploader to collection.json
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnBe committed Nov 13, 2024
1 parent 1d3c601 commit ed821b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
6 changes: 6 additions & 0 deletions bioimageio_collection_backoffice/collection_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
21 changes: 3 additions & 18 deletions bioimageio_collection_backoffice/remote_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
List,
Literal,
Mapping,
NamedTuple,
Optional,
Sequence,
Tuple,
Expand Down Expand Up @@ -50,6 +49,7 @@
CollectionWebsiteConfig,
ConceptSummary,
ConceptVersion,
Uploader,
)
from .db_structure.chat import Chat, Message
from .db_structure.compatibility import (
Expand Down Expand Up @@ -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`"""
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ed821b2

Please sign in to comment.