Skip to content

Commit

Permalink
feat: extend and rename validation result properties
Browse files Browse the repository at this point in the history
BREAKING CHANGE: we renamed .bids_version to more generic .standard + .standard_version
  • Loading branch information
yarikoptic committed Oct 18, 2024
1 parent 6aa414c commit 62695d6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
2 changes: 1 addition & 1 deletion dandi/files/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _validate(self) -> None:
self._asset_metadata[bids_path] = prepare_metadata(
result.metadata
)
self._bids_version = result.origin.bids_version
self._bids_version = result.origin.standard_version

def get_asset_errors(self, asset: BIDSAsset) -> list[ValidationResult]:
""":meta private:"""
Expand Down
32 changes: 19 additions & 13 deletions dandi/files/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import requests
from zarr_checksum.tree import ZarrChecksumTree

from dandi import get_logger
from dandi import __version__, get_logger
from dandi.consts import (
MAX_ZARR_DEPTH,
ZARR_DELETE_BATCH_SIZE,
Expand Down Expand Up @@ -209,17 +209,20 @@ def get_validation_errors(
import zarr

errors: list[ValidationResult] = []
origin: ValidationOrigin = ValidationOrigin(
name="zarr",
version=zarr.__version__,
standard="zarr",
)

try:
data = zarr.open(str(self.filepath))
except Exception:
if devel_debug:
raise
errors.append(
ValidationResult(
origin=ValidationOrigin(
name="zarr",
version=zarr.version.version,
),
origin=origin,
severity=Severity.ERROR,
id="zarr.cannot_open",
scope=Scope.FILE,
Expand All @@ -228,13 +231,19 @@ def get_validation_errors(
)
)
data = None

origin = ValidationOrigin(
name="dandi.zarr",
version=__version__,
standard="zarr",
)
# if data:
# TODO: figure out how to assign standard_version
# origin.standard_version = data.???
if isinstance(data, zarr.Group) and not data:
errors.append(
ValidationResult(
origin=ValidationOrigin(
name="zarr",
version=zarr.version.version,
),
origin=origin,
severity=Severity.ERROR,
id="zarr.empty_group",
scope=Scope.FILE,
Expand All @@ -248,10 +257,7 @@ def get_validation_errors(
raise ValueError(msg)
errors.append(
ValidationResult(
origin=ValidationOrigin(
name="zarr",
version=zarr.version.version,
),
origin=origin,
severity=Severity.ERROR,
id="zarr.tree_depth_exceeded",
scope=Scope.FILE,
Expand Down
3 changes: 2 additions & 1 deletion dandi/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def validate_bids(
origin = ValidationOrigin(
name="bidsschematools",
version=bidsschematools.__version__,
bids_version=validation_result["bids_version"],
standard="bids",
standard_version=validation_result["bids_version"],
)

# Storing variable to not re-compute set paths for each individual file.
Expand Down
28 changes: 22 additions & 6 deletions dandi/validate_types.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
from __future__ import annotations

from dataclasses import dataclass
from enum import Enum
from enum import Enum, IntEnum
from pathlib import Path
from typing import Any


@dataclass
class ValidationOrigin:
name: str
version: str
bids_version: str | None = None
standard: str | None = None # TODO: Enum for the standards??
standard_version: str | None = None


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


class Scope(Enum):
FILE = "file"
FOLDER = "folder"
# Isaac: make it/add "dandiset-metadata" to signal specific relation to metadata
DANDISET = "dandiset"
DATASET = "dataset"


# new/unused, may be should be gone
class ValidationObject(Enum):
METADATA = "metadata"
DATA = "data" # e.g. actual data contained in files, not metadata (e.g. as in
# nwb or nifti header)
FILE = "file" # e.g. file itself, e.g. truncated file or file not matching checksum


@dataclass
class ValidationResult:
id: str
origin: ValidationOrigin
origin: ValidationOrigin # metadata about underlying validator and standard
scope: Scope
origin_result: Any | None = None # original validation result from "origin"
object: ValidationObject | None = None
severity: Severity | None = None
# asset_paths, if not populated, assumes [.path], but could be smth like
# {"path": "task-broken_bold.json",
Expand Down

0 comments on commit 62695d6

Please sign in to comment.