Repository: bids-standard/pybids

Issue:
dataset_description required for derivatives 
Looks like #168 requires a dataset_description.json file to be required for all folders passed to `BIDSLayout` even those that may not be full BIDS datasets. e.g.:

    layout = BIDSLayout(['/path/to/bids/', '/path/to/more/event/files')

This seems like unintentional behavior to me, as roots for derivatives should not require such a description, correct?


Discussion:
Good point. We should probably add a `requires_description` flag to the config files that's `False` by default and `True` only for the BIDS config. This would all go in grabbids rather than grabbit. Feel free to open a PR, otherwise I'll get to it probably tomorrow.
I got it

Resolving patch:
diff --git a/bids/grabbids/bids_layout.py b/bids/grabbids/bids_layout.py
--- a/bids/grabbids/bids_layout.py
+++ b/bids/grabbids/bids_layout.py
@@ -62,18 +62,6 @@ class BIDSLayout(Layout):
     def __init__(self, path, config=None, validate=False,
                  index_associated=True, include=None, exclude=None, **kwargs):
 
-        # Load and validate information in dataset_description.json
-        target = pathjoin(path, 'dataset_description.json')
-        if not exists(target):
-            raise ValueError("Mandatory 'dataset_description.json' file is "
-                             "missing from project root!")
-        self.description = json.load(open(target, 'r'))
-
-        for k in ['Name', 'BIDSVersion']:
-            if k not in self.description:
-                raise ValueError("Mandatory '%s' field missing from "
-                                 "dataset_description.json." % k)
-
         self.validator = BIDSValidator(index_associated=index_associated)
         self.validate = validate
 
@@ -104,12 +92,27 @@ def _load_config(conf):
                 configs.append(_load_config(conf))
 
         # If 'bids' isn't in the list, the user probably made a mistake...
-        if not any([c['name'] != 'bids' for c in configs]):
+        if any([c['name'] == 'bids' for c in configs]):
+            # Load and validate information in dataset_description.json
+            target = pathjoin(path, 'dataset_description.json')
+            if not exists(target):
+                if not exists(path):
+                    raise ValueError("Root directory does not exist.")                
+                raise ValueError("Mandatory 'dataset_description.json' file is "
+                                 "missing from project root!")
+            self.description = json.load(open(target, 'r'))
+
+            for k in ['Name', 'BIDSVersion']:
+                if k not in self.description:
+                    raise ValueError("Mandatory '%s' field missing from "
+                                     "dataset_description.json." % k)
+        else:
             warnings.warn("The core BIDS configuration was not included in the"
                           " config list. If you override the default value for"
                           " config, you probably want to make sure 'bids' is "
                           "included in the list of values.")
 
+
         super(BIDSLayout, self).__init__(path, config=configs,
                                          dynamic_getters=True, include=include,
                                          exclude=exclude, **kwargs)


Test patch:
diff --git a/bids/grabbids/tests/test_grabbids.py b/bids/grabbids/tests/test_grabbids.py
--- a/bids/grabbids/tests/test_grabbids.py
+++ b/bids/grabbids/tests/test_grabbids.py
@@ -35,6 +35,9 @@ def test_load_description(testlayout1):
         data_dir = join(get_test_data_path(), 'images')
         layout = BIDSLayout(data_dir)
         assert e.value.message.startswith("Mandatory 'dataset_description'")
+
+    # Should not raise an error
+    layout = BIDSLayout(data_dir, config='derivatives')
     assert hasattr(testlayout1, 'description')
     assert testlayout1.description['Name'] == '7t_trt'
     assert testlayout1.description['BIDSVersion'] == "1.0.0rc3"