Skip to content

Commit e7d7ac8

Browse files
committed
fix(details): address various issues generating docs, running smoke tests, pytest, etc.
1 parent bd08c2a commit e7d7ac8

File tree

7 files changed

+56
-36
lines changed

7 files changed

+56
-36
lines changed

docs/usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Example: ::
3131
Command-Line Arguments
3232
----------------------
3333
.. argparse::
34-
:ref: fmriprep.cli.run.get_parser
34+
:ref: fmriprep.cli.parser._build_parser
3535
:prog: fmriprep
3636
:nodefault:
3737
:nodefaultconst:

docs/workflows.rst

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ is presented below:
1919

2020
from fmriprep.workflows.tests import mock_config
2121
from fmriprep.workflows.base import init_single_subject_wf
22-
mock_config()
23-
wf = init_single_subject_wf()
22+
with mock_config():
23+
wf = init_single_subject_wf('01')
2424

2525
Preprocessing of structural MRI
2626
-------------------------------
@@ -54,7 +54,7 @@ single reference template (see `Longitudinal processing`_).
5454
skull_strip_fixed_seed=False,
5555
)
5656

57-
See also *sMRIPrep*'s
57+
See also *sMRIPrep*'s
5858
:py:func:`~smriprep.workflows.anatomical.init_anat_preproc_wf`.
5959

6060
.. _t1preproc_steps:
@@ -176,7 +176,7 @@ would be processed by the following command::
176176
-autorecon1 \
177177
-noskullstrip
178178

179-
The second phase imports the brainmask calculated in the
179+
The second phase imports the brainmask calculated in the
180180
`Preprocessing of structural MRI`_ sub-workflow.
181181
The final phase resumes reconstruction, using the T2w image to assist
182182
in finding the pial surface, if available.
@@ -238,13 +238,12 @@ BOLD preprocessing
238238
:simple_form: yes
239239

240240
from fmriprep.workflows.tests import mock_config
241+
from fmriprep import config
241242
from fmriprep.workflows.bold.base import init_func_preproc_wf
242-
mock_config()
243-
244-
from collections import namedtuple
245-
from niworkflows.utils.spaces import SpatialReferences
246-
BIDSLayout = namedtuple('BIDSLayout', ['root'])
247-
wf = init_func_preproc_wf('sub-01_task-nback_bold.nii.gz')
243+
with mock_config():
244+
bold_file = config.execution.bids_dir / 'sub-01' / 'func' \
245+
/ 'sub-01_task-mixedgamblestask_run-01_bold.nii.gz'
246+
wf = init_func_preproc_wf(str(bold_file))
248247

249248
Preprocessing of :abbr:`BOLD (blood-oxygen level-dependent)` files is
250249
split into multiple sub-workflows described below.
@@ -429,7 +428,7 @@ Resampling BOLD runs onto standard spaces
429428
This sub-workflow concatenates the transforms calculated upstream (see
430429
`Head-motion estimation`_, `Susceptibility Distortion Correction (SDC)`_ --if
431430
fieldmaps are available--, `EPI to T1w registration`_, and an anatomical-to-standard
432-
transform from `Preprocessing of structural MRI`_) to map the
431+
transform from `Preprocessing of structural MRI`_) to map the
433432
:abbr:`EPI (echo-planar imaging)`
434433
image to the standard spaces given by the ``--output-spaces`` argument
435434
(see :ref:`output-spaces`).

fmriprep/cli/tests/test_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_get_parser_update(monkeypatch, capsys, current, latest):
8282
def _mock_check_latest(*args, **kwargs):
8383
return Version(latest)
8484

85-
monkeypatch.setattr(config.execution, 'version', current)
85+
monkeypatch.setattr(config.environment, 'version', current)
8686
monkeypatch.setattr(_version, 'check_latest', _mock_check_latest)
8787

8888
_build_parser()

