2222
2323from enum import Enum
2424from pathlib import Path
25- from typing import Annotated , Any
25+ from typing import Any
2626from uuid import UUID
2727
2828import numpy as np
2929from pydantic import (
3030 BaseModel ,
3131 ConfigDict ,
32- PlainSerializer ,
3332 TypeAdapter ,
3433 ValidationError ,
3534 field_serializer ,
3635 field_validator ,
3736 model_validator ,
3837)
3938from pydantic .alias_generators import to_camel , to_snake
40- from pydantic .functional_validators import BeforeValidator
41-
42- from geoh5py .data import DataAssociationEnum , DataTypeEnum
43- from geoh5py .groups import Group , GroupTypeEnum
44- from geoh5py .objects import ObjectBase
45- from geoh5py .shared .validators import (
46- to_class ,
47- to_list ,
48- to_path ,
49- to_type_uid_or_class ,
50- types_to_string ,
51- )
52- from geoh5py .ui_json .annotations import OptionalUUIDList , OptionalValueList
53- from geoh5py .ui_json .validations .form import (
54- empty_string_to_none ,
55- uuid_to_string ,
56- uuid_to_string_or_numeric ,
39+
40+ from geoh5py .groups import GroupTypeEnum
41+ from geoh5py .ui_json .annotations import (
42+ AssociationOptions ,
43+ DataTypeOptions ,
44+ GroupTypes ,
45+ MeshTypes ,
46+ OptionalUUID ,
47+ OptionalUUIDList ,
48+ OptionalValueList ,
49+ PathList ,
5750)
5851
5952
@@ -304,13 +297,6 @@ def valid_choice(self):
304297 return self
305298
306299
307- PathList = Annotated [
308- list [Path ],
309- BeforeValidator (to_path ),
310- BeforeValidator (to_list ),
311- ]
312-
313-
314300class FileForm (BaseForm ):
315301 """
316302 File path uijson form.
@@ -428,21 +414,6 @@ def force_file_description(cls, _):
428414 return ["Directory" ]
429415
430416
431- MeshTypes = Annotated [
432- list [type [ObjectBase ]],
433- BeforeValidator (to_class ),
434- BeforeValidator (to_type_uid_or_class ),
435- BeforeValidator (to_list ),
436- PlainSerializer (types_to_string , when_used = "json" ),
437- ]
438-
439- OptionalUUID = Annotated [
440- UUID | None , # pylint: disable=unsupported-binary-operation
441- BeforeValidator (empty_string_to_none ),
442- PlainSerializer (uuid_to_string ),
443- ]
444-
445-
446417class ObjectForm (BaseForm ):
447418 """
448419 Geoh5py object uijson form.
@@ -457,15 +428,6 @@ class ObjectForm(BaseForm):
457428 mesh_type : MeshTypes
458429
459430
460- GroupTypes = Annotated [
461- list [type [Group ]],
462- BeforeValidator (to_class ),
463- BeforeValidator (to_type_uid_or_class ),
464- BeforeValidator (to_list ),
465- PlainSerializer (types_to_string , when_used = "json" ),
466- ]
467-
468-
469431class GroupForm (BaseForm ):
470432 """
471433 Geoh5py group uijson form.
@@ -480,23 +442,6 @@ class GroupForm(BaseForm):
480442 group_type : GroupTypes
481443
482444
483- Association = Enum ( # type: ignore
484- "Association" ,
485- [(k .name , k .name .capitalize ()) for k in DataAssociationEnum ],
486- type = str ,
487- )
488-
489- DataType = Enum ( # type: ignore
490- "DataType" , [(k .name , k .name .capitalize ()) for k in DataTypeEnum ], type = str
491- )
492-
493- UUIDOrNumber = Annotated [
494- UUID | float | int | None , # pylint: disable=unsupported-binary-operation
495- BeforeValidator (empty_string_to_none ),
496- PlainSerializer (uuid_to_string_or_numeric ),
497- ]
498-
499-
500445class DataFormMixin (BaseModel ):
501446 """
502447 Mixin class to add common attributes a series of data classes.
@@ -513,8 +458,8 @@ class DataFormMixin(BaseModel):
513458 """
514459
515460 parent : str
516- association : Association | list [Association ]
517- data_type : DataType | list [DataType ]
461+ association : AssociationOptions | list [AssociationOptions ]
462+ data_type : DataTypeOptions | list [DataTypeOptions ]
518463
519464
520465class DataForm (DataFormMixin , BaseForm ):
@@ -562,7 +507,7 @@ class GroupMultiDataForm(BaseForm):
562507 group_type : GroupTypes
563508 group_value : OptionalUUID
564509
565- data_type : DataType | list [DataType ]
510+ data_type : DataTypeOptions | list [DataTypeOptions ]
566511 value : str | list [str ]
567512 multi_select : bool = True
568513
0 commit comments