Skip to content

Commit

Permalink
remove superseded and published versions from the staged collection
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnBe committed May 7, 2024
1 parent 36d4a52 commit fc0c0d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 11 additions & 2 deletions bioimageio_collection_backoffice/generate_collection_json.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from pathlib import Path
from typing import Any, Dict, List, Union
from typing import Any, Dict, List, Optional, Union

from bioimageio.spec import ValidationContext
from bioimageio.spec._internal.io import (
get_sha256, # TODO: use bioimageio.spec.utils.get_sha256
)
from bioimageio.spec.common import HttpUrl
from bioimageio.spec.utils import download
from loguru import logger
from ruyaml import YAML

from .remote_resource import PublishedVersion, StagedVersion
Expand All @@ -18,7 +19,7 @@
def create_entry(
client: Client,
rv: Union[PublishedVersion, StagedVersion],
) -> Dict[str, Any]:
) -> Optional[Dict[str, Any]]:
with ValidationContext(perform_io_checks=False):
rdf_url = HttpUrl(rv.rdf_url)

Expand Down Expand Up @@ -91,6 +92,14 @@ def maybe_swap_with_thumbnail(
client.get_file_url("").strip("/") + "/" + rv.folder.strip("/") + "/files"
)
entry["info"] = rv.info.model_dump(mode="json")
if isinstance(rv, StagedVersion) and (
status := entry["info"]["status"]["name"]
) in (
"superseded",
"published",
):
logger.debug("skipping {} staged version {} {}", status, rv.id, rv.version)
return None
try:
old_doi = rdf["config"]["_conceptdoi"]
except KeyError:
Expand Down
6 changes: 4 additions & 2 deletions bioimageio_collection_backoffice/remote_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def generate_collection_json(
)
logger.error(error_in_published_entry)
else:
collection["collection"].append(entry)
if entry is not None:
collection["collection"].append(entry)
elif mode == "staged":
for rv in self.get_all_staged_versions():
try:
Expand All @@ -76,7 +77,8 @@ def generate_collection_json(
"failed to create {} {} entry: {}", rv.id, rv.version, e
)
else:
collection["collection"].append(entry)
if entry is not None:
collection["collection"].append(entry)
else:
assert_never(mode)
coll_descr = build_description(
Expand Down

0 comments on commit fc0c0d0

Please sign in to comment.