Skip to content

Commit 62695d6

Browse files
committed
feat: extend and rename validation result properties
BREAKING CHANGE: we renamed .bids_version to more generic .standard + .standard_version
1 parent 6aa414c commit 62695d6

File tree

4 files changed

+44
-21
lines changed

4 files changed

+44
-21
lines changed

dandi/files/bids.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def _validate(self) -> None:
111111
self._asset_metadata[bids_path] = prepare_metadata(
112112
result.metadata
113113
)
114-
self._bids_version = result.origin.bids_version
114+
self._bids_version = result.origin.standard_version
115115

116116
def get_asset_errors(self, asset: BIDSAsset) -> list[ValidationResult]:
117117
""":meta private:"""

dandi/files/zarr.py

+19-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import requests
1717
from zarr_checksum.tree import ZarrChecksumTree
1818

19-
from dandi import get_logger
19+
from dandi import __version__, get_logger
2020
from dandi.consts import (
2121
MAX_ZARR_DEPTH,
2222
ZARR_DELETE_BATCH_SIZE,
@@ -209,17 +209,20 @@ def get_validation_errors(
209209
import zarr
210210

211211
errors: list[ValidationResult] = []
212+
origin: ValidationOrigin = ValidationOrigin(
213+
name="zarr",
214+
version=zarr.__version__,
215+
standard="zarr",
216+
)
217+
212218
try:
213219
data = zarr.open(str(self.filepath))
214220
except Exception:
215221
if devel_debug:
216222
raise
217223
errors.append(
218224
ValidationResult(
219-
origin=ValidationOrigin(
220-
name="zarr",
221-
version=zarr.version.version,
222-
),
225+
origin=origin,
223226
severity=Severity.ERROR,
224227
id="zarr.cannot_open",
225228
scope=Scope.FILE,
@@ -228,13 +231,19 @@ def get_validation_errors(
228231
)
229232
)
230233
data = None
234+
235+
origin = ValidationOrigin(
236+
name="dandi.zarr",
237+
version=__version__,
238+
standard="zarr",
239+
)
240+
# if data:
241+
# TODO: figure out how to assign standard_version
242+
# origin.standard_version = data.???
231243
if isinstance(data, zarr.Group) and not data:
232244
errors.append(
233245
ValidationResult(
234-
origin=ValidationOrigin(
235-
name="zarr",
236-
version=zarr.version.version,
237-
),
246+
origin=origin,
238247
severity=Severity.ERROR,
239248
id="zarr.empty_group",
240249
scope=Scope.FILE,
@@ -248,10 +257,7 @@ def get_validation_errors(
248257
raise ValueError(msg)
249258
errors.append(
250259
ValidationResult(
251-
origin=ValidationOrigin(
252-
name="zarr",
253-
version=zarr.version.version,
254-
),
260+
origin=origin,
255261
severity=Severity.ERROR,
256262
id="zarr.tree_depth_exceeded",
257263
scope=Scope.FILE,

dandi/validate.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def validate_bids(
4949
origin = ValidationOrigin(
5050
name="bidsschematools",
5151
version=bidsschematools.__version__,
52-
bids_version=validation_result["bids_version"],
52+
standard="bids",
53+
standard_version=validation_result["bids_version"],
5354
)
5455

5556
# Storing variable to not re-compute set paths for each individual file.

dandi/validate_types.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,51 @@
11
from __future__ import annotations
22

33
from dataclasses import dataclass
4-
from enum import Enum
4+
from enum import Enum, IntEnum
55
from pathlib import Path
6+
from typing import Any
67

78

89
@dataclass
910
class ValidationOrigin:
1011
name: str
1112
version: str
12-
bids_version: str | None = None
13+
standard: str | None = None # TODO: Enum for the standards??
14+
standard_version: str | None = None
1315

1416

15-
class Severity(Enum):
17+
# TODO: decide on the naming consistency -- either prepend all with Validation or not
18+
class Severity(IntEnum):
1619
HINT = 1
17-
WARNING = 2
18-
ERROR = 3
20+
INFO = 2 # new/unused, available in linkml
21+
WARNING = 3
22+
ERROR = 4
23+
CRITICAL = 5 # new/unused, linkml has FATAL
1924

2025

2126
class Scope(Enum):
2227
FILE = "file"
2328
FOLDER = "folder"
29+
# Isaac: make it/add "dandiset-metadata" to signal specific relation to metadata
2430
DANDISET = "dandiset"
2531
DATASET = "dataset"
2632

2733

34+
# new/unused, may be should be gone
35+
class ValidationObject(Enum):
36+
METADATA = "metadata"
37+
DATA = "data" # e.g. actual data contained in files, not metadata (e.g. as in
38+
# nwb or nifti header)
39+
FILE = "file" # e.g. file itself, e.g. truncated file or file not matching checksum
40+
41+
2842
@dataclass
2943
class ValidationResult:
3044
id: str
31-
origin: ValidationOrigin
45+
origin: ValidationOrigin # metadata about underlying validator and standard
3246
scope: Scope
47+
origin_result: Any | None = None # original validation result from "origin"
48+
object: ValidationObject | None = None
3349
severity: Severity | None = None
3450
# asset_paths, if not populated, assumes [.path], but could be smth like
3551
# {"path": "task-broken_bold.json",

0 commit comments

Comments
 (0)