-
Notifications
You must be signed in to change notification settings - Fork 98
BUG: Fix bug with path search #1379
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 3 commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ | |
| from copy import deepcopy | ||
| from datetime import datetime | ||
| from io import StringIO | ||
| from itertools import chain as iter_chain | ||
| from os import path as op | ||
| from pathlib import Path | ||
| from textwrap import indent | ||
|
|
@@ -2014,9 +2013,12 @@ 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. | ||
| Glob-style match string(s) of directories to include in the search (i.e., each | ||
| must end with ``"/"``). ``None`` (the default) is equivalent to ``"**/"`` | ||
| (within any subdirectory of the BIDS root). | ||
|
|
||
| .. versionadded:: 0.17 | ||
| with_key : bool | ||
|
|
@@ -2117,8 +2119,7 @@ def get_entity_vals( | |
| search_str = f"**/*{entity_long_abbr_map[entity_key]}-*_*" | ||
| if include_match is not None: | ||
| include_match = _ensure_tuple(include_match) | ||
| filenames = [root.glob(im + search_str) for im in include_match] | ||
| filenames = iter_chain(*filenames) | ||
| filenames = [f for im in include_match for f in root.glob(im + search_str)] | ||
| else: | ||
| filenames = root.glob(search_str) | ||
|
|
||
|
|
@@ -2541,21 +2542,20 @@ def _return_root_paths(root, datatype=None, ignore_json=True, ignore_nosub=False | |
| root = Path(root) # if root is str | ||
|
|
||
| if datatype is None and not ignore_nosub: | ||
| search_str = "*.*" | ||
| paths = root.rglob(search_str) | ||
| paths = root.rglob("*.*") | ||
| else: | ||
| if datatype is not None: | ||
| datatype = _ensure_tuple(datatype) | ||
| search_str = f"**/{'|'.join(datatype)}/.*" | ||
| search_str = f"**/{'|'.join(datatype)}/*.*" | ||
|
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. 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}" | ||
| # TODO: Why is this not equivalent to list(root.rglob(search_str)) ? | ||
| # Most of the speedup is from using glob.iglob here. | ||
| paths = [ | ||
| Path(root, fn) | ||
| for fn in glob.iglob(search_str, root_dir=root, recursive=True) | ||
|
|
||
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
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.