Skip to content

Commit 01203c7

Browse files
martinruefenachtMartin Ruefenacht
andauthored
Bundled apis.json and allow for override (#10)
Co-authored-by: Martin Ruefenacht <martin.ruefenacht@lrz.de>
1 parent af52784 commit 01203c7

File tree

5 files changed

+57117
-17
lines changed

5 files changed

+57117
-17
lines changed

.gitignore

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

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description = "Python API to the MPI Standard"
66
authors = ["Martin Ruefenacht <martin.ruefenacht@lrz.de>"]
77

88
[tool.poetry.dependencies]
9-
python = "^3.6.2"
9+
python = "^3.7"
1010

1111
[tool.poetry.dev-dependencies]
1212
pytest = "^7.0.1"

src/pympistandard/__init__.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
from pathlib import Path
13+
import importlib.resources
1314
import json
1415
from enum import Enum
1516
from typing import Union, Tuple
@@ -54,7 +55,9 @@ def unload() -> None:
5455

5556
# TODO rename to load(api_version, mpi_version, path)
5657
@export
57-
def use_api_version(version: Union[int, str] = "LATEST", given_path: Union[str, Path] = None) -> None:
58+
def use_api_version(
59+
version: Union[int, str] = "LATEST", given_path: Union[str, Path] = None
60+
) -> None:
5861
"""Sets the Python API interface which the user expects to use."""
5962

6063
unload()
@@ -75,7 +78,9 @@ def all_lis_procedures() -> Tuple[Procedure]:
7578
"""Fetch all LIS expressible procedures available in the Standard."""
7679

7780
return tuple(
78-
procedure for procedure in PROCEDURES.values() if procedure.express.lis is not None
81+
procedure
82+
for procedure in PROCEDURES.values()
83+
if procedure.express.lis is not None
7984
)
8085

8186

@@ -84,7 +89,9 @@ def all_iso_c_procedures() -> Tuple[Procedure]:
8489
"""Fetch all ISO C expressible procedures available in the Standard."""
8590

8691
return tuple(
87-
procedure for procedure in PROCEDURES.values() if procedure.express.iso_c is not None
92+
procedure
93+
for procedure in PROCEDURES.values()
94+
if procedure.express.iso_c is not None
8895
)
8996

9097

@@ -93,7 +100,9 @@ def all_f08_procedures() -> Tuple[Procedure]:
93100
"""Fetch all F08 expressible procedures available in the Standard."""
94101

95102
return tuple(
96-
procedure for procedure in PROCEDURES.values() if procedure.express.f08 is not None
103+
procedure
104+
for procedure in PROCEDURES.values()
105+
if procedure.express.f08 is not None
97106
)
98107

99108

@@ -102,7 +111,9 @@ def all_f90_procedures() -> Tuple[Procedure]:
102111
"""Fetch all F90 expressible procedures available in the Standard."""
103112

104113
return tuple(
105-
procedure for procedure in PROCEDURES.values() if procedure.express.f90 is not None
114+
procedure
115+
for procedure in PROCEDURES.values()
116+
if procedure.express.f90 is not None
106117
)
107118

108119

@@ -131,18 +142,15 @@ def _resolve_path(given_path: Union[str, Path] = None) -> Path:
131142
elif "MPISTANDARD" in os.environ:
132143
path = Path(os.environ["MPISTANDARD"] + "/apis.json")
133144

134-
elif "MPI_STANDARD" in os.environ:
135-
path = Path(os.environ["MPI_STANDARD"] + "/apis.json")
136-
137-
# use current working directory
138-
elif (Path.cwd() / "apis.json").exists():
139-
path = Path.cwd() / "apis.json"
145+
# else:
146+
# raise RuntimeError(
147+
# "Could not find apis.json, either use MPISTANDARD environment variable"
148+
# "or execute pympistandard from root of MPI Standard direction."
149+
# )
140150

141151
else:
142-
raise RuntimeError(
143-
"Could not find apis.json, either use MPISTANDARD environment variable"
144-
"or execute pympistandard from root of MPI Standard direction."
145-
)
152+
# fallback to packaged data
153+
path = importlib.resources.files("pympistandard.data").joinpath("apis.json")
146154

147155
# require resolved path to exist
148156
path.resolve(True)

src/pympistandard/data/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)