From 8dba0108b8e8e0aee219d7cfff38caf880de5a3d Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 12 Sep 2024 20:36:59 -0400 Subject: [PATCH] Fix comparison but also make caching optional depending on either original file had it --- dandi/pynwb_utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dandi/pynwb_utils.py b/dandi/pynwb_utils.py index 92e3d4a9b..e280c6ab7 100644 --- a/dandi/pynwb_utils.py +++ b/dandi/pynwb_utils.py @@ -515,18 +515,18 @@ def copy_nwb_file(src: str | Path, dest: str | Path) -> str: dest = op.join(dest, op.basename(src)) else: os.makedirs(op.dirname(dest), exist_ok=True) + kws = {} + if Version(pynwb.__version__) >= Version("2.8.2"): + # we might make it leaner by not caching the spec if original + # file did not have it. Possible only since 2.8.2.dev11 + kws["cache_spec"] = bool(pynwb.NWBHDF5IO.get_namespaces(src)) with pynwb.NWBHDF5IO(src, "r") as ior, pynwb.NWBHDF5IO(dest, "w") as iow: data = ior.read() data.generate_new_id() iow.export( ior, nwbfile=data, - # do not export spec since - **( - {"cache_spec": False} - if Version(pynwb.__version__) > Version("2.8.2") - else {} - ), + **kws, ) return str(dest)