Skip to content

Commit

Permalink
add field sem_ver
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnBe committed Feb 28, 2024
1 parent 06b8272 commit b9714ba
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,11 @@ all generic 0.3.0 changes (except models already have the `parent` field) plus:
#### generic 0.2.4 and model 0.4.10

* Breaking changes that are fully auto-convertible
* `version` is now a single number. The minor version from the previous SemVer 2.0 is used when converting.
* `id_emoji` is a new, optional field (set from `config.bioimageio.nickname_icon` if available)
* `version` is now a single number. If version is set as a string with a dot (from complying with the previous field definition, holding a SemVer 2.0 version), it is moved to the new `sem_ver` field.
* `id` overwritten with value from `config.bioimageio.nickname` if available
* Non-breaking changes
* `sem_ver` is a new, opitonal field (set from `version` if applicable)
* `id_emoji` is a new, optional field (set from `config.bioimageio.nickname_icon` if available)
* `uploader` is a new, optional field with `email` and an optional `name` subfields

#### model 0.4.9
Expand Down
19 changes: 12 additions & 7 deletions bioimageio/spec/generic/v0_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
from bioimageio.spec._internal.types import OrcidId as OrcidId
from bioimageio.spec._internal.types import RelativeFilePath as RelativeFilePath
from bioimageio.spec._internal.types import ResourceId as ResourceId
from bioimageio.spec._internal.types import (
Version as Version,
)
from bioimageio.spec._internal.types.field_validation import (
AfterValidator as _AfterValidator,
)
Expand Down Expand Up @@ -336,16 +339,18 @@ def warn_about_tag_categories(
version: Annotated[int, Ge(ge=1), Field(examples=[1, 2, 3])] = 1
"""The version number of the resource.
note: previous versions of this spec accepted a SemVer 2.0 version, e.g. 0.1.0.
These are now converted by using the minor part as version nr."""
These are now moved to the new `sem_ver` field."""

sem_ver: Optional[Version] = None
"""A SemVer 2.0 version of the resource."""

@field_validator("version", mode="before")
@model_validator(mode="before")
@classmethod
def _convert_version(cls, value: Any):
if isinstance(value, str) and "." in value:
_, v, *_ = value.split(".")
return v
def _convert_version(cls, data: Union[Any, Dict[Any, Any]]):
if isinstance(data, dict) and "." in str(data.get("version")):
data["sem_ver"] = data.pop("version")

return value
return data


class GenericDescrBase(GenericModelDescrBase):
Expand Down
4 changes: 4 additions & 0 deletions bioimageio/spec/generic/v0_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from bioimageio.spec._internal.types import RelativeFilePath as RelativeFilePath
from bioimageio.spec._internal.types import ResourceId as ResourceId
from bioimageio.spec._internal.types import Sha256 as Sha256
from bioimageio.spec._internal.types import Version as Version
from bioimageio.spec._internal.types.field_validation import Predicate, WithSuffix
from bioimageio.spec._internal.validation_context import validation_context_var
from bioimageio.spec.generic import v0_2
Expand Down Expand Up @@ -326,6 +327,9 @@ def warn_about_tag_categories(
version: Annotated[int, Ge(ge=1), Field(examples=[1, 2, 3])] = 1
"""The version number of the resource."""

sem_ver: Optional[Version] = None
"""A SemVer 2.0 version of the resource."""


class GenericDescrBase(GenericModelDescrBase):
"""Base for all resource descriptions except for the model descriptions"""
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def check_bioimageio_yaml(
),
):
# these fields may intentionally be manipulated
exclude_from_comp |= {"version", "id_emoji", "id"}
exclude_from_comp |= {"sem_ver", "id_emoji", "id"}

deserialized = rd.model_dump(
mode="json", exclude=exclude_from_comp, exclude_unset=True
Expand Down

0 comments on commit b9714ba

Please sign in to comment.