fmriprep/config.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,27 @@
77
88
Example
99
-------
10-
>>> from fmriprep import config
11-
>>> config_file = config.execution.work_dir / '.fmriprep.toml'
12-
>>> config.to_filename(config_file)
13-
>>> # Call build_workflow(config_file, retval) in a subprocess
14-
>>> with Manager() as mgr:
15-
>>> from .workflow import build_workflow
16-
>>> retval = mgr.dict()
17-
>>> p = Process(target=build_workflow, args=(str(config_file), retval))
18-
>>> p.start()
19-
>>> p.join()
20-
>>> config.load(config_file)
21-
>>> # Access configs from any code section as:
22-
>>> value = config.section.setting
10+
11+
.. code-block:: Python
12+
13+
>>> from fmriprep import config
14+
>>> config_file = config.execution.work_dir / '.fmriprep.toml'
15+
>>> config.to_filename(config_file)
16+
>>> # Call build_workflow(config_file, retval) in a subprocess
17+
>>> with Manager() as mgr:
18+
>>> from .workflow import build_workflow
19+
>>> retval = mgr.dict()
20+
>>> p = Process(target=build_workflow, args=(str(config_file), retval))
21+
>>> p.start()
22+
>>> p.join()
23+
>>> config.load(config_file)
24+
>>> # Access configs from any code section as:
25+
>>> value = config.section.setting
2326
2427
The module also has a :py:func:`to_filename` function to allow writting out
25-
the settings to hard disk in *ToML* format, which looks like::
28+
the settings to hard disk in *ToML* format, which looks like
29+
30+
.. code-block:: toml
2631
2732
[environment]
2833
cpu_count = 8

fmriprep/workflows/base.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def init_fmriprep_wf():
4848
4949
from fmriprep.workflows.tests import mock_config
5050
from fmriprep.workflows.base import init_fmriprep_wf
51-
mock_config()
52-
wf = init_fmriprep_wf()
51+
with mock_config():
52+
wf = init_fmriprep_wf()
5353
5454
"""
5555
fmriprep_wf = Workflow(name='fmriprep_wf')
@@ -109,8 +109,8 @@ def init_single_subject_wf(subject_id):
109109
110110
from fmriprep.workflows.tests import mock_config
111111
from fmriprep.workflows.base import init_single_subject_wf
112-
mock_config()
113-
wf = init_single_subject_wf('test')
112+
with mock_config():
113+
wf = init_single_subject_wf('01')
114114
115115
Parameters
116116
----------
@@ -222,15 +222,16 @@ def init_single_subject_wf(subject_id):
222222
freesurfer=config.workflow.run_reconall,
223223
hires=config.workflow.hires,
224224
longitudinal=config.workflow.longitudinal,
225+
num_t1w=len(subject_data['t1w']),
225226
omp_nthreads=config.nipype.omp_nthreads,
226227
output_dir=str(config.execution.output_dir),
227228
reportlets_dir=reportlets_dir,
228229
skull_strip_fixed_seed=config.workflow.skull_strip_fixed_seed,
229-
skull_strip_mode='force',
230+
# skull_strip_mode='force',
230231
skull_strip_template=Reference.from_string(
231232
config.workflow.skull_strip_template)[0],
232233
spaces=spaces,
233-
t1w=subject_data['t1w'],
234+
# t1w=subject_data['t1w'],
234235
)
235236

236237
workflow.connect([

fmriprep/workflows/bold/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ def init_func_preproc_wf(bold_file):
5151
:simple_form: yes
5252
5353
from fmriprep.workflows.tests import mock_config
54+
from fmriprep import config
5455
from fmriprep.workflows.bold.base import init_func_preproc_wf
55-
mock_config()
56-
wf = init_func_preproc_wf('sub-01_task-mixedgamblestask_run-01_bold.nii.gz')
56+
with mock_config():
57+
bold_file = config.execution.bids_dir / 'sub-01' / 'func' \
58+
/ 'sub-01_task-mixedgamblestask_run-01_bold.nii.gz'
59+
wf = init_func_preproc_wf(str(bold_file))
5760
5861
Parameters
5962
----------

fmriprep/workflows/tests.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
"""Utilities and mocks for testing and documentation building."""
2+
import os
3+
from contextlib import contextmanager
24
from pathlib import Path
35
from pkg_resources import resource_filename as pkgrf
46
from toml import loads
57
from tempfile import mkdtemp
68

79

10+
@contextmanager
811
def mock_config():
912
"""Create a mock config for documentation and testing purposes."""
1013
from .. import config
14+
_old_fs = os.getenv('FREESURFER_HOME')
15+
if not _old_fs:
16+
os.environ['FREESURFER_HOME'] = mkdtemp()
17+
1118
filename = Path(pkgrf('fmriprep', 'data/tests/config.toml'))
1219
settings = loads(filename.read_text())
1320
for sectionname, configs in settings.items():
@@ -18,5 +25,10 @@ def mock_config():
1825
config.init_spaces()
1926

2027
config.execution.work_dir = Path(mkdtemp())
21-
config.execution.bids_dir = Path(pkgrf('fmriprep', 'data/tests/ds000005'))
28+
config.execution.bids_dir = Path(pkgrf('fmriprep', 'data/tests/ds000005')).absolute()
2229
config.init_layout()
30+
31+
yield
32+
33+
if not _old_fs:
34+
del os.environ["FREESURFER_HOME"]

0 commit comments

Comments
 (0)