Skip to content

Commit 260cac2

Browse files
committed
remove WithGenericFormatVersion mixin
1 parent 5b4dbfc commit 260cac2

File tree

16 files changed

+95
-81
lines changed

16 files changed

+95
-81
lines changed

bioimageio/spec/_internal/base_nodes.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import inspect
66
import os
77
import traceback
8-
from abc import ABC
8+
from abc import ABC, abstractmethod
99
from copy import deepcopy
1010
from typing import (
1111
Any,
@@ -140,7 +140,7 @@ def set_fields_explicitly(cls, data: Union[Any, Dict[Any, Any]]) -> Union[Any, D
140140
return data
141141

142142

143-
class ResourceDescriptionBase(NodeWithExplicitlySetFields):
143+
class ResourceDescriptionBase(NodeWithExplicitlySetFields, ABC):
144144
"""base class for all resource descriptions"""
145145

146146
_internal_validation_context: InternalValidationContext = PrivateAttr(
@@ -163,15 +163,15 @@ def validation_summaries(self) -> List[ValidationSummary]:
163163
def root(self) -> Union[AnyUrl, DirectoryPath]:
164164
return self._internal_validation_context["root"]
165165

166+
@abstractmethod
166167
@classmethod
167168
def convert_from_older_format(cls, data: BioimageioYamlContent, context: InternalValidationContext) -> None:
168-
pass
169+
...
169170

170171
@model_validator(mode="before")
171172
@classmethod
172-
def update_context_and_data(cls, data: BioimageioYamlContent, info: ValidationInfo):
173+
def _convert_from_older_format(cls, data: BioimageioYamlContent, info: ValidationInfo):
173174
context = get_internal_validation_context(info.context)
174-
cls._update_context(context, data)
175175
cls.convert_from_older_format(data, context)
176176
return data
177177

@@ -304,6 +304,10 @@ class InvalidDescription(ResourceDescriptionBase, extra="allow", title="An inval
304304
format_version: Any = "unknown"
305305
fields_to_set_explicitly: ClassVar[FrozenSet[LiteralString]] = frozenset()
306306

307+
@classmethod
308+
def convert_from_older_format(cls, data: BioimageioYamlContent, context: InternalValidationContext) -> None:
309+
pass
310+
307311

308312
class StringNode(collections.UserString, ABC):
309313
"""deprecated! don't use for new spec fields!"""

bioimageio/spec/application/v0_2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
from bioimageio.spec.generic.v0_2 import Author as Author
1111
from bioimageio.spec.generic.v0_2 import Badge as Badge
1212
from bioimageio.spec.generic.v0_2 import CiteEntry as CiteEntry
13-
from bioimageio.spec.generic.v0_2 import GenericBase, WithGenericFormatVersion
13+
from bioimageio.spec.generic.v0_2 import GenericBase
1414
from bioimageio.spec.generic.v0_2 import LinkedResource as LinkedResource
1515
from bioimageio.spec.generic.v0_2 import Maintainer as Maintainer
1616

1717

18-
class Application(GenericBase, WithGenericFormatVersion, title="bioimage.io application specification"):
18+
class Application(GenericBase, title="bioimage.io application specification"):
1919
"""Bioimage.io description of an application."""
2020

2121
type: Literal["application"] = "application"

bioimageio/spec/application/v0_3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
from bioimageio.spec.generic.v0_3 import Author as Author
1111
from bioimageio.spec.generic.v0_3 import Badge as Badge
1212
from bioimageio.spec.generic.v0_3 import CiteEntry as CiteEntry
13-
from bioimageio.spec.generic.v0_3 import GenericBase, WithGenericFormatVersion
13+
from bioimageio.spec.generic.v0_3 import GenericBase
1414
from bioimageio.spec.generic.v0_3 import LinkedResource as LinkedResource
1515
from bioimageio.spec.generic.v0_3 import Maintainer as Maintainer
1616

1717

18-
class Application(GenericBase, WithGenericFormatVersion, title="bioimage.io application specification"):
18+
class Application(GenericBase, title="bioimage.io application specification"):
1919
"""Bioimage.io description of an application."""
2020

2121
type: Literal["application"] = "application"

bioimageio/spec/collection/v0_2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from bioimageio.spec.generic.v0_2 import Badge as Badge
2828
from bioimageio.spec.generic.v0_2 import CiteEntry as CiteEntry
2929
from bioimageio.spec.generic.v0_2 import Generic as Generic
30-
from bioimageio.spec.generic.v0_2 import GenericBase, WithGenericFormatVersion
30+
from bioimageio.spec.generic.v0_2 import GenericBase
3131
from bioimageio.spec.generic.v0_2 import LinkedResource as LinkedResource
3232
from bioimageio.spec.generic.v0_2 import Maintainer as Maintainer
3333
from bioimageio.spec.model.v0_4 import Model as Model
@@ -111,7 +111,7 @@ def entry(self) -> EntryNode:
111111
return self._entry
112112

113113

114-
class Collection(GenericBase, WithGenericFormatVersion, extra="allow", title="bioimage.io collection specification"):
114+
class Collection(GenericBase, extra="allow", title="bioimage.io collection specification"):
115115
"""A bioimage.io collection describes several other bioimage.io resources.
116116
Note that collections cannot be nested; resources listed under `collection` may not be collections themselves.
117117
"""

bioimageio/spec/collection/v0_3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from bioimageio.spec.generic.v0_3 import Author as Author
1818
from bioimageio.spec.generic.v0_3 import Badge as Badge
1919
from bioimageio.spec.generic.v0_3 import CiteEntry as CiteEntry
20-
from bioimageio.spec.generic.v0_3 import Generic, GenericBase, WithGenericFormatVersion
20+
from bioimageio.spec.generic.v0_3 import Generic, GenericBase
2121
from bioimageio.spec.generic.v0_3 import LinkedResource as LinkedResource
2222
from bioimageio.spec.generic.v0_3 import Maintainer as Maintainer
2323
from bioimageio.spec.model.v0_4 import Model as Model04
@@ -55,7 +55,7 @@ def entry(self) -> EntryNode:
5555
return self._entry
5656

5757

58-
class Collection(GenericBase, WithGenericFormatVersion, extra="allow", title="bioimage.io collection specification"):
58+
class Collection(GenericBase, extra="allow", title="bioimage.io collection specification"):
5959
"""A bioimage.io collection resource description file (collection RDF) describes a collection of bioimage.io
6060
resources.
6161
The resources listed in a collection RDF have types other than 'collection'; collections cannot be nested.

bioimageio/spec/dataset/v0_2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
from bioimageio.spec.generic.v0_2 import Author as Author
1111
from bioimageio.spec.generic.v0_2 import Badge as Badge
1212
from bioimageio.spec.generic.v0_2 import CiteEntry as CiteEntry
13-
from bioimageio.spec.generic.v0_2 import GenericBase, WithGenericFormatVersion
13+
from bioimageio.spec.generic.v0_2 import GenericBase
1414
from bioimageio.spec.generic.v0_2 import Maintainer as Maintainer
1515

1616

17-
class Dataset(GenericBase, WithGenericFormatVersion, title="bioimage.io dataset specification"):
17+
class Dataset(GenericBase, title="bioimage.io dataset specification"):
1818
"""A bioimage.io dataset resource description file (dataset RDF) describes a dataset relevant to bioimage
1919
processing.
2020
"""

bioimageio/spec/dataset/v0_3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
from bioimageio.spec.generic.v0_3 import Author as Author
77
from bioimageio.spec.generic.v0_3 import Badge as Badge
88
from bioimageio.spec.generic.v0_3 import CiteEntry as CiteEntry
9-
from bioimageio.spec.generic.v0_3 import GenericBase, WithGenericFormatVersion
9+
from bioimageio.spec.generic.v0_3 import GenericBase
1010
from bioimageio.spec.generic.v0_3 import HttpUrl as HttpUrl
1111
from bioimageio.spec.generic.v0_3 import Maintainer as Maintainer
1212
from bioimageio.spec.generic.v0_3 import RelativeFilePath as RelativeFilePath
1313

1414

15-
class Dataset(GenericBase, WithGenericFormatVersion, title="bioimage.io dataset specification"):
15+
class Dataset(GenericBase, title="bioimage.io dataset specification"):
1616
"""A bioimage.io dataset resource description file (dataset RDF) describes a dataset relevant to bioimage
1717
processing.
1818
"""

bioimageio/spec/generic/v0_2.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from bioimageio.spec._internal.field_warning import as_warning, warn
1111
from bioimageio.spec._internal.types import (
1212
AbsoluteFilePath,
13+
BioimageioYamlContent,
1314
DeprecatedLicenseId,
1415
Doi,
1516
FileSource,
@@ -21,7 +22,8 @@
2122
Version,
2223
)
2324
from bioimageio.spec._internal.types.field_validation import WithSuffix
24-
from bioimageio.spec._internal.validation_context import get_internal_validation_context
25+
from bioimageio.spec._internal.validation_context import InternalValidationContext, get_internal_validation_context
26+
from bioimageio.spec.generic.v0_2_converter import convert_from_older_format
2527

2628
KNOWN_SPECIFIC_RESOURCE_TYPES = ("application", "collection", "dataset", "model", "notebook")
2729

@@ -144,7 +146,7 @@ class LinkedResource(Node):
144146

145147

146148
class GenericModelBase(ResourceDescriptionBase):
147-
"""Base with common fields"""
149+
"""Base for all resource descriptions including of model descriptions"""
148150

149151
name: Annotated[NotEmpty[str], warn(MaxLen(128), "Longer than 128 characters.")]
150152
"""A human-friendly name of the resource description"""
@@ -285,6 +287,19 @@ def warn_about_tag_categories(cls, value: List[str], info: ValidationInfo) -> Li
285287

286288

287289
class GenericBase(GenericModelBase):
290+
"""Base for all resource descriptions except for the model descriptions"""
291+
292+
format_version: Literal["0.2.3"] = "0.2.3"
293+
"""The format version of this resource specification
294+
(not the `version` of the resource description)
295+
When creating a new resource always use the latest micro/patch version described here.
296+
The `format_version` is important for any consumer software to understand how to parse the fields.
297+
"""
298+
299+
@classmethod
300+
def convert_from_older_format(cls, data: BioimageioYamlContent, context: InternalValidationContext) -> None:
301+
convert_from_older_format(data, context)
302+
288303
badges: List[Badge] = Field(default_factory=list)
289304
"""badges associated with this resource"""
290305

@@ -324,17 +339,7 @@ def deprecated_spdx_license(cls, value: Optional[str]) -> Optional[str]:
324339
ResourceDescriptionType = TypeVar("ResourceDescriptionType", bound=GenericBase)
325340

326341

327-
class WithGenericFormatVersion(Node):
328-
format_version: Literal["0.2.3"] = "0.2.3"
329-
330-
"""The format version of this resource specification
331-
(not the `version` of the resource description)
332-
When creating a new resource always use the latest micro/patch version described here.
333-
The `format_version` is important for any consumer software to understand how to parse the fields.
334-
"""
335-
336-
337-
class Generic(GenericBase, WithGenericFormatVersion, extra="ignore", title="bioimage.io generic specification"):
342+
class Generic(GenericBase, extra="ignore", title="bioimage.io generic specification"):
338343
"""Specification of the fields used in a generic bioimage.io-compliant resource description file (RDF).
339344
340345
An RDF is a YAML file that describes a resource such as a model, a dataset, or a notebook.

bioimageio/spec/generic/v0_3.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from bioimageio.spec._internal.field_warning import as_warning, warn
1212
from bioimageio.spec._internal.types import AbsoluteFilePath as AbsoluteFilePath
1313
from bioimageio.spec._internal.types import (
14+
BioimageioYamlContent,
1415
DeprecatedLicenseId,
1516
FileSource,
1617
LicenseId,
@@ -21,11 +22,13 @@
2122
)
2223
from bioimageio.spec._internal.types import RelativeFilePath as RelativeFilePath
2324
from bioimageio.spec._internal.types.field_validation import WithSuffix
25+
from bioimageio.spec._internal.validation_context import InternalValidationContext
2426
from bioimageio.spec.generic.v0_2 import VALID_COVER_IMAGE_EXTENSIONS, CoverImageSource
2527
from bioimageio.spec.generic.v0_2 import Author as Author
2628
from bioimageio.spec.generic.v0_2 import Badge as Badge
2729
from bioimageio.spec.generic.v0_2 import CiteEntry as CiteEntry
2830
from bioimageio.spec.generic.v0_2 import Maintainer as Maintainer
31+
from bioimageio.spec.generic.v0_3_converter import convert_from_older_format
2932

3033
KNOWN_SPECIFIC_RESOURCE_TYPES = ("application", "collection", "dataset", "model", "notebook")
3134

@@ -51,13 +54,8 @@ class LinkedResource(Node):
5154
"""A valid resource `id` from the official bioimage.io collection."""
5255

5356

54-
class WithGenericFormatVersion(Node):
55-
format_version: Literal["0.3.0"] = "0.3.0"
56-
"""The **format** version of this resource specification"""
57-
58-
5957
class GenericModelBase(ResourceDescriptionBase):
60-
"""Base with with common fields"""
58+
"""Base for all resource descriptions including of model descriptions"""
6159

6260
name: Annotated[NotEmpty[str], MaxLen(128)]
6361
"""A human-friendly name of the resource description"""
@@ -203,6 +201,15 @@ def warn_about_tag_categories(cls, value: List[str], info: ValidationInfo) -> Li
203201

204202

205203
class GenericBase(GenericModelBase):
204+
"""Base for all resource descriptions except for the model descriptions"""
205+
206+
format_version: Literal["0.3.0"] = "0.3.0"
207+
"""The **format** version of this resource specification"""
208+
209+
@classmethod
210+
def convert_from_older_format(cls, data: BioimageioYamlContent, context: InternalValidationContext) -> None:
211+
convert_from_older_format(data, context)
212+
206213
documentation: Annotated[
207214
Optional[MarkdownSource],
208215
Field(
@@ -232,7 +239,7 @@ class GenericBase(GenericModelBase):
232239
ResourceDescriptionType = TypeVar("ResourceDescriptionType", bound=GenericBase)
233240

234241

235-
class Generic(GenericBase, WithGenericFormatVersion, title="bioimage.io generic specification"):
242+
class Generic(GenericBase, title="bioimage.io generic specification"):
236243
"""Specification of the fields used in a generic bioimage.io-compliant resource description file (RDF).
237244
238245
An RDF is a YAML file that describes a resource such as a model, a dataset, or a notebook.

bioimageio/spec/model/v0_4.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,5 +916,4 @@ def ignore_url_parent(cls, parent: Any):
916916

917917
@classmethod
918918
def convert_from_older_format(cls, data: BioimageioYamlContent, context: InternalValidationContext) -> None:
919-
super().convert_from_older_format(data, context)
920919
convert_from_older_format(data, context)

0 commit comments

Comments
 (0)