Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use paths instead of io in pynwb.validate call #425

Merged
merged 5 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 22 additions & 2 deletions src/nwbinspector/nwbinspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -550,8 +558,20 @@ def inspect_nwbfile(
filterwarnings(action="ignore", message="No cached namespaces found in .*")
filterwarnings(action="ignore", message="Ignoring cached namespace .*")

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:
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:
if not skip_validate:
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(
Expand Down
Loading