From 72258b121e28612112f449c591ccfc0006b9bc08 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 14 Dec 2022 16:19:28 -0500 Subject: [PATCH] BF: convert str errors from checking nwb version into proper ValidationResult It also caused another kaboom within hdmf bubbling up through nwbinspector, filed https://github.com/NeurodataWithoutBorders/nwbinspector/issues/329 --- dandi/pynwb_utils.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/dandi/pynwb_utils.py b/dandi/pynwb_utils.py index 5a34c38fa..ca92f544e 100644 --- a/dandi/pynwb_utils.py +++ b/dandi/pynwb_utils.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from collections import Counter import os import os.path as op @@ -336,7 +338,9 @@ def validate( path = str(path) # Might come in as pathlib's PATH errors: List[ValidationResult] = [] try: - if Version(pynwb.__version__) >= Version("2.2.0"): # Use cached namespace feature + if Version(pynwb.__version__) >= Version( + "2.2.0" + ): # Use cached namespace feature # argument get_cached_namespaces is True by default error_outputs, _ = pynwb.validate(paths=[path]) else: # Fallback if an older version @@ -391,9 +395,23 @@ def validate( else: if version is not None: # Explicitly sanitize so we collect warnings. - # TODO: later cast into proper ERRORs - # Do we really need this custom internal function? string comparison works fine.. - version = _sanitize_nwb_version(version, log=errors.append) + nwb_errors: list[str] = [] + version = _sanitize_nwb_version(version, log=nwb_errors.append) + for e in nwb_errors: + errors.append( + ValidationResult( + origin=ValidationOrigin( + name="pynwb", + version=pynwb.__version__, + ), + severity=Severity.ERROR, + id="pywnb.GENERIC", + scope=Scope.FILE, + path=Path(path), + message=e, + ) + ) + # Do we really need this custom internal function? string comparison works fine. try: v = semantic_version.Version(version) except ValueError: