Skip to content

Commit 2961392

Browse files
authored
RF/DOC: Parser defaults (#3487)
Renders `fmriprep` proper defaults in the sphinx documentation. A few drive-by changes: - `--no-submm-recon` and `--no-msm` are now argparse.BooleanOptionalActions - `--work-dir` default is set during argument parsing (to avoid rendering an arbitrary path when docs are built)
2 parents 2263b64 + a38e10f commit 2961392

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

docs/usage.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ Command-Line Arguments
3535
.. argparse::
3636
:ref: fmriprep.cli.parser._build_parser
3737
:prog: fmriprep
38-
:nodefault:
39-
:nodefaultconst:
4038

4139

4240
The command-line interface of the docker wrapper

fmriprep/cli/parser.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"""Parser."""
2424

2525
import sys
26+
from pathlib import Path
2627

2728
from .. import config
2829

@@ -32,9 +33,13 @@ def _build_parser(**kwargs):
3233
3334
``kwargs`` are passed to ``argparse.ArgumentParser`` (mainly useful for debugging).
3435
"""
35-
from argparse import Action, ArgumentDefaultsHelpFormatter, ArgumentParser
36+
from argparse import (
37+
Action,
38+
ArgumentDefaultsHelpFormatter,
39+
ArgumentParser,
40+
BooleanOptionalAction,
41+
)
3642
from functools import partial
37-
from pathlib import Path
3843

3944
from niworkflows.utils.spaces import OutputReferencesAction, Reference
4045
from packaging.version import Version
@@ -413,7 +418,7 @@ def _fallback_trt(value, parser):
413418
'--slice-time-ref',
414419
required=False,
415420
action='store',
416-
default=None,
421+
default=0.5,
417422
type=SliceTimeRef,
418423
help='The time of the reference slice to correct BOLD values to, as a fraction '
419424
'acquisition time. 0 indicates the start, 0.5 the midpoint, and 1 the end '
@@ -496,7 +501,6 @@ def _fallback_trt(value, parser):
496501
)
497502
g_conf.add_argument(
498503
'--project-goodvoxels',
499-
required=False,
500504
action='store_true',
501505
default=False,
502506
help='Exclude voxels whose timeseries have locally high coefficient of variation '
@@ -521,10 +525,11 @@ def _fallback_trt(value, parser):
521525
'(default is 91k, which equates to 2mm resolution)',
522526
)
523527
g_outputs.add_argument(
524-
'--no-msm',
525-
action='store_false',
528+
'--msm',
529+
action=BooleanOptionalAction,
530+
default=True,
526531
dest='run_msmsulc',
527-
help='Disable Multimodal Surface Matching surface registration.',
532+
help='Enable or disable Multimodal Surface Matching surface registration.',
528533
)
529534

530535
g_confounds = parser.add_argument_group('Options relating to confounds')
@@ -634,10 +639,11 @@ def _fallback_trt(value, parser):
634639
'(default: OUTPUT_DIR/freesurfer)',
635640
)
636641
g_fs.add_argument(
637-
'--no-submm-recon',
638-
action='store_false',
642+
'--submm-recon',
643+
action=BooleanOptionalAction,
644+
default=True,
639645
dest='hires',
640-
help='Disable sub-millimeter (hires) reconstruction',
646+
help='Enable or disable sub-millimeter (hi-res) reconstruction.',
641647
)
642648
g_fs.add_argument(
643649
'--fs-no-reconall',
@@ -656,6 +662,7 @@ def _fallback_trt(value, parser):
656662
g_carbon = parser.add_argument_group('Options for carbon usage tracking')
657663
g_carbon.add_argument(
658664
'--track-carbon',
665+
default=False,
659666
action='store_true',
660667
help='Tracks power draws using CodeCarbon package',
661668
)
@@ -682,7 +689,6 @@ def _fallback_trt(value, parser):
682689
'--work-dir',
683690
action='store',
684691
type=Path,
685-
default=Path('work').absolute(),
686692
help='Path where intermediate results should be stored',
687693
)
688694
g_other.add_argument(
@@ -776,6 +782,9 @@ def parse_args(args=None, namespace=None):
776782
config.execution.log_level = int(max(25 - 5 * opts.verbose_count, logging.DEBUG))
777783
config.from_dict(vars(opts), init=['nipype'])
778784

785+
if config.execution.work_dir is None:
786+
config.execution.work_dir = Path('work').absolute()
787+
779788
# Consistency checks
780789
force_set = set(config.workflow.force)
781790
ignore_set = set(config.workflow.ignore)

fmriprep/cli/tests/test_parser.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,19 @@ def test_derivatives(tmp_path):
270270
parser.parse_args(temp_args)
271271

272272
_reset_config()
273+
274+
275+
@pytest.mark.parametrize(
276+
('supp_args', 'opt', 'expected'),
277+
[
278+
(['--no-submm-recon'], 'hires', False),
279+
(['--submm-recon'], 'hires', True),
280+
([], 'hires', True),
281+
(['--no-msm'], 'run_msmsulc', False),
282+
],
283+
)
284+
def test_optional_booleans(tmp_path, supp_args, opt, expected):
285+
out_path = str(tmp_path / 'out')
286+
args = [str(tmp_path), out_path, 'participant'] + supp_args
287+
pargs = _build_parser().parse_args(args)
288+
assert getattr(pargs, opt) == expected

0 commit comments

Comments
 (0)