Skip to content

Commit

Permalink
Draft vX modules
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhekhorn committed Oct 17, 2024
1 parent e4b04e9 commit e0aa2c8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/eko/io/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from .. import version as vmod
from ..interpolation import XGrid
from . import v1, v2
from .dictlike import DictLike
from .paths import InternalPaths
from .types import EvolutionPoint as EPoint
Expand Down Expand Up @@ -56,19 +57,21 @@ def load(cls, path: os.PathLike):
Returns
-------
bool
Metadata
loaded metadata
"""
path = pathlib.Path(path)
paths = InternalPaths(path)
# read raw file first to catch version
raw = yaml.safe_load(InternalPaths(path).metadata.read_text(encoding="utf-8"))
raw = yaml.safe_load(paths.metadata.read_text(encoding="utf-8"))
version = parse(raw["version"])
# patch if necessary
if version.major == 0 and version.minor == 13:
raise NotImplementedError("TODO")
raw = v1.update_metadata(paths, raw)
elif version.major == 0 and version.minor == 14:
raise NotImplementedError("TODO")
else:
content = cls.from_dict(raw)
raw = v2.update_metadata(paths, raw)
# now we are ready
content = cls.from_dict(raw)
content._path = path
return content

Expand Down
25 changes: 25 additions & 0 deletions src/eko/io/v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Legacy interface to files created with v0.13.
Although the data version v1 was already before v0.13 we only support
that API version.
"""

from .paths import InternalPaths


def update_metadata(paths: InternalPaths, raw: dict) -> dict:
"""Modify the raw metadata to the new format.
Parameters
----------
paths:
base paths to the EKO
raw:
raw yaml content
Returns
-------
dict
compatible raw yaml content
"""
return raw
26 changes: 26 additions & 0 deletions src/eko/io/v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Legacy interface to files created with v0.14.
Although the data version v2 was never assigned to v0.14 we use it for
exactly that API version.
"""

from .paths import InternalPaths


def update_metadata(paths: InternalPaths, raw: dict) -> dict:
"""Modify the raw metadata to the new format.
Parameters
----------
paths:
base paths to the EKO
raw:
raw yaml content
Returns
-------
dict
compatible raw yaml content
"""
raw["data_version"] = 2
return raw
2 changes: 1 addition & 1 deletion src/eko/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"""

__version__ = "0.0.0"
__data_version__ = 1
__data_version__ = 3

0 comments on commit e0aa2c8

Please sign in to comment.