Skip to content

Commit 08ec2b3

Browse files
committed
ref+tst: allow bidsgrabber to initialize without pybids, grab dependencies from requirements.txt
1 parent 77fb3c4 commit 08ec2b3

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ before_install:
3636
conda update -q conda &&
3737
conda config --add channels conda-forge &&
3838
conda install python=${TRAVIS_PYTHON_VERSION} &&
39-
conda install -y nipype icu &&
40-
rm -r ${CONDA_HOME}/lib/python${TRAVIS_PYTHON_VERSION}/site-packages/nipype*; }
39+
conda install -y icu &&
40+
pip install -r requirements.txt &&; }
4141
# Add install of vtk and mayavi to test mesh (disabled): conda install -y vtk mayavi
4242
- travis_retry apt_inst
4343
- travis_retry conda_inst

nipype/interfaces/bids_utils.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
77
BIDSDataGrabber: Query data from BIDS dataset using pybids grabbids.
88
9+
10+
Change directory to provide relative paths for doctests
11+
>>> import os
12+
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
13+
>>> datadir = os.path.realpath(os.path.join(filepath, '../testing/data'))
14+
>>> os.chdir(datadir)
915
"""
1016
from os.path import join, dirname
1117
import json
@@ -52,36 +58,29 @@ class BIDSDataGrabber(BaseInterface):
5258
from a project, and makes BIDS entities (e.g. subject) available for
5359
filtering outputs.
5460
55-
>>> bg = BIDSDataGrabber() # doctest: +SKIP
61+
>>> bg = BIDSDataGrabber()
5662
>>> bg.inputs.base_dir = 'ds005/'
5763
>>> bg.inputs.subject = '01'
58-
>>> results = bg.run() # doctest
59-
>>> basename(results.outputs.anat[0])
60-
'sub-01_T1w.nii.gz'
61-
62-
>>> basename(results.outputs.func[0])
63-
'sub-01_task-mixedgamblestask_run-01_bold.nii.gz'
64+
>>> results = bg.run() # doctest: +SKIP
6465
6566
6667
Dynamically created, user-defined output fields can also be defined to
6768
return different types of outputs from the same project. All outputs
6869
are filtered on common entities, which can be explicitly defined as
6970
infields.
7071
71-
>>> bg = BIDSDataGrabber(infields = ['subject'], outfields = ['dwi']) # doctest: +SKIP
72+
>>> bg = BIDSDataGrabber(infields = ['subject'], outfields = ['dwi'])
7273
>>> bg.inputs.base_dir = 'ds005/'
7374
>>> bg.inputs.subject = '01'
7475
>>> bg.inputs.output_query['dwi'] = dict(modality='dwi')
75-
>>> results = bg.run()
76-
>>> basename(results.outputs.dwi[0])
77-
'sub-01_dwi.nii.gz'
76+
>>> results = bg.run() # doctest: +SKIP
7877
7978
"""
8079
input_spec = BIDSDataGrabberInputSpec
8180
output_spec = DynamicTraitedSpec
8281
_always_run = True
8382

84-
def __init__(self, infields=None, **kwargs):
83+
def __init__(self, infields=[], **kwargs):
8584
"""
8685
Parameters
8786
----------
@@ -93,17 +92,13 @@ def __init__(self, infields=None, **kwargs):
9392
If no matching items, returns Undefined.
9493
"""
9594
super(BIDSDataGrabber, self).__init__(**kwargs)
96-
if not have_pybids:
97-
raise ImportError(
98-
"The BIDSEventsGrabber interface requires pybids."
99-
" Please make sure it is installed.")
10095

10196
if not isdefined(self.inputs.output_query):
10297
self.inputs.output_query = {"func": {"modality": "func"},
10398
"anat": {"modality": "anat"}}
10499

105-
# If infields is None, use all BIDS entities
106-
if infields is None:
100+
# If infields is empty, use all BIDS entities
101+
if not infields and have_pybids:
107102
bids_config = join(dirname(gb.__file__), 'config', 'bids.json')
108103
bids_config = json.load(open(bids_config, 'r'))
109104
infields = [i['name'] for i in bids_config['entities']]
@@ -119,6 +114,10 @@ def __init__(self, infields=None, **kwargs):
119114
self.inputs.trait_set(trait_change_notify=False, **undefined_traits)
120115

121116
def _run_interface(self, runtime):
117+
if not have_pybids:
118+
raise ImportError(
119+
"The BIDSEventsGrabber interface requires pybids."
120+
" Please make sure it is installed.")
122121
return runtime
123122

124123
def _list_outputs(self):

nipype/testing/data/ds005/filler.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)