Skip to content

Commit c50c62a

Browse files
author
Martin Ruefenacht
committed
Linked constants with kind
1 parent c4c26ae commit c50c62a

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/pympistandard/__init__.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ def _resolve_path(given_path: Union[str, Path] = None) -> Path:
144144

145145
# use given path
146146
if given_path is not None:
147-
path = given_path / "apis.json"
147+
path = given_path / "mpidb.json"
148148

149149
# use environment variable paths
150150
elif "MPISTANDARD" in os.environ:
151-
path = Path(os.environ["MPISTANDARD"] + "/apis.json")
151+
path = Path(os.environ["MPISTANDARD"] + "/mpidb.json")
152152

153153
# else:
154154
# raise RuntimeError(
@@ -158,7 +158,7 @@ def _resolve_path(given_path: Union[str, Path] = None) -> Path:
158158

159159
else:
160160
# fallback to packaged data
161-
path = importlib.resources.files("pympistandard.data").joinpath("apis.json")
161+
path = importlib.resources.files("pympistandard.data").joinpath("mpidb.json")
162162

163163
# require resolved path to exist
164164
path.resolve(True)
@@ -173,11 +173,6 @@ def _load_database_v1(path: Path) -> None:
173173

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

176-
with path.joinpath("constants.json").open() as constants_file:
177-
for name, desc in dataset.items():
178-
const = Constant(name, desc)
179-
CONSTANTS[const.name] = const
180-
181176
with path.open("r") as datafile:
182177
if path.suffix == ".json":
183178
dataset = json.load(datafile)
@@ -196,7 +191,7 @@ def _load_database_v1(path: Path) -> None:
196191
raise RuntimeError(f"Unrecognized suffix of data file {path}")
197192

198193
# read in datafile
199-
for name, desc in dataset.items():
194+
for name, desc in dataset["procedures"].items():
200195
if desc["attributes"]["predefined_function"]:
201196
predef = PredefinedFunction(name, desc)
202197
PREDEFINED_FUNCTIONS[predef.name] = predef
@@ -208,3 +203,7 @@ def _load_database_v1(path: Path) -> None:
208203
else:
209204
procedure = Procedure(name, desc)
210205
PROCEDURES[procedure.name] = procedure
206+
207+
for name, desc in dataset["constants"].items():
208+
const = Constant(name, desc)
209+
CONSTANTS[name] = const

src/pympistandard/kind.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
from dataclasses import dataclass
99
from collections import defaultdict
10-
from typing import Optional, MutableMapping, TYPE_CHECKING
10+
from typing import Optional, MutableMapping, TYPE_CHECKING, List
1111

1212

13-
from .storage import CALLBACKS
13+
from .storage import CALLBACKS, CONSTANTS
1414

1515

1616
if TYPE_CHECKING:
@@ -106,7 +106,7 @@ def has_embiggenment(self) -> bool:
106106
return False
107107

108108
@property
109-
def callback(self) -> Optional['Callback']:
109+
def callback(self) -> Optional["Callback"]:
110110
"""Access the relevant Callback object for this Kind."""
111111

112112
# NOTE this should eventually be non-optional, all FUNCTION KINDs will have a Callback
@@ -126,6 +126,12 @@ def callback(self) -> Optional['Callback']:
126126

127127
return None
128128

129+
@property
130+
def constants(self) -> List:
131+
"""Access all constants with this KIND."""
132+
133+
return [const for const in CONSTANTS.values() if const.kind == self]
134+
129135
@property
130136
def express(self) -> KindExpressions:
131137
"""Get the KindExpression object to express the Kind in a language."""

0 commit comments

Comments
 (0)