Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hook for submodules for extensions #249

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,6 @@ venv.bak/

# Generated files:
_version.py

# Submodules
xbout/modules/*/
17 changes: 17 additions & 0 deletions xbout/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions xbout/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -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}")