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

BF: convert str errors from checking nwb version into proper ValidationResult #1174

Merged
merged 1 commit into from
Dec 14, 2022
Merged
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
26 changes: 22 additions & 4 deletions dandi/pynwb_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from collections import Counter
import os
import os.path as op
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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] = []
yarikoptic marked this conversation as resolved.
Show resolved Hide resolved
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:
Expand Down