Repository: mne-tools/mne-bids-pipeline

Issue:
Commandline --root_dir flag error
I get the following error when running mne-pipeline from the commandline with the --root_dir flag.  If I set bids_root in the config2.py file, I do not have this issue.  The issue appears to be from checking the bids_root variable during the import of config.py before it is set using the get_bids_root() function.  

```python
(mne_pipeline) jstout@kani:/fast/BIDS_HV_V1mod$ ~/src/mne-bids-pipeline/run.py /fast/BIDS_HV_V1mod/config2.py --root_dir=/fast/BIDS_HV_V1mod
2021-07-12 16:47:53 INFO Now running: init/00-init_derivatives_dir.py
16:47:53 Using custom configuration: /fast/BIDS_HV_V1mod/config2.py
Traceback (most recent call last):
  File "/home/jstout/src/mne-bids-pipeline/run.py", line 228, in <module>
    fire.Fire(process)
  File "/home/jstout/miniconda3/envs/mne_pipeline/lib/python3.8/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/home/jstout/miniconda3/envs/mne_pipeline/lib/python3.8/site-packages/fire/core.py", line 466, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/home/jstout/miniconda3/envs/mne_pipeline/lib/python3.8/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/home/jstout/src/mne-bids-pipeline/run.py", line 222, in process
    _run_script(script_path, config, root_dir, subject, session, task, run,
  File "/home/jstout/src/mne-bids-pipeline/run.py", line 108, in _run_script
    runpy.run_path(script_path, run_name='__main__')
  File "/home/jstout/miniconda3/envs/mne_pipeline/lib/python3.8/runpy.py", line 265, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/home/jstout/miniconda3/envs/mne_pipeline/lib/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/home/jstout/miniconda3/envs/mne_pipeline/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/jstout/src/mne-bids-pipeline/scripts/init/00-init_derivatives_dir.py", line 18, in <module>
    import config
  File "/home/jstout/src/mne-bids-pipeline/config.py", line 1800, in <module>
    _all_sessions = _get_entity_vals_cached(
  File "/home/jstout/src/mne-bids-pipeline/config.py", line 1745, in _get_entity_vals_cached
    return mne_bids.get_entity_vals(*args, **kwargs)
  File "/home/jstout/miniconda3/envs/mne_pipeline/lib/python3.8/site-packages/mne_bids/path.py", line 1278, in get_entity_vals
    filenames = (Path(root)
  File "/home/jstout/miniconda3/envs/mne_pipeline/lib/python3.8/pathlib.py", line 1041, in __new__
    self = cls._from_parts(args, init=False)
  File "/home/jstout/miniconda3/envs/mne_pipeline/lib/python3.8/pathlib.py", line 682, in _from_parts
    drv, root, parts = self._parse_args(args)
  File "/home/jstout/miniconda3/envs/mne_pipeline/lib/python3.8/pathlib.py", line 666, in _parse_args
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType
```

Line 1800 in config.py causes the error:
```python
_all_sessions = _get_entity_vals_cached(
    bids_root,
    entity_key='session',
    ignore_datatypes=tuple(_ignore_datatypes)
)
```
Solution ?
If the section is changed to the below, this no longer errors out.  `(bids_root >> root=get_bids_root())`

```python
_all_sessions = _get_entity_vals_cached(
    root=get_bids_root(),
    entity_key='session',
    ignore_datatypes=tuple(_ignore_datatypes)
)
```


Discussion:
Thanks for reporting! This indeed seems to be the correct fix. Would you like to make a Pull Request with this change?

Resolving patch:
diff --git a/config.py b/config.py
--- a/config.py
+++ b/config.py
@@ -1798,7 +1798,7 @@ def get_datatype() -> Literal['meg', 'eeg']:
 )
 
 _all_sessions = _get_entity_vals_cached(
-    bids_root,
+    root=get_bids_root(),
     entity_key='session',
     ignore_datatypes=tuple(_ignore_datatypes)
 )


Test patch: