Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions dandi/tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ def mock_bids_validate(*args: Any, **kwargs: Any) -> list[ValidationResult]:
f"BIDS specification."
)

# Check that there is also a HINT about .bidsignore
validation_hints = [
r
for r in validation_results
if r.severity is not None and r.severity == Severity.HINT
]

# Assert that there is at least one hint
assert len(validation_hints) >= 1

# Find the hint about .bidsignore for dandiset.yaml
bidsignore_hint = next(
(h for h in validation_hints if h.id == "DANDI.BIDSIGNORE_DANDISET_YAML"),
None,
)
assert bidsignore_hint is not None
assert bidsignore_hint.message is not None
assert ".bidsignore" in bidsignore_hint.message
assert dandiset_metadata_file in bidsignore_hint.message


def test_validate_bids_onefile(bids_error_examples: Path, tmp_path: Path) -> None:
"""
Expand Down
26 changes: 24 additions & 2 deletions dandi/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,14 @@ def validate(
if r_id not in df_result_ids:
# If the error is about the dandiset metadata file, modify
# the message in the validation to give the context of DANDI
if (
# and add a HINT to suggest adding to .bidsignore
is_dandiset_yaml_error = (
r.path is not None
and r.dataset_path is not None
and r.path.relative_to(r.dataset_path).as_posix()
== dandiset_metadata_file
):
)
if is_dandiset_yaml_error:
r.message = (
f"The dandiset metadata file, `{dandiset_metadata_file}`, "
f"is not a part of BIDS specification. Please include a "
Expand All @@ -205,3 +207,23 @@ def validate(
df_results.append(r)
df_result_ids.add(r_id)
yield r

# After yielding the error for dandiset.yaml, also yield a HINT
if is_dandiset_yaml_error:
hint = ValidationResult(
id="DANDI.BIDSIGNORE_DANDISET_YAML",
origin=ORIGIN_VALIDATION_DANDI_LAYOUT,
severity=Severity.HINT,
scope=Scope.DATASET,
path=r.dataset_path,
dataset_path=r.dataset_path,
dandiset_path=dandiset_path,
message=(
f"Consider creating or updating a `.bidsignore` file "
f"in the root of your BIDS dataset to ignore "
f"`{dandiset_metadata_file}`. "
f"Add the following line to `.bidsignore`:\n"
f"{dandiset_metadata_file}"
),
)
Comment on lines +213 to +228
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hint = ValidationResult(
id="DANDI.BIDSIGNORE_DANDISET_YAML",
origin=ORIGIN_VALIDATION_DANDI_LAYOUT,
severity=Severity.HINT,
scope=Scope.DATASET,
path=r.dataset_path,
dataset_path=r.dataset_path,
dandiset_path=dandiset_path,
message=(
f"Consider creating or updating a `.bidsignore` file "
f"in the root of your BIDS dataset to ignore "
f"`{dandiset_metadata_file}`. "
f"Add the following line to `.bidsignore`:\n"
f"{dandiset_metadata_file}"
),
)
hint = ValidationResult(
id="DANDI.BIDSIGNORE_DANDISET_YAML",
origin=ORIGIN_VALIDATION_DANDI_LAYOUT,
scope=Scope.DATASET,
origin_result=r,
severity=Severity.HINT,
dandiset_path=r.dandiset_path,
dataset_path=r.dataset_path,
path=r.path,
message=(
f"Consider creating or updating a `.bidsignore` file "
f"in the root of your BIDS dataset to ignore "
f"`{dandiset_metadata_file}`. "
f"Add the following line to `.bidsignore`:\n"
f"{dandiset_metadata_file}"
),
)

yield hint
Loading