Skip to content

Commit 199a496

Browse files
authored
Merge pull request #88 from oesteban/maint/config-module
ENH: Adopt config module
2 parents 8e796a5 + 2d1eacd commit 199a496

29 files changed

+1602
-959
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ jobs:
451451
which dmriprep | grep sdist\\/bin
452452
INSTALLED_VERSION=$(dmriprep --version)
453453
INSTALLED_VERSION=${INSTALLED_VERSION%$'\r'}
454-
INSTALLED_VERSION=${INSTALLED_VERSION#*"dmriprep v"}
454+
INSTALLED_VERSION=${INSTALLED_VERSION#*"dMRIPrep v"}
455455
echo "VERSION: \"$THISVERSION\""
456456
echo "INSTALLED: \"$INSTALLED_VERSION\""
457457
test "$INSTALLED_VERSION" = "$THISVERSION"
@@ -470,7 +470,7 @@ jobs:
470470
which dmriprep | grep wheel\\/bin
471471
INSTALLED_VERSION=$(dmriprep --version)
472472
INSTALLED_VERSION=${INSTALLED_VERSION%$'\r'}
473-
INSTALLED_VERSION=${INSTALLED_VERSION#*"dmriprep v"}
473+
INSTALLED_VERSION=${INSTALLED_VERSION#*"dMRIPrep v"}
474474
echo "VERSION: \"$THISVERSION\""
475475
echo "INSTALLED: \"$INSTALLED_VERSION\""
476476
test "$INSTALLED_VERSION" = "$THISVERSION"

.dockerignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ dmriprep.egg-info/**/*
1212
dmriprep.egg-info
1313
.eggs/**/*
1414
.eggs
15+
.pytest_cache/**/*
16+
.pytest_cache
17+
.ipynb_checkpoints/**/*
18+
.ipynb_checkpoints
19+
1520

1621
# housekeeping tools
1722
.maintenance/**/*
@@ -27,6 +32,8 @@ src/
2732
.gitignore
2833
.git/**/*
2934
.git
35+
.github/**/*
36+
.github
3037
.mailmap
3138

3239
# other
@@ -41,7 +48,6 @@ out/
4148
.codecov.yml
4249
.coveragerc
4350
.pep8speaks.yml
44-
.readthedocs.yml
4551
.travis.yml
4652
.zenodo.json
4753

MANIFEST.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@ include LICENSE
55
# versioneer
66
include versioneer.py
77
include dmriprep/_version.py
8-
9-
# data
10-
include dmriprep/config/reports-spec.yml

dmriprep/__init__.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
"""Top-level package for dmriprep."""
2-
import warnings as _warnings
32
from .__about__ import (
43
__version__,
54
__copyright__,
65
__credits__,
76
__packagename__,
87
)
98

10-
119
__all__ = [
1210
'__version__',
1311
'__copyright__',
1412
'__credits__',
1513
'__packagename__',
1614
]
17-
18-
# cmp is not used by dmriprep, so ignore nipype-generated warnings
19-
_warnings.filterwarnings('ignore', r'cmp not installed')
20-
_warnings.filterwarnings('ignore', r'This has not been fully tested. Please report any failures.')
21-
_warnings.filterwarnings('ignore', r"can't resolve package from __spec__ or __package__")
22-
_warnings.simplefilter('ignore', DeprecationWarning)
23-
_warnings.simplefilter('ignore', ResourceWarning)

dmriprep/cli/parser.py

Lines changed: 341 additions & 0 deletions
Large diffs are not rendered by default.

dmriprep/cli/run.py

Lines changed: 78 additions & 524 deletions
Large diffs are not rendered by default.

dmriprep/cli/tests/test_parser.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
"""Test parser."""
2+
from packaging.version import Version
3+
import pytest
4+
from ..parser import _build_parser
5+
from .. import version as _version
6+
from ... import config
7+
8+
MIN_ARGS = ['data/', 'out/', 'participant']
9+
10+
11+
@pytest.mark.parametrize('args,code', [
12+
([], 2),
13+
(MIN_ARGS, 2), # bids_dir does not exist
14+
(MIN_ARGS + ['--fs-license-file'], 2),
15+
(MIN_ARGS + ['--fs-license-file', 'fslicense.txt'], 2),
16+
])
17+
def test_parser_errors(args, code):
18+
"""Check behavior of the parser."""
19+
with pytest.raises(SystemExit) as error:
20+
_build_parser().parse_args(args)
21+
22+
assert error.value.code == code
23+
24+
25+
@pytest.mark.parametrize('args', [
26+
MIN_ARGS,
27+
MIN_ARGS + ['--fs-license-file'],
28+
])
29+
def test_parser_valid(tmp_path, args):
30+
"""Check valid arguments."""
31+
datapath = (tmp_path / 'data').absolute()
32+
datapath.mkdir(exist_ok=True)
33+
args[0] = str(datapath)
34+
35+
if '--fs-license-file' in args:
36+
_fs_file = tmp_path / 'license.txt'
37+
_fs_file.write_text('')
38+
args.insert(args.index('--fs-license-file') + 1,
39+
str(_fs_file.absolute()))
40+
41+
opts = _build_parser().parse_args(args)
42+
43+
assert opts.bids_dir == datapath
44+
45+
46+
@pytest.mark.parametrize('argval,gb', [
47+
('1G', 1),
48+
('1GB', 1),
49+
('1000', 1), # Default units are MB
50+
('32000', 32), # Default units are MB
51+
('4000', 4), # Default units are MB
52+
('1000M', 1),
53+
('1000MB', 1),
54+
('1T', 1000),
55+
('1TB', 1000),
56+
('%dK' % 1e6, 1),
57+
('%dKB' % 1e6, 1),
58+
('%dB' % 1e9, 1),
59+
])
60+
def test_memory_arg(tmp_path, argval, gb):
61+
"""Check the correct parsing of the memory argument."""
62+
datapath = (tmp_path / 'data').absolute()
63+
datapath.mkdir(exist_ok=True)
64+
_fs_file = tmp_path / 'license.txt'
65+
_fs_file.write_text('')
66+
67+
args = MIN_ARGS + ['--fs-license-file', str(_fs_file)] \
68+
+ ['--mem', argval]
69+
args[0] = str(datapath)
70+
opts = _build_parser().parse_args(args)
71+
72+
assert opts.memory_gb == gb
73+
74+
75+
@pytest.mark.parametrize('current,latest', [
76+
('1.0.0', '1.3.2'),
77+
('1.3.2', '1.3.2')
78+
])
79+
def test_get_parser_update(monkeypatch, capsys, current, latest):
80+
"""Make sure the out-of-date banner is shown."""
81+
expectation = Version(current) < Version(latest)
82+
83+
def _mock_check_latest(*args, **kwargs):
84+
return Version(latest)
85+
86+
monkeypatch.setattr(config.environment, 'version', current)
87+
monkeypatch.setattr(_version, 'check_latest', _mock_check_latest)
88+
89+
_build_parser()
90+
captured = capsys.readouterr().err
91+
92+
msg = """\
93+
You are using dMRIPrep-%s, and a newer version of dMRIPrep is available: %s.
94+
Please check out our documentation about how and when to upgrade:
95+
https://dmriprep.readthedocs.io/en/latest/faq.html#upgrading""" % (current, latest)
96+
97+
assert (msg in captured) is expectation
98+
99+
100+
@pytest.mark.parametrize('flagged', [
101+
(True, None),
102+
(True, 'random reason'),
103+
(False, None),
104+
])
105+
def test_get_parser_blacklist(monkeypatch, capsys, flagged):
106+
"""Make sure the blacklisting banner is shown."""
107+
def _mock_is_bl(*args, **kwargs):
108+
return flagged
109+
110+
monkeypatch.setattr(_version, 'is_flagged', _mock_is_bl)
111+
112+
_build_parser()
113+
captured = capsys.readouterr().err
114+
115+
assert ('FLAGGED' in captured) is flagged[0]
116+
if flagged[0]:
117+
assert ((flagged[1] or 'reason: unknown') in captured)

dmriprep/cli/tests/test_run.py

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)