Skip to content

Commit ce05fcd

Browse files
author
Martin Ruefenacht
committed
Added yaml support for datafile
1 parent 8f31ac2 commit ce05fcd

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
**/__pycache__
22
**/make.bat
33
**/_build
4+
**/*.json

src/pympistandard/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,23 @@ def _load_database_v1(path: Path) -> None:
145145
"""
146146

147147
with path.open("r") as datafile:
148-
dataset = json.load(datafile)
148+
if path.suffix == ".json":
149+
dataset = json.load(datafile)
149150

151+
elif path.suffix == ".yaml":
152+
try:
153+
import yaml
154+
155+
dataset = yaml.load(datafile)
156+
157+
except Exception as error:
158+
print("yaml may not be installed")
159+
raise error
160+
161+
else:
162+
raise RuntimeError(f"Unrecognized suffix of data file {path}")
163+
164+
# read in datafile
150165
for name, desc in dataset.items():
151166
if desc["attributes"]["predefined_function"]:
152167
predef = PredefinedFunction(name, desc)

0 commit comments

Comments
 (0)