Skip to content

Commit 5f03d9b

Browse files
authored
Merge pull request #1819 from dandi/bids-ignore
Upload .bidsignore files as part of BIDS datasets
2 parents 0fe497d + 6caea92 commit 5f03d9b

5 files changed

Lines changed: 30 additions & 4 deletions

File tree

dandi/consts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ def urls(self) -> Iterator[str]:
201201

202202
BIDS_DATASET_DESCRIPTION = "dataset_description.json"
203203

204+
BIDS_IGNORE_FILE = ".bidsignore"
205+
204206
# Fields which would be used to compose organized filenames
205207
# TODO: add full description into command --help etc
206208
# Order matters!

dandi/files/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
from pathlib import Path
1818

1919
from dandi import get_logger
20-
from dandi.consts import BIDS_DATASET_DESCRIPTION, dandiset_metadata_file
20+
from dandi.consts import (
21+
BIDS_DATASET_DESCRIPTION,
22+
BIDS_IGNORE_FILE,
23+
dandiset_metadata_file,
24+
)
2125
from dandi.exceptions import UnknownAssetError
2226

2327
from ._private import BIDSFileFactory, DandiFileFactory
@@ -110,7 +114,9 @@ def find_dandi_files(
110114
while path_queue:
111115
p, bidsdd = path_queue.popleft()
112116
if p.name.startswith("."):
113-
continue
117+
# Allow .bidsignore files within BIDS datasets to be uploaded
118+
if not (p.name == BIDS_IGNORE_FILE and bidsdd is not None):
119+
continue
114120
if p.is_dir():
115121
if p.is_symlink():
116122
lgr.warning("%s: Ignoring unsupported symbolic link to directory", p)

dandi/tests/fixtures.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ def bids_dandiset(new_dandiset: SampleDandiset, bids_examples: Path) -> SampleDa
687687
ignore=shutil.ignore_patterns(dandiset_metadata_file),
688688
)
689689
(new_dandiset.dspath / "CHANGES").write_text("0.1.0 2014-11-03\n")
690+
(new_dandiset.dspath / ".bidsignore").write_text("dandiset.yaml\n")
690691
return new_dandiset
691692

692693

dandi/tests/test_files.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ def test_find_dandi_files_with_bids(tmp_path: Path) -> None:
179179
dandiset_metadata_file,
180180
"foo.txt",
181181
"bar.nwb",
182+
"bids1/.bidsignore",
182183
"bids1/dataset_description.json",
183184
"bids1/file.txt",
184185
"bids1/subdir/quux.nwb",
@@ -196,6 +197,12 @@ def test_find_dandi_files_with_bids(tmp_path: Path) -> None:
196197

197198
assert files == [
198199
NWBAsset(filepath=tmp_path / "bar.nwb", path="bar.nwb", dandiset_path=tmp_path),
200+
GenericBIDSAsset(
201+
filepath=tmp_path / "bids1" / ".bidsignore",
202+
path="bids1/.bidsignore",
203+
dandiset_path=tmp_path,
204+
bids_dataset_description_ref=ANY, # type: ignore[arg-type]
205+
),
199206
BIDSDatasetDescriptionAsset(
200207
filepath=tmp_path / "bids1" / "dataset_description.json",
201208
path="bids1/dataset_description.json",
@@ -246,9 +253,15 @@ def test_find_dandi_files_with_bids(tmp_path: Path) -> None:
246253
),
247254
]
248255

249-
bidsdd = files[1]
256+
bidsdd = files[2]
250257
assert isinstance(bidsdd, BIDSDatasetDescriptionAsset)
251258
assert sorted(bidsdd.dataset_files, key=attrgetter("filepath")) == [
259+
GenericBIDSAsset(
260+
filepath=tmp_path / "bids1" / ".bidsignore",
261+
path="bids1/.bidsignore",
262+
dandiset_path=tmp_path,
263+
bids_dataset_description_ref=ANY, # type: ignore[arg-type]
264+
),
252265
GenericBIDSAsset(
253266
filepath=tmp_path / "bids1" / "file.txt",
254267
path="bids1/file.txt",
@@ -271,7 +284,7 @@ def test_find_dandi_files_with_bids(tmp_path: Path) -> None:
271284
for asset in bidsdd.dataset_files:
272285
assert asset.bids_dataset_description is bidsdd
273286

274-
bidsdd = files[5]
287+
bidsdd = files[6]
275288
assert isinstance(bidsdd, BIDSDatasetDescriptionAsset)
276289
assert sorted(bidsdd.dataset_files, key=attrgetter("filepath")) == [
277290
GenericBIDSAsset(

dandi/tests/test_upload.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ def test_upload_bids_validation_ignore(
226226
dandiset.get_asset_by_path("dataset_description.json")
227227
# actual data file?
228228
dandiset.get_asset_by_path("sub-Sub1/anat/sub-Sub1_T1w.nii.gz")
229+
# .bidsignore file?
230+
dandiset.get_asset_by_path(".bidsignore")
229231

230232

231233
def test_upload_bids_metadata(
@@ -276,6 +278,8 @@ def test_upload_bids(
276278
dandiset.get_asset_by_path("dataset_description.json")
277279
# actual data file?
278280
dandiset.get_asset_by_path("sub-Sub1/anat/sub-Sub1_T1w.nii.gz")
281+
# .bidsignore file should be uploaded automatically
282+
dandiset.get_asset_by_path(".bidsignore")
279283

280284

281285
def test_upload_bids_non_nwb_file(bids_dandiset: SampleDandiset) -> None:

0 commit comments

Comments
 (0)