1111import tomli_w
1212from pydantic import BaseModel , Field , PrivateAttr
1313
14- from modflow_devtools .dfns .schema import Dfns
14+ from modflow_devtools .dfn import schema as dfn
15+ from modflow_devtools .dfns import schema as dfns
1516
1617__all__ = [
1718 "DfnRegistry" ,
@@ -27,10 +28,7 @@ class DfnRegistry(BaseModel):
2728
2829 model_config = {"arbitrary_types_allowed" : True }
2930
30- _spec : Dfns | None = PrivateAttr (default = None , init = False )
31-
32- @property
33- def spec (self ) -> Dfns :
31+ def spec (self , schema_version : str = dfns .CURRENT_SCHEMA_VERSION ) -> dfns .Dfns | dfn .Dfns :
3432 raise NotImplementedError
3533
3634 def get_path (self , component : str ) -> Path :
@@ -45,11 +43,10 @@ class LocalDfnRegistry(DfnRegistry):
4543 def model_post_init (self , _ ) -> None :
4644 object .__setattr__ (self , "path" , Path (self .path ).expanduser ().resolve ())
4745
48- @property
49- def spec (self ) -> Dfns :
50- if self ._spec is None :
51- self ._spec = Dfns .load (self .path )
52- return self ._spec
46+ def spec (self , schema_version : str = dfns .CURRENT_SCHEMA_VERSION ) -> dfns .Dfns | dfn .Dfns :
47+ if schema_version == dfns .CURRENT_SCHEMA_VERSION :
48+ return dfns .Dfns .load (self .path )
49+ return dfn .Dfn .load_all (self .path , schema_version = schema_version ) # type: ignore
5350
5451 def get_path (self , component : str ) -> Path :
5552 for ext in [".dfn" , ".toml" ]:
@@ -163,13 +160,12 @@ def cache_path(self) -> Path:
163160 repo , _ = self .release_id .split ("@" )
164161 return RemoteDfnRegistry .base_cache_path () / repo / self .latest_tag ()
165162
166- @property
167- def spec (self ) -> Dfns :
168- if self ._spec is None :
169- if not self .cache_path .exists () or not any (self .cache_path .iterdir ()):
170- self .sync ()
171- self ._spec = Dfns .load (self .cache_path )
172- return self ._spec
163+ def spec (self , schema_version : str = dfns .CURRENT_SCHEMA_VERSION ) -> dfns .Dfns | dfn .Dfns :
164+ if not self .cache_path .exists () or not any (self .cache_path .iterdir ()):
165+ self .sync ()
166+ if schema_version == dfns .CURRENT_SCHEMA_VERSION :
167+ return dfns .Dfns .load (self .cache_path )
168+ return dfn .Dfn .load_all (self .cache_path , schema_version = schema_version ) # type: ignore
173169
174170 def sync (self , force : bool = False ) -> None :
175171 """Download and extract DFN files for this release to the local cache."""
0 commit comments