Skip to content

Commit

Permalink
Merge pull request #1110 from nipreps/enh/bids-db-handling
Browse files Browse the repository at this point in the history
FIX: BIDS database directory handling
  • Loading branch information
oesteban committed Apr 4, 2023
2 parents 21b4aab + d205cdb commit 5bb5947
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .circleci/circle_T1w.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.bids_db
.bids_db/layout_index.sqlite
.bidsignore
dataset_description.json
group_T1w.html
Expand Down
2 changes: 2 additions & 0 deletions .circleci/circle_bold.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.bids_db
.bids_db/layout_index.sqlite
.bidsignore
dataset_description.json
group_bold.html
Expand Down
24 changes: 16 additions & 8 deletions mriqc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,23 +457,31 @@ def init(cls):
+ r"))"
)

_db_path = cls.bids_database_dir or (
cls.work_dir / cls.run_uuid / "bids_db"
)
_db_path.mkdir(exist_ok=True, parents=True)

# Recommended after PyBIDS 12.1
_indexer = BIDSLayoutIndexer(
validate=False,
ignore=ignore_paths,
)

# 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.mkdir(exist_ok=True, parents=True)

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

_db_path.replace(cls.bids_database_dir.absolute())

cls._layout = BIDSLayout(
str(cls.bids_dir),
database_path=_db_path,
reset_database=cls.bids_database_dir is None,
database_path=cls.bids_database_dir,
indexer=_indexer,
)
cls.bids_database_dir = _db_path

cls.layout = cls._layout

Expand Down
1 change: 1 addition & 0 deletions mriqc/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def test_bids_indexing_manifest(tmp_path, testdata_path, testcase):

reload(config)

config.execution.output_dir = Path(tmp_path) / "out"
config.execution.bids_dir = _expand_bids(
tmp_path,
testdata_path,
Expand Down

0 comments on commit 5bb5947

Please sign in to comment.