diff --git a/snakebids/core/input_generation.py b/snakebids/core/input_generation.py index ec541f3c..372e9665 100644 --- a/snakebids/core/input_generation.py +++ b/snakebids/core/input_generation.py @@ -56,6 +56,7 @@ def generate_inputs( participant_label: Iterable[str] | str | None = ..., exclude_participant_label: Iterable[str] | str | None = ..., use_bids_inputs: Literal[True] | None = ..., + index_metadata: bool = ..., validate: bool = ..., pybids_database_dir: Path | str | None = ..., pybids_reset_database: bool = ..., @@ -75,6 +76,7 @@ def generate_inputs( participant_label: Iterable[str] | str | None = ..., exclude_participant_label: Iterable[str] | str | None = ..., use_bids_inputs: Literal[False] = ..., + index_metadata: bool = ..., validate: bool = ..., pybids_database_dir: Path | str | None = ..., pybids_reset_database: bool = ..., @@ -93,6 +95,7 @@ def generate_inputs( participant_label: Iterable[str] | str | None = None, exclude_participant_label: Iterable[str] | str | None = None, use_bids_inputs: bool | None = None, + index_metadata: bool = False, validate: bool = False, pybids_database_dir: Path | str | None = None, pybids_reset_database: bool | None = None, @@ -163,6 +166,10 @@ def generate_inputs( :class`BidsDataset`. Setting to True is deprecated as of v0.8, as this is now the default behaviour + index_metadata + If True indexes metadata of BIDS directory using pybids, otherwise skips + indexing. + validate If True performs validation of BIDS directory using pybids, otherwise skips validation. @@ -277,6 +284,7 @@ def generate_inputs( pybids_config=pybids_config, pybidsdb_dir=pybidsdb_dir, pybidsdb_reset=pybidsdb_reset, + index_metadata=index_metadata, validate=validate, ) if not _all_custom_paths(pybids_inputs) @@ -392,6 +400,7 @@ def _gen_bids_layout( pybidsdb_dir: Path | str | None, pybidsdb_reset: bool, pybids_config: Path | str | None = None, + index_metadata: bool = False, validate: bool = False, ) -> BIDSLayout: """Create (or reindex) the BIDSLayout. @@ -414,6 +423,9 @@ def _gen_bids_layout( A boolean that determines whether to reset / overwrite existing database. + index_metadata + A boolen that determines whether to parse and index metadata + validate A boolean that determines whether to validate the bids dataset @@ -438,7 +450,7 @@ def _gen_bids_layout( config=pybids_config, database_path=pybidsdb_dir, reset_database=pybidsdb_reset, - indexer=BIDSLayoutIndexer(validate=False, index_metadata=False), + indexer=BIDSLayoutIndexer(validate=False, index_metadata=index_metadata), ) diff --git a/snakebids/tests/test_generate_inputs.py b/snakebids/tests/test_generate_inputs.py index d852fe79..d2383ecb 100644 --- a/snakebids/tests/test_generate_inputs.py +++ b/snakebids/tests/test_generate_inputs.py @@ -1227,6 +1227,27 @@ def test_nonstandard_custom_pybids_config(tmpdir: Path): ) +def test_index_metadata(mocker: MockerFixture): + from snakebids.core import input_generation + + spy = mocker.spy(input_generation, "BIDSLayoutIndexer") + mocker.patch.object(input_generation, "BIDSLayout", side_effect=ValueError) + + # Simplest case -- one input type, using pybids + with pytest.raises(ValueError): # noqa + generate_inputs( + pybids_inputs={"foo": {}}, + bids_dir=..., # type: ignore + derivatives=..., # type: ignore + index_metadata=True, + ) + + spy.assert_called_once_with( + validate=False, + index_metadata=True, + ) + + def test_t1w(): # create config real_bids_dir = "snakebids/tests/data/bids_t1w"