From 565e0bbe15c1e1ea49d75d6b3664ff31813172c1 Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Tue, 19 Dec 2023 00:06:54 -0800 Subject: [PATCH 1/5] Update nwbinspector.py --- src/nwbinspector/nwbinspector.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/nwbinspector/nwbinspector.py b/src/nwbinspector/nwbinspector.py index 33245e940..8e92aff15 100644 --- a/src/nwbinspector/nwbinspector.py +++ b/src/nwbinspector/nwbinspector.py @@ -550,18 +550,18 @@ def inspect_nwbfile( filterwarnings(action="ignore", message="No cached namespaces found in .*") filterwarnings(action="ignore", message="Ignoring cached namespace .*") - with pynwb.NWBHDF5IO(path=nwbfile_path, mode="r", load_namespaces=True, driver=driver) as io: - if not skip_validate: - validation_errors = pynwb.validate(io=io) - for validation_error in validation_errors: - yield InspectorMessage( - message=validation_error.reason, - importance=Importance.PYNWB_VALIDATION, - check_function_name=validation_error.name, - location=validation_error.location, - file_path=nwbfile_path, - ) + if not skip_validate: + validation_errors = pynwb.validate(paths=[nwbfile_path], driver=driver) + for validation_error in validation_errors: + yield InspectorMessage( + message=validation_error.reason, + importance=Importance.PYNWB_VALIDATION, + check_function_name=validation_error.name, + location=validation_error.location, + file_path=nwbfile_path, + ) + with pynwb.NWBHDF5IO(path=nwbfile_path, mode="r", load_namespaces=True, driver=driver) as io: try: nwbfile_object = robust_s3_read(command=io.read, max_retries=max_retries) for inspector_message in inspect_nwbfile_object( From 361d573481d15050062ac6fccca7d0fa82076c01 Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Tue, 19 Dec 2023 00:18:44 -0800 Subject: [PATCH 2/5] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6d676a1c..705f3f30c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ * Added `check_rate_is_not_zero` for ensuring non-zero rate value of `TimeSeries` that has more than one frame. [#389](https://github.com/NeurodataWithoutBorders/nwbinspector/issues/389) +### Fixes + +* Use cached extension namespaces when calling pynwb validate instead of just the core namespace. [#425](https://github.com/NeurodataWithoutBorders/nwbinspector/pull/425) + # v0.4.30 ### Fixes From c958cfe243f16e75dd42bd722079db82c9549e6c Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Tue, 19 Dec 2023 01:05:11 -0800 Subject: [PATCH 3/5] Update nwbinspector.py --- src/nwbinspector/nwbinspector.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/nwbinspector/nwbinspector.py b/src/nwbinspector/nwbinspector.py index 8e92aff15..e7082b366 100644 --- a/src/nwbinspector/nwbinspector.py +++ b/src/nwbinspector/nwbinspector.py @@ -551,15 +551,16 @@ def inspect_nwbfile( filterwarnings(action="ignore", message="Ignoring cached namespace .*") if not skip_validate: - validation_errors = pynwb.validate(paths=[nwbfile_path], driver=driver) - for validation_error in validation_errors: - yield InspectorMessage( - message=validation_error.reason, - importance=Importance.PYNWB_VALIDATION, - check_function_name=validation_error.name, - location=validation_error.location, - file_path=nwbfile_path, - ) + validation_error_list = pynwb.validate(paths=[nwbfile_path], driver=driver) + for validation_namespace_errors in validation_error_list: + for validation_error in validation_namespace_errors: + yield InspectorMessage( + message=validation_error.reason, + importance=Importance.PYNWB_VALIDATION, + check_function_name=validation_error.name, + location=validation_error.location, + file_path=nwbfile_path, + ) with pynwb.NWBHDF5IO(path=nwbfile_path, mode="r", load_namespaces=True, driver=driver) as io: try: From 813b407efdbc46855d3bd772045964d081cf265e Mon Sep 17 00:00:00 2001 From: rly Date: Tue, 19 Dec 2023 01:36:48 -0800 Subject: [PATCH 4/5] Fix pynwb.validate call --- src/nwbinspector/nwbinspector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nwbinspector/nwbinspector.py b/src/nwbinspector/nwbinspector.py index e7082b366..64f685431 100644 --- a/src/nwbinspector/nwbinspector.py +++ b/src/nwbinspector/nwbinspector.py @@ -551,7 +551,7 @@ def inspect_nwbfile( filterwarnings(action="ignore", message="Ignoring cached namespace .*") if not skip_validate: - validation_error_list = pynwb.validate(paths=[nwbfile_path], driver=driver) + validation_error_list, _ = pynwb.validate(paths=[nwbfile_path], driver=driver) for validation_namespace_errors in validation_error_list: for validation_error in validation_namespace_errors: yield InspectorMessage( From 984adccceeadc63f2b6d9bcc4a8c30de12162cfa Mon Sep 17 00:00:00 2001 From: rly Date: Tue, 19 Dec 2023 01:54:32 -0800 Subject: [PATCH 5/5] Make tests pass on pynwb 2.1.0 --- src/nwbinspector/nwbinspector.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/nwbinspector/nwbinspector.py b/src/nwbinspector/nwbinspector.py index 64f685431..010040ccd 100644 --- a/src/nwbinspector/nwbinspector.py +++ b/src/nwbinspector/nwbinspector.py @@ -13,6 +13,7 @@ from warnings import filterwarnings, warn from distutils.util import strtobool from collections import defaultdict +from packaging.version import Version import click import pynwb @@ -29,7 +30,14 @@ ) from .register_checks import InspectorMessage, Importance from .tools import get_s3_urls_and_dandi_paths -from .utils import FilePathType, PathType, OptionalListOfStrings, robust_s3_read, calculate_number_of_cpu +from .utils import ( + FilePathType, + PathType, + OptionalListOfStrings, + robust_s3_read, + calculate_number_of_cpu, + get_package_version, +) from nwbinspector import __version__ INTERNAL_CONFIGS = dict(dandi=Path(__file__).parent / "internal_configs" / "dandi.inspector_config.yaml") @@ -550,7 +558,7 @@ def inspect_nwbfile( filterwarnings(action="ignore", message="No cached namespaces found in .*") filterwarnings(action="ignore", message="Ignoring cached namespace .*") - if not skip_validate: + if not skip_validate and get_package_version("pynwb") >= Version("2.2.0"): validation_error_list, _ = pynwb.validate(paths=[nwbfile_path], driver=driver) for validation_namespace_errors in validation_error_list: for validation_error in validation_namespace_errors: @@ -563,6 +571,17 @@ def inspect_nwbfile( ) with pynwb.NWBHDF5IO(path=nwbfile_path, mode="r", load_namespaces=True, driver=driver) as io: + if not skip_validate and get_package_version("pynwb") < Version("2.2.0"): + validation_errors = pynwb.validate(io=io) + for validation_error in validation_errors: + yield InspectorMessage( + message=validation_error.reason, + importance=Importance.PYNWB_VALIDATION, + check_function_name=validation_error.name, + location=validation_error.location, + file_path=nwbfile_path, + ) + try: nwbfile_object = robust_s3_read(command=io.read, max_retries=max_retries) for inspector_message in inspect_nwbfile_object(