Skip to content

Commit

Permalink
Merge pull request #1121 from nipreps/fix/bids-db
Browse files Browse the repository at this point in the history
FIX: Better handling of BIDS cached indexation
  • Loading branch information
oesteban committed Jun 14, 2023
2 parents d0c4a13 + e3a07e4 commit 64becde
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
6 changes: 6 additions & 0 deletions mriqc/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ def _bids_filter(value):
help="Path to an existing PyBIDS database folder, for faster indexing "
"(especially useful for large datasets).",
)
g_bids.add_argument(
"--bids-database-wipe",
action="store_true",
default=False,
help="Wipe out previously existing BIDS indexing caches, forcing re-indexing.",
)

# General performance
g_perfm = parser.add_argument_group("Options to handle performance")
Expand Down
21 changes: 16 additions & 5 deletions mriqc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ class execution(_Config):
"""An existing path to the dataset, which must be BIDS-compliant."""
bids_database_dir = None
"""Path to the directory containing SQLite database indices for the input BIDS dataset."""
bids_database_wipe = False
"""Wipe out previously existing BIDS indexing caches, forcing re-indexing."""
bids_description_hash = None
"""Checksum (SHA256) of the ``dataset_description.json`` of the BIDS dataset."""
cwd = os.getcwd()
Expand Down Expand Up @@ -466,18 +468,27 @@ def init(cls):
)

# Initialize database in a multiprocessing-safe manner
cls.bids_database_dir = cls.output_dir / ".bids_db"
if not cls.bids_database_dir.exists():
_db_path = cls.output_dir / f".bids_db-{cls.run_uuid}"
_db_path = (
cls.work_dir if cls.participant_label else cls.output_dir
) / f".bids_db-{cls.run_uuid}"

if cls.bids_database_dir is None:
cls.bids_database_dir = (
cls.output_dir / ".bids_db"
if not cls.participant_label else _db_path
)

if cls.bids_database_wipe or not cls.bids_database_dir.exists():
_db_path.mkdir(exist_ok=True, parents=True)

BIDSLayout(
cls._layout = BIDSLayout(
str(cls.bids_dir),
database_path=_db_path,
indexer=_indexer,
)

_db_path.replace(cls.bids_database_dir.absolute())
if _db_path != cls.bids_database_dir:
_db_path.replace(cls.bids_database_dir.absolute())

cls._layout = BIDSLayout(
str(cls.bids_dir),
Expand Down

0 comments on commit 64becde

Please sign in to comment.