Skip to content

Commit

Permalink
Merge pull request #601 from bioimage-io/rm_version_number
Browse files Browse the repository at this point in the history
Remove version_number field
  • Loading branch information
FynnBe authored May 28, 2024
2 parents 38cb0af + 0c990f7 commit 3dfb341
Show file tree
Hide file tree
Showing 35 changed files with 119 additions and 1,023 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ Made with [contrib.rocks](https://contrib.rocks).

### bioimageio.spec Python package

#### bioimageio.spec 0.5.2post6 (to be released)
#### bioimageio.spec 0.5.3

* remove collection description
* update SPDX license list
* update generic description to 0.3.1
* update model description to 0.5.3
* add timeout argument to all requests.get calls

#### bioimageio.spec 0.5.2post5

Expand Down Expand Up @@ -283,6 +287,11 @@ Made with [contrib.rocks](https://contrib.rocks).

### Resource Description Format Versions

#### general 0.3.1 and model 0.5.3

* Non-breaking changes
* remove `version_number` in favor of using `version`

#### model 0.5.2

* Non-breaking changes
Expand Down
2 changes: 1 addition & 1 deletion bioimageio/spec/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.5.2post5"
"version": "0.5.3"
}
3 changes: 0 additions & 3 deletions bioimageio/spec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

from . import application as application
from . import collection as collection
from . import dataset as dataset
from . import generic as generic
from . import model as model
Expand Down Expand Up @@ -31,8 +30,6 @@
)
from .application import AnyApplicationDescr as AnyApplicationDescr
from .application import ApplicationDescr as ApplicationDescr
from .collection import AnyCollectionDescr as AnyCollectionDescr
from .collection import CollectionDescr as CollectionDescr
from .dataset import AnyDatasetDescr as AnyDatasetDescr
from .dataset import DatasetDescr as DatasetDescr
from .generic import AnyGenericDescr as AnyGenericDescr
Expand Down
12 changes: 0 additions & 12 deletions bioimageio/spec/_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
from .application import AnyApplicationDescr, ApplicationDescr
from .application.v0_2 import ApplicationDescr as ApplicationDescr02
from .application.v0_3 import ApplicationDescr as ApplicationDescr03
from .collection import AnyCollectionDescr, CollectionDescr
from .collection.v0_2 import CollectionDescr as CollectionDescr02
from .collection.v0_3 import CollectionDescr as CollectionDescr03
from .dataset import AnyDatasetDescr, DatasetDescr
from .dataset.v0_2 import DatasetDescr as DatasetDescr02
from .dataset.v0_3 import DatasetDescr as DatasetDescr03
Expand All @@ -38,7 +35,6 @@
Annotated[
Union[
ApplicationDescr,
CollectionDescr,
DatasetDescr,
ModelDescr,
NotebookDescr,
Expand All @@ -53,7 +49,6 @@
SpecificResourceDescr = Annotated[
Union[
AnyApplicationDescr,
AnyCollectionDescr,
AnyDatasetDescr,
AnyModelDescr,
AnyNotebookDescr,
Expand Down Expand Up @@ -99,13 +94,6 @@ def dump_description(
None: ApplicationDescr,
}
),
"collection": MappingProxyType(
{
"0.2": CollectionDescr02,
"0.3": CollectionDescr03,
None: CollectionDescr,
}
),
"dataset": MappingProxyType(
{
"0.2": DatasetDescr02,
Expand Down
23 changes: 12 additions & 11 deletions bioimageio/spec/_internal/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ class Settings(BaseSettings, extra="ignore"):
"""url to bioimageio collection.json to resolve collection specific resource IDs.
"""

collection_staged: str = (
"https://uk1s3.embassy.ebi.ac.uk/public-datasets/bioimage.io/collection_staged.json"
collection_draft: str = (
"https://uk1s3.embassy.ebi.ac.uk/public-datasets/bioimage.io/collection_draft.json"
)
"""url to bioimageio collection_staged.json to resolve collection specific, staged
resource IDs."""

resolve_staged: bool = True
"""Flag to resolve staged resource versions following the pattern
<resource id>/staged/<stage number>.
Note that anyone may stage a new resource version and that such a staged version
may not have been reviewed.
Set this flag to False to avoid this potential security risk."""
"""url to bioimageio collection_draft.json to resolve collection specific draft
versions of resources ending with '/draft'."""

resolve_draft: bool = True
"""Flag to resolve draft resource versions following the pattern
<resource id>/draft.
Note that anyone may stage a new draft and that such a draft version
may not have been reviewed yet.
Set this flag to False to avoid this potential security risk
and disallow loading draft versions."""

perform_io_checks: bool = True
"""wether or not to perform validation that requires file io,
Expand Down
107 changes: 38 additions & 69 deletions bioimageio/spec/_internal/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def open_bioimageio_yaml(

collection = get_collection()
if source not in collection:
if "/staged/" in source:
if settings.resolve_staged:
collection_url = settings.collection_staged
if isinstance(source, str) and source.endswith("/draft"):
if settings.resolve_draft:
collection_url = settings.collection_draft
else:
collection_url = ""
logger.error(
"Did not try to resolve '{}' as BIOIMAGEIO_RESOLVE_STAGED is set to False",
"Did not try to resolve '{}' as BIOIMAGEIO_RESOLVE_DRAFT is set to False",
source,
)
else:
Expand All @@ -115,7 +115,7 @@ def open_bioimageio_yaml(
logger.info(
"{} loading {} {} from {}",
entry.emoji,
entry.id,
f"{entry.id}/{entry.version}",
entry.version,
entry.url,
)
Expand All @@ -142,6 +142,7 @@ class _CollectionEntry(NamedTuple):
url: str
sha256: Optional[Sha256]
version: str
doi: Optional[str]


def _get_one_collection(url: str):
Expand All @@ -160,81 +161,49 @@ def _get_one_collection(url: str):
logger.error("`collection` field of {} has type {}", url, type(collection))
return ret

for entry in collection:
if entry["entry_sha256"] is None:
logger.debug("skipping {} with entry_sha256=None", entry["id"])
continue

if not isinstance(entry, dict):
logger.error("entry has type {}", type(entry))
continue
if not isinstance(entry["id"], str):
logger.error("entry['id'] has type {}", type(entry["id"]))
continue
if not isinstance(entry["id_emoji"], str):
logger.error(
"{}.id_emoji has type {}", entry["id"], type(entry["id_emoji"])
for raw_entry in collection:
try:
for i, (v, d) in enumerate(zip(raw_entry["versions"], raw_entry["dois"])):
entry = _CollectionEntry(
id=raw_entry["id"],
emoji=raw_entry.get("id_emoji", raw_entry.get("nickname_icon", "")),
url=raw_entry["rdf_source"],
sha256=raw_entry["rdf_sha256"],
version=v,
doi=d,
)
ret[f"{raw_entry['id']}/{v}"] = entry
if i == 0:
# latest version
ret[raw_entry["id"]] = entry
if (concept_doi := raw_entry.get("concept_doi")) is not None:
ret[concept_doi] = entry

if (nickname := raw_entry.get("nickname")) is not None:
ret[nickname] = entry

if d is not None:
ret[d] = entry

except Exception as e:
entry_id = (
raw_entry.get("id", "unknown")
if isinstance(raw_entry, dict)
else "unknown"
)
continue
if not isinstance(entry["entry_source"], str):
logger.error(
"{}.entry_source has type {}", entry["id"], type(entry["entry_source"])
)
continue
if not isinstance(entry["entry_sha256"], str):
logger.error(
"{}.entry_sha256 has type {}", entry["id"], type(entry["entry_sha256"])
"failed to parse collection entry with `id={}`: {}", entry_id, e
)
continue

c_entry = _CollectionEntry(
entry["id"],
entry["id_emoji"],
entry["entry_source"],
(
None
if entry.get("entry_sha256") is None
else Sha256(entry["entry_sha256"])
),
version=str(entry["version_number"]),
)
# set version specific entry
ret[c_entry.id + "/" + str(entry["version_number"])] = c_entry

# set doi entry
doi = entry.get("doi")
if doi is not None:
ret[doi] = c_entry

# update 'latest version' entry
if c_entry.id not in ret:
update = True
else:
old_v = ret[c_entry.id].version
v = c_entry.version

if old_v.startswith("staged"):
update = not v.startswith("staged") or int(
v.replace("staged/", "")
) > int(old_v.replace("staged/", ""))
else:
update = not v.startswith("staged") and int(v) > int(old_v)

if update:
ret[c_entry.id] = c_entry
# set concept doi entry
concept_doi = entry.get("concept_doi")
if concept_doi is not None:
ret[concept_doi] = c_entry

return ret


@lru_cache
def get_collection() -> Mapping[str, _CollectionEntry]:
try:
if settings.resolve_staged:
ret = _get_one_collection(settings.collection_staged)
if settings.resolve_draft:
ret = _get_one_collection(settings.collection_draft)
else:
ret = {}

Expand Down
8 changes: 2 additions & 6 deletions bioimageio/spec/application/v0_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pydantic import Field
from typing_extensions import Annotated

from .._internal.common_nodes import Node
from .._internal.io import FileDescr as FileDescr
from .._internal.io_basics import AbsoluteFilePath as AbsoluteFilePath
from .._internal.io_basics import Sha256 as Sha256
Expand All @@ -14,7 +13,7 @@
from ..generic.v0_3 import BadgeDescr as BadgeDescr
from ..generic.v0_3 import CiteEntry as CiteEntry
from ..generic.v0_3 import Doi as Doi
from ..generic.v0_3 import GenericDescrBase, ResourceId
from ..generic.v0_3 import GenericDescrBase, LinkedResourceNode, ResourceId
from ..generic.v0_3 import LinkedResource as LinkedResource
from ..generic.v0_3 import Maintainer as Maintainer
from ..generic.v0_3 import OrcidId as OrcidId
Expand Down Expand Up @@ -45,11 +44,8 @@ class ApplicationDescr(GenericDescrBase, title="bioimage.io application specific
"""The primary source of the application"""


class LinkedApplication(Node):
class LinkedApplication(LinkedResourceNode):
"""Reference to a bioimage.io application."""

id: ApplicationId
"""A valid application `id` from the bioimage.io collection."""

version_number: int
"""version number (n-th published version, not the semantic version) of linked application"""
20 changes: 0 additions & 20 deletions bioimageio/spec/collection/__init__.py

This file was deleted.

Loading

0 comments on commit 3dfb341

Please sign in to comment.