|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -from typing import Final |
4 | | - |
5 | 3 | from pydantic import BaseModel, field_validator |
6 | 4 | from pydantic.experimental.missing_sentinel import MISSING |
7 | 5 | from zarr_cm import ConventionMetadataObject |
8 | 6 | from zarr_cm import multiscales as multiscales_cm |
9 | 7 |
|
10 | | -from eopf_geozarr.data_api.geozarr.common import ZarrConventionMetadata |
11 | | - |
12 | 8 | # Convention constants from zarr-cm |
13 | 9 | CONVENTION_ID = multiscales_cm.UUID |
14 | 10 | CONVENTION_SCHEMA_URL = multiscales_cm.SCHEMA_URL |
|
22 | 18 | MultiscalesJSON = multiscales_cm.MultiscalesAttrs |
23 | 19 | MultiscalesConventionAttrsJSON = multiscales_cm.MultiscalesConventionAttrs |
24 | 20 |
|
25 | | -# A final dict representation of the Multiscales convention metadata |
26 | | -MULTISCALE_CONVENTION_METADATA: Final[ConventionMetadataObject] = multiscales_cm.CMO |
27 | | - |
28 | | - |
29 | | -class MultiscaleConventionMetadata(ZarrConventionMetadata): |
30 | | - uuid: str = multiscales_cm.CMO["uuid"] |
31 | | - schema_url: str = multiscales_cm.CMO["schema_url"] |
32 | | - name: str = multiscales_cm.CMO["name"] |
33 | | - description: str = multiscales_cm.CMO["description"] |
34 | | - spec_url: str = multiscales_cm.CMO["spec_url"] |
35 | | - |
36 | 21 |
|
37 | 22 | class ZarrConventionAttrs(BaseModel): |
38 | | - zarr_conventions: tuple[ZarrConventionMetadata, ...] |
| 23 | + zarr_conventions: tuple[ConventionMetadataObject, ...] |
39 | 24 |
|
40 | 25 | model_config = {"extra": "allow"} |
41 | 26 |
|
@@ -68,20 +53,15 @@ class MultiscalesAttrs(ZarrConventionAttrs): |
68 | 53 | @field_validator("zarr_conventions", mode="after") |
69 | 54 | @classmethod |
70 | 55 | def ensure_multiscales_convention( |
71 | | - cls, value: tuple[ZarrConventionMetadata, ...] |
72 | | - ) -> tuple[ZarrConventionMetadata, ...]: |
| 56 | + cls, value: tuple[ConventionMetadataObject, ...] |
| 57 | + ) -> tuple[ConventionMetadataObject, ...]: |
73 | 58 | """ |
74 | 59 | Iterate over the elements of zarr_conventions and check that at least one of them is |
75 | 60 | multiscales |
76 | 61 | """ |
77 | | - success: bool = False |
78 | | - errors: dict[int, ValueError] = {} |
79 | | - for idx, convention_meta in enumerate(value): |
80 | | - try: |
81 | | - MultiscaleConventionMetadata(**convention_meta.model_dump()) |
82 | | - success = True |
83 | | - except ValueError as e: |
84 | | - errors[idx] = e |
85 | | - if not success: |
86 | | - raise ValueError("Multiscales convention not found. Errors: " + str(errors)) |
| 62 | + expected_uuid = multiscales_cm.CMO["uuid"] |
| 63 | + if not any(c["uuid"] == expected_uuid for c in value): |
| 64 | + raise ValueError( |
| 65 | + f"Multiscales convention (uuid={expected_uuid}) not found in zarr_conventions" |
| 66 | + ) |
87 | 67 | return value |
0 commit comments