Skip to content

Commit

Permalink
Merge pull request #15 from BioImageTools/feat/pydantic
Browse files Browse the repository at this point in the history
Feat/pydantic
  • Loading branch information
d-v-b authored Nov 21, 2024
2 parents 470f4f1 + 06eed37 commit ee5cf52
Show file tree
Hide file tree
Showing 18 changed files with 516 additions and 328 deletions.
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ dev = [
"pytest>=8.3.3",
]

test = ["pytest"]

pydantic=["pydantic"]

[tool.uv]
default-groups = ["docs", "dev"]
default-groups = ["docs", "dev", "pydantic", "test"]

# Ruff configuration for linting and formatting
# https://docs.astral.sh/ruff
Expand Down
7 changes: 7 additions & 0 deletions src/ome_zarr_models/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pydantic


class Base(pydantic.BaseModel):
"""
The base pydantic model for all metadata classes
"""
16 changes: 13 additions & 3 deletions src/ome_zarr_models/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
"""Utility functions."""
from dataclasses import MISSING, fields, is_dataclass

import pydantic
from dataclasses import MISSING, fields, is_dataclass
from pydantic import create_model

from typing import TypeVar
T = TypeVar("T")

def _unique_items_validator(values: list[T]) -> list[T]:
for ind, value in enumerate(values, start=1):
if value in values[ind:]:
raise ValueError(f"Non-unique values in {values}.")
return values

def dataclass_to_pydantic(dataclass_type: type) -> type[pydantic.BaseModel]:
"""Convert a dataclass to a Pydantic model.
Expand Down Expand Up @@ -32,4 +38,8 @@ def dataclass_to_pydantic(dataclass_type: type) -> type[pydantic.BaseModel]:
# No default value
field_definitions[_field.name] = (_field.type, Ellipsis)

<<<<<<< HEAD
return create_model(dataclass_type.__name__, **field_definitions)
=======
return create_model(dataclass_type.__name__, **field_definitions)
>>>>>>> 470f4f1a33aef4ecf2ebf0906c912a3621c8957b
Empty file.
92 changes: 0 additions & 92 deletions src/ome_zarr_models/v04/hcs.py

This file was deleted.

218 changes: 0 additions & 218 deletions src/ome_zarr_models/v04/image.py

This file was deleted.

Empty file removed src/ome_zarr_models/v04/label.py
Empty file.
3 changes: 3 additions & 0 deletions src/ome_zarr_models/v04/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ome_zarr_models.v04.models.axes import Axis
from ome_zarr_models.v04.models.coordinate_transformations import PathScale, PathTranslation, VectorScale, VectorTranslation
from ome_zarr_models.v04.models.multiscales import Dataset, Multiscale, MultiscaleGroupAttrs
13 changes: 13 additions & 0 deletions src/ome_zarr_models/v04/models/axes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from ome_zarr_models.base import Base


class Axis(Base):
"""
Model for an element of `Multiscale.axes`.
See https://ngff.openmicroscopy.org/0.4/#axes-md.
"""

name: str
type: str | None = None
unit: str | None = None
Loading

0 comments on commit ee5cf52

Please sign in to comment.