Skip to content

Commit 637faef

Browse files
authored
Merge branch 'master' into introduce-hatch-envs
2 parents 6b56e02 + f14c1ee commit 637faef

16 files changed

Lines changed: 125 additions & 62 deletions

File tree

dandi/bids_validator_deno/_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from pydantic import DirectoryPath, validate_call
1414

1515
from dandi.utils import find_parent_directory_containing
16-
from dandi.validate_types import (
16+
from dandi.validate.types import (
1717
Origin,
1818
OriginType,
1919
Scope,

dandi/cli/cmd_validate.py

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from collections.abc import Iterable
43
import logging
54
import os
65
import re
@@ -11,8 +10,59 @@
1110

1211
from .base import devel_debug_option, devel_option, map_to_click_exceptions
1312
from ..utils import pluralize
14-
from ..validate import validate as validate_
15-
from ..validate_types import Severity, ValidationResult
13+
from ..validate.core import validate as validate_
14+
from ..validate.types import Severity, ValidationResult
15+
16+
17+
def _collect_results(
18+
paths: tuple[str, ...],
19+
schema: str | None,
20+
devel_debug: bool,
21+
allow_any_path: bool,
22+
) -> list[ValidationResult]:
23+
"""Run validation and collect all results into a list."""
24+
# Avoid heavy import by importing within function:
25+
from ..pynwb_utils import ignore_benign_pynwb_warnings
26+
27+
# Don't log validation warnings, as this command reports them to the user
28+
# anyway:
29+
root = logging.getLogger()
30+
for h in root.handlers:
31+
h.addFilter(lambda r: not getattr(r, "validating", False))
32+
33+
if not paths:
34+
paths = (os.curdir,)
35+
# below we are using load_namespaces but it causes HDMF to whine if there
36+
# is no cached name spaces in the file. It is benign but not really useful
37+
# at this point, so we ignore it although ideally there should be a formal
38+
# way to get relevant warnings (not errors) from PyNWB
39+
ignore_benign_pynwb_warnings()
40+
41+
return list(
42+
validate_(
43+
*paths,
44+
schema_version=schema,
45+
devel_debug=devel_debug,
46+
allow_any_path=allow_any_path,
47+
)
48+
)
49+
50+
51+
def _filter_results(
52+
results: list[ValidationResult],
53+
min_severity: str,
54+
ignore: str | None,
55+
) -> list[ValidationResult]:
56+
"""Filter results by minimum severity and ignore pattern."""
57+
min_severity_value = Severity[min_severity].value
58+
filtered = [
59+
r
60+
for r in results
61+
if r.severity is not None and r.severity.value >= min_severity_value
62+
]
63+
if ignore is not None:
64+
filtered = [r for r in filtered if not re.search(ignore, r.id)]
65+
return filtered
1666

1767

1868
@click.command()
@@ -102,49 +152,15 @@ def validate(
102152
103153
Exits with non-0 exit code if any file is not compliant.
104154
"""
105-
# Avoid heavy import by importing within function:
106-
from ..pynwb_utils import ignore_benign_pynwb_warnings
107-
108-
# Don't log validation warnings, as this command reports them to the user
109-
# anyway:
110-
root = logging.getLogger()
111-
for h in root.handlers:
112-
h.addFilter(lambda r: not getattr(r, "validating", False))
113-
114-
if not paths:
115-
paths = (os.curdir,)
116-
# below we are using load_namespaces but it causes HDMF to whine if there
117-
# is no cached name spaces in the file. It is benign but not really useful
118-
# at this point, so we ignore it although ideally there should be a formal
119-
# way to get relevant warnings (not errors) from PyNWB
120-
ignore_benign_pynwb_warnings()
121-
122-
validator_result = validate_(
123-
*paths,
124-
schema_version=schema,
125-
devel_debug=devel_debug,
126-
allow_any_path=allow_any_path,
127-
)
128-
129-
min_severity_value = Severity[min_severity].value
130-
131-
filtered_results = [
132-
i
133-
for i in validator_result
134-
if i.severity is not None and i.severity.value >= min_severity_value
135-
]
136-
137-
_process_issues(filtered_results, grouping, ignore)
155+
results = _collect_results(paths, schema, devel_debug, allow_any_path)
156+
filtered = _filter_results(results, min_severity, ignore)
157+
_process_issues(filtered, grouping)
138158

139159

140160
def _process_issues(
141-
validator_result: Iterable[ValidationResult],
161+
issues: list[ValidationResult],
142162
grouping: str,
143-
ignore: str | None = None,
144163
) -> None:
145-
issues = [i for i in validator_result if i.severity is not None]
146-
if ignore is not None:
147-
issues = [i for i in issues if not re.search(ignore, i.id)]
148164
purviews = [i.purview for i in issues]
149165
if grouping == "none":
150166
display_errors(

dandi/cli/tests/test_cmd_validate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from ..cmd_validate import _process_issues, validate
77
from ...tests.xfail import mark_xfail_windows_python313_posixsubprocess
8-
from ...validate_types import (
8+
from ...validate.types import (
99
Origin,
1010
OriginType,
1111
Scope,

dandi/files/bases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from dandi.metadata.core import get_default_metadata
3030
from dandi.misctypes import DUMMY_DANDI_ETAG, Digest, LocalReadableFile, P
3131
from dandi.utils import post_upload_size_check, pre_upload_size_check, yaml_load
32-
from dandi.validate_types import (
32+
from dandi.validate.types import (
3333
ORIGIN_INTERNAL_DANDI,
3434
ORIGIN_VALIDATION_DANDI,
3535
Origin,

dandi/files/bids.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ..consts import ZARR_MIME_TYPE, dandiset_metadata_file
1717
from ..metadata.core import add_common_metadata, prepare_metadata
1818
from ..misctypes import Digest
19-
from ..validate_types import (
19+
from ..validate.types import (
2020
ORIGIN_VALIDATION_DANDI_LAYOUT,
2121
Scope,
2222
Severity,
@@ -92,7 +92,7 @@ def _get_metadata(self) -> None:
9292
with self._lock:
9393
if self._asset_metadata is None:
9494
# Import here to avoid circular import
95-
from dandi.validate import validate_bids
95+
from dandi.validate.core import validate_bids
9696

9797
# === Validate the dataset using bidsschematools ===
9898
# This is done to obtain the metadata for each asset in the dataset

dandi/files/zarr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
import json
1111
import os
1212
import os.path
13-
import urllib.parse
1413
from pathlib import Path
1514
from time import sleep
1615
from typing import Any, Optional
16+
import urllib.parse
1717

1818
from dandischema.models import BareAsset, DigestType
1919
from pydantic import BaseModel, ConfigDict, ValidationError
@@ -47,7 +47,7 @@
4747
)
4848

4949
from .bases import LocalDirectoryAsset
50-
from ..validate_types import (
50+
from ..validate.types import (
5151
ORIGIN_VALIDATION_DANDI_ZARR,
5252
Origin,
5353
OriginType,

dandi/organize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
pluralize,
4444
yaml_load,
4545
)
46-
from .validate_types import (
46+
from .validate.types import (
4747
ORIGIN_VALIDATION_DANDI_LAYOUT,
4848
Scope,
4949
Severity,

dandi/pynwb_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
)
4343
from .misctypes import Readable
4444
from .utils import get_module_version, is_url
45-
from .validate_types import (
45+
from .validate.types import (
4646
Origin,
4747
OriginType,
4848
Scope,

dandi/tests/test_bids_validator_deno/test_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
)
2828
from dandi.consts import dandiset_metadata_file
2929
from dandi.tests.fixtures import BIDS_TESTDATA_SELECTION
30-
from dandi.validate_types import (
30+
from dandi.validate.types import (
3131
OriginType,
3232
Scope,
3333
Severity,

dandi/upload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from .support import pyout as pyouts
5050
from .support.pyout import naturalsize
5151
from .utils import ensure_datetime, path_is_subpath, pluralize
52-
from .validate_types import Severity
52+
from .validate.types import Severity
5353

5454

5555
def _check_dandidownload_paths(dfile: DandiFile) -> None:

0 commit comments

Comments
 (0)