From 9b941e228aa2f467e87435508f566cfc3beecf99 Mon Sep 17 00:00:00 2001 From: Alp Erkent Date: Tue, 9 Apr 2024 16:59:03 -0400 Subject: [PATCH 1/3] Fix functionality when is_derivative=True and validate=False Description of the "is_derivative" parameter of BIDSLayout states that this parameter "can be enabled along with validate=False to index derivatives without dataset_description.json." However, the initialization method of BIDSLayout calls "validate_derivative_path(root)" on line 141, which eventually leads to a "FileNotFoundError" as the this function then tries to read a dataset_description.json file that does not exist. This commit fixes this issue by catching this FileNotFoundError and restores intended functionality. --- bids/layout/layout.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bids/layout/layout.py b/bids/layout/layout.py index eaf09cbd..841de1c4 100644 --- a/bids/layout/layout.py +++ b/bids/layout/layout.py @@ -139,7 +139,7 @@ def __init__(self, root=None, validate=True, absolute_paths=True, ]): try: self.source_pipeline = validate_derivative_path(root) - except BIDSValidationError as err: + except (BIDSValidationError, FileNotFoundError) as err: if validate: raise err self.source_pipeline = None From c5e2a49fab040af7da408d1b2dc7aacb90848238 Mon Sep 17 00:00:00 2001 From: Alp Erkent Date: Mon, 22 Apr 2024 23:02:35 -0400 Subject: [PATCH 2/3] Update index.py to fix UnboundLocalError --- bids/layout/index.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bids/layout/index.py b/bids/layout/index.py index 38800d0e..8c3a8f5b 100644 --- a/bids/layout/index.py +++ b/bids/layout/index.py @@ -265,6 +265,7 @@ def _index_metadata(self): # ensure we are returning objects filters['return_type'] = 'object' + ext_key = 'extensions' if 'extensions' in filters else 'extension' if filters.get(ext_key): filters[ext_key] = listify(filters[ext_key]) # ensure json files are being indexed From 56b90324662a1daa1f8612cffc0797123cb03b30 Mon Sep 17 00:00:00 2001 From: Alp Erkent Date: Fri, 10 May 2024 13:54:49 -0400 Subject: [PATCH 3/3] Change 'ext_key' to 'extension' in index.py --- bids/layout/index.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bids/layout/index.py b/bids/layout/index.py index 8c3a8f5b..9cb56f55 100644 --- a/bids/layout/index.py +++ b/bids/layout/index.py @@ -265,12 +265,11 @@ def _index_metadata(self): # ensure we are returning objects filters['return_type'] = 'object' - ext_key = 'extensions' if 'extensions' in filters else 'extension' - if filters.get(ext_key): - filters[ext_key] = listify(filters[ext_key]) + if filters.get('extension'): + filters['extension'] = listify(filters['extension']) # ensure json files are being indexed - if '.json' not in filters[ext_key]: - filters[ext_key].append('.json') + if '.json' not in filters['extension']: + filters['extension'].append('.json') # Process JSON files first if we're indexing metadata all_files = self._layout.get(absolute_paths=True, **filters)