Skip to content

Commit e694e32

Browse files
author
Martin Ruefenacht
committed
Cleaned up path resolution
1 parent ce05fcd commit e694e32

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/pympistandard/__init__.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,8 @@
4545
)
4646

4747

48-
# NOTE provide itertors all_1_0, all_3_1, etc...
49-
50-
5148
@export
52-
def use_api_version(version: Union[int, str] = "LATEST", given_path: str = None) -> None:
49+
def use_api_version(version: Union[int, str] = "LATEST", given_path: Union[str, Path] = None) -> None:
5350
"""Sets the Python API interface which the user expects to use."""
5451

5552
# clean from possible prior usage
@@ -113,29 +110,37 @@ def _register_kinds_v1() -> None:
113110
KINDS[key.lower()] = item
114111

115112

116-
def _resolve_path(given_path: str = None) -> Path:
113+
def _resolve_path(given_path: Union[str, Path] = None) -> Path:
117114
"""Find correct path to load apis.json from."""
118115

119-
path = Path("apis.json")
116+
# convert str path to Path
117+
if isinstance(given_path, str):
118+
given_path = Path(given_path)
120119

120+
# use given path
121121
if given_path is not None:
122-
path = Path(given_path + "/apis.json").resolve()
122+
path = given_path / "apis.json"
123123

124+
# use environment variable paths
124125
elif "MPISTANDARD" in os.environ:
125-
path = Path(os.environ["MPISTANDARD"] + "/apis.json").resolve()
126-
print(path)
126+
path = Path(os.environ["MPISTANDARD"] + "/apis.json")
127127

128-
# TODO with separation from mpi_standard directory this would not be valid anymore, so remove it.
129-
elif path.exists():
130-
# load directly
131-
pass
128+
elif "MPI_STANDARD" in os.environ:
129+
path = Path(os.environ["MPI_STANDARD"] + "/apis.json")
130+
131+
# use current working directory
132+
elif (Path.cwd() / "apis.json").exists():
133+
path = Path.cwd() / "apis.json"
132134

133135
else:
134136
raise RuntimeError(
135137
"Could not find apis.json, either use MPISTANDARD environment variable"
136138
"or execute pympistandard from root of MPI Standard direction."
137139
)
138140

141+
# require resolved path to exist
142+
path.resolve(True)
143+
139144
return path
140145

141146

0 commit comments

Comments
 (0)