diff --git a/dandi/pynwb_utils.py b/dandi/pynwb_utils.py index 3d0a8b3ec..e280c6ab7 100644 --- a/dandi/pynwb_utils.py +++ b/dandi/pynwb_utils.py @@ -515,10 +515,19 @@ 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) + iow.export( + ior, + nwbfile=data, + **kws, + ) return str(dest)