Skip to content

Commit 2bc19d8

Browse files
committed
okay maybe working now
1 parent f4d5d41 commit 2bc19d8

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

.github/workflows/pylint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
- name: Install esmpy (From ESMF repo)
8989
env:
9090
ESMFMKFILE: ${{ env.ESMFMKFILE }}
91-
ESMF_ROOT: ${{ env.ESMF_ROOT }}
91+
ESMF_ROOT: ${{ env.ESMF_ROOT }}
9292
LD_LIBRARY_PATH: ${{ env.ESMF_INSTALL_PREFIX }}/lib:${{ env.LD_LIBRARY_PATH }}
9393
run: |
9494
poetry run python -m pip --no-build-isolation --no-deps \

cmip7_prep/cmor_writer.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
from contextlib import AbstractContextManager, contextmanager
1111
from pathlib import Path
12+
import json
13+
import tempfile
1214
import re
1315
import types
1416
import warnings
@@ -477,9 +479,15 @@ def __enter__(self) -> "CmorSession":
477479
# caller passed a context manager directly
478480
self._dataset_json_cm = dj
479481
p = dj.__enter__() # ← ENTER the CM, get a Path
480-
cmor.dataset_json(str(p))
481-
cmor.set_cur_dataset_attribute("outpath", str(self._outdir))
482-
print(f"outpath set to {self._outdir}")
482+
483+
with open(p, encoding="utf-8") as f:
484+
cfg = json.load(f)
485+
cfg["outpath"] = str(self._outdir)
486+
tmp = tempfile.NamedTemporaryFile("w", suffix=".json", delete=False)
487+
json.dump(cfg, tmp)
488+
tmp.close()
489+
cmor.dataset_json(str(tmp.name))
490+
483491
try:
484492
prod = cmor.get_cur_dataset_attribute("product") # type: ignore[attr-defined]
485493
except Exception: # pylint: disable=broad-except
@@ -794,6 +802,7 @@ def write_variable(
794802
nt = 0
795803

796804
# ---- Main variable write ----
805+
797806
cmor.write(
798807
var_id,
799808
np.asarray(data_filled),
@@ -818,9 +827,8 @@ def write_variable(
818827
else:
819828
cmor.write(ps_id, np.asarray(ps_filled), store_with=var_id)
820829
self._pending_ps = None
821-
outdir = Path(cmor.get_cur_dataset_attribute("outpath"))
822-
outfile = outdir / f"{getattr(vdef, 'name', varname)}.nc"
823-
cmor.close(var_id, file_name=str(outfile))
830+
831+
cmor.close(var_id)
824832

825833
def write_variables(
826834
self,

0 commit comments

Comments
 (0)