diff --git a/.gitignore b/.gitignore index 907b66d0..2c1cd8bb 100644 --- a/.gitignore +++ b/.gitignore @@ -108,3 +108,6 @@ venv.bak/ # Generated files: _version.py + +# Submodules +xbout/modules/*/ diff --git a/xbout/load.py b/xbout/load.py index 39c77d6f..87f6ec75 100644 --- a/xbout/load.py +++ b/xbout/load.py @@ -12,6 +12,7 @@ from . import geometries from .utils import _set_attrs_on_all_vars, _separate_metadata, _check_filetype, _is_path +from .modules import avail as modules _BOUT_PER_PROC_VARIABLES = [ @@ -240,6 +241,14 @@ def attrs_remove_section(obj, section): else: ds = geometries.apply_geometry(ds, None) + matches = [module for module in modules if module.does_match(ds)] + if len(matches): + assert ( + len(matches) == 1 + ), f"More than module claim to be able to read the dataset: {[x.__file__ for x in matches]}" + (match,) = matches + ds = match.update(ds) + if info == "terse": print("Read in dataset from {}".format(str(Path(datapath)))) elif info: @@ -332,6 +341,14 @@ def attrs_remove_section(obj, section): # BOUT++ ds.bout.fine_interpolation_factor = 8 + matches = [module for module in modules if module.does_match(ds)] + if len(matches): + assert ( + len(matches) == 1 + ), f"More than module claim to be able to read the dataset: {[x.__file__ for x in matches]}" + (match,) = matches + ds = match.update(ds) + if info == "terse": print("Read in dataset from {}".format(str(Path(datapath)))) elif info: diff --git a/xbout/modules/__init__.py b/xbout/modules/__init__.py new file mode 100644 index 00000000..77dcbed6 --- /dev/null +++ b/xbout/modules/__init__.py @@ -0,0 +1,18 @@ +import pkgutil +import importlib + +avail = [] + + +class skeleton: + name = "not set" + + def does_match(self, ds): + return False + + def update(self, ds): + return ds + + +for module in pkgutil.iter_modules(__path__): + importlib.import_module(f"xbout.modules.{module.name}")