From baa5471af72a93cc0bd2f54d7b3471e5dc9615d6 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Fri, 26 Jul 2024 21:58:07 -0700 Subject: [PATCH] getting started doing hdmf mixins but am tired --- .../src/nwb_linkml/generators/pydantic.py | 2 +- .../src/nwb_linkml/includes/__init__.py | 0 nwb_linkml/src/nwb_linkml/includes/hdmf.py | 37 +++++++++++++++++++ .../{includes.py => includes/types.py} | 0 nwb_linkml/src/nwb_linkml/lang_elements.py | 9 ----- 5 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 nwb_linkml/src/nwb_linkml/includes/__init__.py create mode 100644 nwb_linkml/src/nwb_linkml/includes/hdmf.py rename nwb_linkml/src/nwb_linkml/{includes.py => includes/types.py} (100%) diff --git a/nwb_linkml/src/nwb_linkml/generators/pydantic.py b/nwb_linkml/src/nwb_linkml/generators/pydantic.py index 1b15468..f35b4d9 100644 --- a/nwb_linkml/src/nwb_linkml/generators/pydantic.py +++ b/nwb_linkml/src/nwb_linkml/generators/pydantic.py @@ -62,7 +62,7 @@ from pydantic import BaseModel from nwb_linkml.maps import flat_to_nptyping from nwb_linkml.maps.naming import module_case, version_module_case -from nwb_linkml.includes import ModelTypeString, _get_name, NamedString, NamedImports +from nwb_linkml.includes.types import ModelTypeString, _get_name, NamedString, NamedImports OPTIONAL_PATTERN = re.compile(r"Optional\[([\w\.]*)\]") diff --git a/nwb_linkml/src/nwb_linkml/includes/__init__.py b/nwb_linkml/src/nwb_linkml/includes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nwb_linkml/src/nwb_linkml/includes/hdmf.py b/nwb_linkml/src/nwb_linkml/includes/hdmf.py new file mode 100644 index 0000000..ee81b39 --- /dev/null +++ b/nwb_linkml/src/nwb_linkml/includes/hdmf.py @@ -0,0 +1,37 @@ +""" +Special types for mimicking HDMF special case behavior +""" + +from typing import Optional +from pydantic import BaseModel, field_validator, ConfigDict, model_validator + + +class DynamicTableMixin(BaseModel): + model_config = ConfigDict(extra='allow') + + @model_validator(mode='after') + def ensure_equal_length(cls, model: 'DynamicTableMixin') -> 'DynamicTableMixin': + """ + Ensure all vectors are of equal length + """ + raise NotImplementedError('TODO') + + @model_validator(mode="after") + def create_index_backrefs(cls, model: 'DynamicTableMixin') -> 'DynamicTableMixin': + """ + Ensure that vectordata with vectorindexes know about them + """ + raise NotImplementedError('TODO') + + def __getitem__(self, item): + raise NotImplementedError('TODO') + + def __setitem__(self, key, value): + raise NotImplementedError('TODO') + + + +class VectorDataMixin(BaseModel): + index: Optional[BaseModel] = None + + diff --git a/nwb_linkml/src/nwb_linkml/includes.py b/nwb_linkml/src/nwb_linkml/includes/types.py similarity index 100% rename from nwb_linkml/src/nwb_linkml/includes.py rename to nwb_linkml/src/nwb_linkml/includes/types.py diff --git a/nwb_linkml/src/nwb_linkml/lang_elements.py b/nwb_linkml/src/nwb_linkml/lang_elements.py index d35a767..7bb68c4 100644 --- a/nwb_linkml/src/nwb_linkml/lang_elements.py +++ b/nwb_linkml/src/nwb_linkml/lang_elements.py @@ -7,20 +7,12 @@ from typing import List from linkml_runtime.linkml_model import ( ClassDefinition, - EnumDefinition, - PermissibleValue, Prefix, SchemaDefinition, TypeDefinition, ) from nwb_linkml.maps import flat_to_linkml, flat_to_np -from nwb_schema_language.datamodel.nwb_schema_pydantic import FlatDtype as FlatDtype_source - -FlatDType = EnumDefinition( - name="FlatDType", - permissible_values=[PermissibleValue(p) for p in FlatDtype_source.__members__], -) def _make_dtypes() -> List[TypeDefinition]: @@ -59,7 +51,6 @@ NwbLangSchema = SchemaDefinition( name="nwb.language", id="nwb.language", description="Adapter objects to mimic the behavior of elements in the nwb-schema-language", - enums=[FlatDType], classes=[AnyType], types=DTypeTypes, imports=["linkml:types"],