-
Notifications
You must be signed in to change notification settings - Fork 33
Overhauling validation results to get them closer to cover different types of validators #1514
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
666b8f4
feat: improve `ValidationResult`
yarikoptic 5240543
fix: add `eval_type_backport` dependency
candleindark 5c12e8b
fix: avoid catching unexpected errors in NWB validation
candleindark 3b31ee7
Merge branch 'master' into ext-validation
candleindark 699005d
rf: define and reuse some common `origin` objects
candleindark cf401cd
fix: relabel validation result of Zarr data by `dandi-cli` itself
candleindark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,11 +42,47 @@ | |
| ) | ||
|
|
||
| from .bases import LocalDirectoryAsset | ||
| from ..validate_types import Scope, Severity, ValidationOrigin, ValidationResult | ||
| from ..validate_types import ( | ||
| ORIGIN_VALIDATION_DANDI_ZARR, | ||
| Origin, | ||
| OriginType, | ||
| Scope, | ||
| Severity, | ||
| Standard, | ||
| ValidationResult, | ||
| Validator, | ||
| ) | ||
|
|
||
| lgr = get_logger() | ||
|
|
||
|
|
||
| def get_zarr_format_version(data: Any) -> str: | ||
| """ | ||
| Get the Zarr storage specification version from a Zarr data object | ||
|
|
||
| Parameters | ||
| ---------- | ||
| data : zarr.core.Array or zarr.hierarchy.Group | ||
| The Zarr data object from which to extract the storage specification version | ||
|
|
||
| Returns | ||
| ------- | ||
| str | ||
| The Zarr storage specification version, | ||
| https://zarr-specs.readthedocs.io/en/latest/specs.html, used in the Zarr data | ||
| object | ||
| """ | ||
| import zarr # Delay heavy import | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm, apparently we have no single test on validation of zarrs? that's odd :-/ filed dedicated for that |
||
|
|
||
| if isinstance(data, zarr.Group): | ||
| meta = json.loads(data.store.get(".zgroup")) | ||
| elif isinstance(data, zarr.Array): | ||
| meta = json.loads(data.store.get(".zarray")) | ||
| else: | ||
| raise TypeError("`data` must be a `zarr.core.Array` or `zarr.hierarchy.Group`") | ||
| return str(meta["zarr_format"]) | ||
yarikoptic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @dataclass | ||
| class LocalZarrEntry(BasePath): | ||
| """A file or directory within a `ZarrAsset`""" | ||
|
|
@@ -209,34 +245,37 @@ | |
| import zarr | ||
|
|
||
| errors: list[ValidationResult] = [] | ||
| origin_internal_zarr: Origin = Origin( | ||
| type=OriginType.INTERNAL, | ||
| validator=Validator.zarr, | ||
| validator_version=zarr.__version__, | ||
| standard=Standard.ZARR, | ||
| ) | ||
|
|
||
| try: | ||
| data = zarr.open(str(self.filepath)) | ||
candleindark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| except Exception: | ||
| except Exception as e: | ||
| if devel_debug: | ||
| raise | ||
| errors.append( | ||
| ValidationResult( | ||
| origin=ValidationOrigin( | ||
| name="zarr", | ||
| version=zarr.version.version, | ||
| ), | ||
| origin=origin_internal_zarr, | ||
| severity=Severity.ERROR, | ||
| id="zarr.cannot_open", | ||
| scope=Scope.FILE, | ||
| origin_result=e, | ||
candleindark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| path=self.filepath, | ||
| message="Error opening file.", | ||
| ) | ||
| ) | ||
| data = None | ||
|
|
||
| if isinstance(data, zarr.Group) and not data: | ||
| errors.append( | ||
| ValidationResult( | ||
| origin=ValidationOrigin( | ||
| name="zarr", | ||
| version=zarr.version.version, | ||
| ), | ||
| origin=ORIGIN_VALIDATION_DANDI_ZARR, | ||
| severity=Severity.ERROR, | ||
| id="zarr.empty_group", | ||
| id="dandi_zarr.empty_group", | ||
| scope=Scope.FILE, | ||
| path=self.filepath, | ||
| message="Zarr group is empty.", | ||
|
|
@@ -248,12 +287,9 @@ | |
| raise ValueError(msg) | ||
| errors.append( | ||
| ValidationResult( | ||
| origin=ValidationOrigin( | ||
| name="zarr", | ||
| version=zarr.version.version, | ||
| ), | ||
| origin=ORIGIN_VALIDATION_DANDI_ZARR, | ||
| severity=Severity.ERROR, | ||
| id="zarr.tree_depth_exceeded", | ||
| id="dandi_zarr.tree_depth_exceeded", | ||
| scope=Scope.FILE, | ||
| path=self.filepath, | ||
| message=msg, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.