Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 5 additions & 8 deletions mne_bids/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,8 @@ def get_entity_vals(
ignore_suffixes : str | array-like of str | None
Suffixes to ignore. If ``None``, include all suffixes. This can be helpful for
ignoring non-data sidecars such as `*_scans.tsv` or `*_coordsystem.json`.

.. versionadded:: 0.17
include_match : str | array-like of str | None
Apply a starting match pragma following Unix style pattern syntax from
package glob to prefilter search criterion.
Expand Down Expand Up @@ -2542,24 +2544,19 @@ def _return_root_paths(root, datatype=None, ignore_json=True, ignore_nosub=False

if datatype is None and not ignore_nosub:
search_str = "*.*"
paths = root.rglob(search_str)
else:
if datatype is not None:
datatype = _ensure_tuple(datatype)
search_str = f"**/{'|'.join(datatype)}/.*"
search_str = f"**/{'|'.join(datatype)}/*.*"
Copy link
Member Author

Choose a reason for hiding this comment

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

This was the real bug. All else is just cleanups + test

else:
search_str = "**/*.*"

# only browse files which are of the form root/sub-*,
# such that we truely only look in 'sub'-folders:

if ignore_nosub:
search_str = "sub-*/" + search_str
search_str = f"sub-*/{search_str}"

paths = [
Path(root, fn)
for fn in glob.iglob(search_str, root_dir=root, recursive=True)
]
paths = root.rglob(search_str)

# Only keep files (not directories), ...
# and omit the JSON sidecars if `ignore_json` is True.
Expand Down
23 changes: 22 additions & 1 deletion mne_bids/tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ def test_filter_fnames(entities, expected_n_matches):


@testing.requires_testing_data
def test_match(return_bids_test_dir):
def test_match_basic(return_bids_test_dir):
"""Test retrieval of matching basenames."""
bids_root = Path(return_bids_test_dir)

Expand Down Expand Up @@ -1140,6 +1140,27 @@ def test_match(return_bids_test_dir):
bids_path_01.fpath.unlink() # clean up created file


def test_match_advanced(tmp_path):
"""Test additional match functionality."""
bids_root = tmp_path
fnames = (
"sub-01/nirs/sub-01_task-tapping_events.tsv",
"sub-02/nirs/sub-02_task-tapping_events.tsv",
)
for fname in fnames:
this_path = Path(bids_root / fname)
this_path.parent.mkdir(parents=True, exist_ok=True)
this_path.touch()
path = BIDSPath(
root=bids_root,
datatype="nirs",
suffix="events",
extension=".tsv",
)
matches = path.match()
assert len(matches) == len(fnames), path


@testing.requires_testing_data
def test_find_matching_paths(return_bids_test_dir):
"""We test by yielding the same results as BIDSPath.match().
Expand Down
Loading