Skip to content

Commit 5ba77c6

Browse files
committed
back out to v8.8.1 of ESMF
1 parent 73e8adc commit 5ba77c6

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

.github/workflows/pylint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
ESMF_NETCDF: nc-config
7676
ESMF_INSTALL_PREFIX: $HOME/ESMF
7777
with:
78-
version: latest
78+
version: v8.8.1
7979
esmpy: true
8080
- name: Show ESMF info
8181
run: |

cmip7_prep/cmor_writer.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
`cmor_dataset.json` living under `cmip7_prep/data/`.
88
"""
99

10-
from contextlib import AbstractContextManager
10+
from contextlib import AbstractContextManager, contextmanager
1111
from pathlib import Path
1212
import re
1313
from importlib.resources import files as ir_files, as_file
@@ -23,6 +23,26 @@
2323
_UUID_RE = re.compile(r"^[0-9a-f\-]{36}$", re.IGNORECASE)
2424

2525

26+
@contextmanager
27+
def _as_path_cm(obj):
28+
"""
29+
Yield a Path whether `obj` is already a path-like or a context manager
30+
(e.g., importlib.resources.as_file(...)).
31+
"""
32+
# already a path-like → no-op context
33+
if isinstance(obj, (str, Path)):
34+
yield Path(obj)
35+
return
36+
37+
# context manager that yields a path-like
38+
if hasattr(obj, "__enter__") and hasattr(obj, "__exit__"):
39+
with obj as p:
40+
yield Path(p)
41+
return
42+
43+
raise TypeError(f"Unsupported dataset_json object type: {type(obj)!r}")
44+
45+
2646
# ---------------------------------------------------------------------
2747
# Packaged resource helpers
2848
# ---------------------------------------------------------------------

0 commit comments

Comments
 (0)