|
45 | 45 | )
|
46 | 46 |
|
47 | 47 |
|
48 |
| -# NOTE provide itertors all_1_0, all_3_1, etc... |
49 |
| - |
50 |
| - |
51 | 48 | @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: |
53 | 50 | """Sets the Python API interface which the user expects to use."""
|
54 | 51 |
|
55 | 52 | # clean from possible prior usage
|
@@ -113,29 +110,37 @@ def _register_kinds_v1() -> None:
|
113 | 110 | KINDS[key.lower()] = item
|
114 | 111 |
|
115 | 112 |
|
116 |
| -def _resolve_path(given_path: str = None) -> Path: |
| 113 | +def _resolve_path(given_path: Union[str, Path] = None) -> Path: |
117 | 114 | """Find correct path to load apis.json from."""
|
118 | 115 |
|
119 |
| - path = Path("apis.json") |
| 116 | + # convert str path to Path |
| 117 | + if isinstance(given_path, str): |
| 118 | + given_path = Path(given_path) |
120 | 119 |
|
| 120 | + # use given path |
121 | 121 | if given_path is not None:
|
122 |
| - path = Path(given_path + "/apis.json").resolve() |
| 122 | + path = given_path / "apis.json" |
123 | 123 |
|
| 124 | + # use environment variable paths |
124 | 125 | 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") |
127 | 127 |
|
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" |
132 | 134 |
|
133 | 135 | else:
|
134 | 136 | raise RuntimeError(
|
135 | 137 | "Could not find apis.json, either use MPISTANDARD environment variable"
|
136 | 138 | "or execute pympistandard from root of MPI Standard direction."
|
137 | 139 | )
|
138 | 140 |
|
| 141 | + # require resolved path to exist |
| 142 | + path.resolve(True) |
| 143 | + |
139 | 144 | return path
|
140 | 145 |
|
141 | 146 |
|
|
0 commit comments