10
10
11
11
12
12
from pathlib import Path
13
+ import importlib .resources
13
14
import json
14
15
from enum import Enum
15
16
from typing import Union , Tuple
@@ -54,7 +55,9 @@ def unload() -> None:
54
55
55
56
# TODO rename to load(api_version, mpi_version, path)
56
57
@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 :
58
61
"""Sets the Python API interface which the user expects to use."""
59
62
60
63
unload ()
@@ -75,7 +78,9 @@ def all_lis_procedures() -> Tuple[Procedure]:
75
78
"""Fetch all LIS expressible procedures available in the Standard."""
76
79
77
80
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
79
84
)
80
85
81
86
@@ -84,7 +89,9 @@ def all_iso_c_procedures() -> Tuple[Procedure]:
84
89
"""Fetch all ISO C expressible procedures available in the Standard."""
85
90
86
91
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
88
95
)
89
96
90
97
@@ -93,7 +100,9 @@ def all_f08_procedures() -> Tuple[Procedure]:
93
100
"""Fetch all F08 expressible procedures available in the Standard."""
94
101
95
102
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
97
106
)
98
107
99
108
@@ -102,7 +111,9 @@ def all_f90_procedures() -> Tuple[Procedure]:
102
111
"""Fetch all F90 expressible procedures available in the Standard."""
103
112
104
113
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
106
117
)
107
118
108
119
@@ -131,18 +142,15 @@ def _resolve_path(given_path: Union[str, Path] = None) -> Path:
131
142
elif "MPISTANDARD" in os .environ :
132
143
path = Path (os .environ ["MPISTANDARD" ] + "/apis.json" )
133
144
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
+ # )
140
150
141
151
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" )
146
154
147
155
# require resolved path to exist
148
156
path .resolve (True )
0 commit comments