Skip to content

Commit 2e1e1d3

Browse files
committed
ENH+BF: find_files to take list of topdirs, look for _bold only under sub-* directories
Originally issue reported on https://neurostars.org/t/heudicov-permission-denied-bids-derivatives-mriqc/16543 where heudiconv would crash while trying to create an _events.tsv file under derivatives/mriqc. heudiconv should not care to look anywhere besides immediate subject directories, even if people place derivatives direcly in the dataset into which they are also converting their data into (making YODA unhappy).
1 parent 0e0f9e3 commit 2e1e1d3

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

heudiconv/bids.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def populate_aggregated_jsons(path):
114114
# way too many -- let's just collect all which are the same!
115115
# FIELDS_TO_TRACK = {'RepetitionTime', 'FlipAngle', 'EchoTime',
116116
# 'Manufacturer', 'SliceTiming', ''}
117-
for fpath in find_files('.*_task-.*\_bold\.json', topdir=path,
117+
for fpath in find_files('.*_task-.*\_bold\.json',
118+
topdir=glob(op.join(path, 'sub-*')),
118119
exclude_vcs=True,
119120
exclude="/\.(datalad|heudiconv)/"):
120121
#

heudiconv/parser.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
_VCS_REGEX = '%s\.(?:git|gitattributes|svn|bzr|hg)(?:%s|$)' % (op.sep, op.sep)
2626

27+
2728
@docstring_parameter(_VCS_REGEX)
2829
def find_files(regex, topdir=op.curdir, exclude=None,
2930
exclude_vcs=True, dirs=False):
@@ -36,12 +37,16 @@ def find_files(regex, topdir=op.curdir, exclude=None,
3637
exclude_vcs:
3738
If True, excludes commonly known VCS subdirectories. If string, used
3839
as regex to exclude those files (regex: `{}`)
39-
topdir: basestring, optional
40+
topdir: basestring or list, optional
4041
Directory where to search
4142
dirs: bool, optional
4243
Either to match directories as well as files
4344
"""
44-
45+
if isinstance(topdir, (list, tuple)):
46+
for topdir_ in topdir:
47+
yield from find_files(
48+
regex, topdir=topdir_, exclude=exclude, exclude_vcs=exclude_vcs, dirs=dirs)
49+
return
4550
for dirpath, dirnames, filenames in os.walk(topdir):
4651
names = (dirnames + filenames) if dirs else filenames
4752
paths = (op.join(dirpath, name) for name in names)

0 commit comments

Comments
 (0)