Skip to content

Move KINDs to the MPI Standard #19

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

Draft
wants to merge 12 commits into
base: develop
Choose a base branch
from
Draft
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
65 changes: 51 additions & 14 deletions src/pympistandard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""


__all__ = ["PROCEDURES", "KINDS", "CALLBACKS", "PREDEFINED_FUNCTIONS"]
__all__ = ["PROCEDURES", "KINDS", "CALLBACKS", "PREDEFINED_FUNCTIONS", "CONSTANTS"]
__author__ = "Martin Ruefenacht"
__version__ = "0.1"

Expand All @@ -19,13 +19,21 @@
import sys


MPI_DATABASE_FILE: str = "apis.json"
MPI_DATABASE_FILE: str = "mpidb.json"


from .storage import KINDS, PROCEDURES, CALLBACKS, PREDEFINED_FUNCTIONS, clear_storage
from .storage import (
KINDS,
PROCEDURES,
CALLBACKS,
PREDEFINED_FUNCTIONS,
CONSTANTS,
clear_storage,
)
from .parameter import Direction
from .procedure import Procedure
from .callback import Callback
from .constant import Constant
from .predefined_function import PredefinedFunction
from .kind import Kind, PolyKind
from . import _kinds
Expand Down Expand Up @@ -70,7 +78,7 @@ def use_api_version(

# load version of API
if version in (1, "LATEST"):
_register_kinds_v1()
# _register_kinds_v1()

path = _resolve_path(given_path, force_bundled)
_load_database_v1(path)
Expand Down Expand Up @@ -123,14 +131,14 @@ def all_f90_procedures() -> Tuple[Procedure]:
)


def _register_kinds_v1() -> None:
"""
Register all Kind instances found in the _kinds.py file in the KINDS variable.
"""

for key, item in _kinds.__dict__.items():
if isinstance(item, Kind):
KINDS[key.lower()] = item
# def _register_kinds_v1() -> None:
# """
# Register all Kind instances found in the _kinds.py file in the KINDS variable.
# """
#
# for key, item in _kinds.__dict__.items():
# if isinstance(item, Kind):
# KINDS[key.lower()] = item


def _load_bundled_db():
Expand Down Expand Up @@ -176,11 +184,31 @@ def _resolve_path(
return path


def _load_kind_v1(kind) -> Kind:
if kind["kind_name"].startswith("POLY"):
return PolyKind(
kind["kind_name"],
kind["lis"],
kind["c_small"],
kind["f90"],
kind["f08_small"],
kind["c_large"],
kind["f08_large"],
)

else:
return Kind(
kind["kind_name"], kind["lis"], kind["c_small"], kind["f90"], kind["f08_small"]
)


def _load_database_v1(path: Path) -> None:
"""
Find and register all procedures found in the 'apis.json' file with Procedure instances.
"""

# TODO discover which files of our database are in path, apis.json, constants.json

with path.open("r") as datafile:
if path.suffix == ".json":
dataset = json.load(datafile)
Expand All @@ -198,8 +226,12 @@ def _load_database_v1(path: Path) -> None:
else:
raise RuntimeError(f"Unrecognized suffix of data file {path}")

# read in datafile
for name, desc in dataset.items():
# read in all kinds
for name, desc in dataset["kinds"].items():
KINDS[name.lower()] = _load_kind_v1(desc)

# read in all procedures, callbacks, predefined_functions
for name, desc in dataset["procedures"].items():
if desc["attributes"]["predefined_function"]:
predef = PredefinedFunction(name, desc)
PREDEFINED_FUNCTIONS[predef.name] = predef
Expand All @@ -211,3 +243,8 @@ def _load_database_v1(path: Path) -> None:
else:
procedure = Procedure(name, desc)
PROCEDURES[procedure.name] = procedure

# read in all constants
for name, desc in dataset["constants"].items():
const = Constant(name, desc)
CONSTANTS[name] = const
Loading