Skip to content

Commit c2b8e0f

Browse files
authored
Merge pull request #788 from nipreps/fix/786-read-bids-meta
ENH: Allow passing a ``database_path`` to create a ``BIDSLayout``
2 parents 647c895 + 996693b commit c2b8e0f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

niworkflows/interfaces/bids.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class _BIDSBaseInputSpec(BaseInterfaceInputSpec):
8484
(None, Directory(exists=True)), usedefault=True, desc="optional bids directory"
8585
)
8686
bids_validate = traits.Bool(True, usedefault=True, desc="enable BIDS validator")
87+
index_db = Directory(exists=True, desc="a PyBIDS layout cache directory")
8788

8889

8990
class _BIDSInfoInputSpec(_BIDSBaseInputSpec):
@@ -832,7 +833,13 @@ def _outputs(self):
832833
def _run_interface(self, runtime):
833834
self.layout = self.inputs.bids_dir or self.layout
834835
self.layout = _init_layout(
835-
self.inputs.in_file, self.layout, self.inputs.bids_validate
836+
self.inputs.in_file,
837+
self.layout,
838+
self.inputs.bids_validate,
839+
database_path=(
840+
self.inputs.index_db if isdefined(self.inputs.index_db)
841+
else None
842+
)
836843
)
837844

838845
# Fill in BIDS entities of the output ("*_id")

niworkflows/utils/bids.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def get_metadata_for_nifti(in_file, bids_dir=None, validate=True):
280280
return _init_layout(in_file, bids_dir, validate).get_metadata(str(in_file))
281281

282282

283-
def _init_layout(in_file=None, bids_dir=None, validate=True):
283+
def _init_layout(in_file=None, bids_dir=None, validate=True, database_path=None):
284284
if isinstance(bids_dir, BIDSLayout):
285285
return bids_dir
286286

@@ -294,7 +294,11 @@ def _init_layout(in_file=None, bids_dir=None, validate=True):
294294
if bids_dir is None:
295295
raise RuntimeError("Could not infer BIDS root")
296296

297-
layout = BIDSLayout(str(bids_dir), validate=validate)
297+
layout = BIDSLayout(
298+
str(bids_dir),
299+
validate=validate,
300+
database_path=database_path,
301+
)
298302
return layout
299303

300304

0 commit comments

Comments
 (0)