Skip to content

Commit 72c11d6

Browse files
authored
Merge pull request #3414 from skoudoro/fix-3411
[FIX] Import error for nipype.interfaces.dipy.base
2 parents adab17d + 37d0fa9 commit 72c11d6

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

nipype/info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def get_nipype_gitversion():
162162
EXTRA_REQUIRES = {
163163
"data": ["datalad"],
164164
"doc": [
165-
"dipy!=1.4.1",
165+
"dipy",
166166
"ipython",
167167
"matplotlib",
168168
"nbsphinx",
@@ -172,7 +172,7 @@ def get_nipype_gitversion():
172172
"sphinxcontrib-napoleon",
173173
],
174174
"duecredit": ["duecredit"],
175-
"nipy": ["nitime", "nilearn", "dipy!=1.4.1", "nipy", "matplotlib"],
175+
"nipy": ["nitime", "nilearn", "dipy", "nipy", "matplotlib"],
176176
"profiler": ["psutil>=5.0"],
177177
"pybids": ["pybids>=0.7.0"],
178178
"specs": ["black"],

nipype/interfaces/dipy/base.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,21 @@
2727

2828

2929
def no_dipy():
30-
"""Check if dipy is available"""
30+
"""Check if dipy is available."""
3131
global HAVE_DIPY
3232
return not HAVE_DIPY
3333

3434

3535
def dipy_version():
36-
"""Check dipy version"""
36+
"""Check dipy version."""
3737
if no_dipy():
3838
return None
3939

4040
return dipy.__version__
4141

4242

4343
class DipyBaseInterface(LibraryBaseInterface):
44-
"""
45-
A base interface for py:mod:`dipy` computations
46-
"""
44+
"""A base interface for py:mod:`dipy` computations."""
4745

4846
_pkg = "dipy"
4947

@@ -57,9 +55,7 @@ class DipyBaseInterfaceInputSpec(BaseInterfaceInputSpec):
5755

5856

5957
class DipyDiffusionInterface(DipyBaseInterface):
60-
"""
61-
A base interface for py:mod:`dipy` computations
62-
"""
58+
"""A base interface for py:mod:`dipy` computations."""
6359

6460
input_spec = DipyBaseInterfaceInputSpec
6561

@@ -90,6 +86,24 @@ def _gen_filename(self, name, ext=None):
9086
return out_prefix + "_" + name + ext
9187

9288

89+
def get_default_args(func):
90+
"""Return optional arguments of a function.
91+
92+
Parameters
93+
----------
94+
func: callable
95+
96+
Returns
97+
-------
98+
dict
99+
100+
"""
101+
signature = inspect.signature(func)
102+
return {k: v.default for k, v in signature.parameters.items()
103+
if v.default is not inspect.Parameter.empty
104+
}
105+
106+
93107
def convert_to_traits_type(dipy_type, is_file=False):
94108
"""Convert DIPY type to Traits type."""
95109
dipy_type = dipy_type.lower()
@@ -189,7 +203,7 @@ def dipy_to_nipype_interface(cls_name, dipy_flow, BaseClass=DipyBaseInterface):
189203
parser = IntrospectiveArgumentParser()
190204
flow = dipy_flow()
191205
parser.add_workflow(flow)
192-
default_values = inspect.getfullargspec(flow.run).defaults
206+
default_values = list(get_default_args(flow.run).values())
193207
optional_params = [
194208
args + (val,) for args, val in zip(parser.optional_parameters, default_values)
195209
]

nipype/interfaces/dipy/tests/test_base.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from packaging.version import Version
23
from collections import namedtuple
34
from ...base import traits, File, TraitedSpec, BaseInterfaceInputSpec
45
from ..base import (
@@ -8,6 +9,8 @@
89
DipyBaseInterface,
910
no_dipy,
1011
get_dipy_workflows,
12+
get_default_args,
13+
dipy_version
1114
)
1215

1316

@@ -112,6 +115,32 @@ def test_create_interface_specs():
112115
assert "out_params" in current_params.keys()
113116

114117

118+
@pytest.mark.skipif(no_dipy() or Version(dipy_version()) < Version("1.4"),
119+
reason="DIPY >=1.4 required")
120+
def test_get_default_args():
121+
from dipy.utils.deprecator import deprecated_params
122+
123+
def test(dummy=11, x=3):
124+
return dummy, x
125+
126+
@deprecated_params('x', None, '0.3', '0.5', alternative='test2.y')
127+
def test2(dummy=11, x=3):
128+
return dummy, x
129+
130+
@deprecated_params(['dummy', 'x'], None, '0.3', alternative='test2.y')
131+
def test3(dummy=11, x=3):
132+
return dummy, x
133+
134+
@deprecated_params(['dummy', 'x'], None, '0.3', '0.5',
135+
alternative='test2.y')
136+
def test4(dummy=11, x=3):
137+
return dummy, x
138+
139+
expected_res = {'dummy': 11, 'x': 3}
140+
for func in [test, test2, test3, test4]:
141+
assert get_default_args(func) == expected_res
142+
143+
115144
@pytest.mark.skipif(no_dipy(), reason="DIPY is not installed")
116145
def test_dipy_to_nipype_interface():
117146
from dipy.workflows.workflow import Workflow
@@ -178,3 +207,4 @@ def test_get_dipy_workflows():
178207
test_convert_to_traits_type()
179208
test_create_interface_specs()
180209
test_dipy_to_nipype_interface()
210+
test_get_default_args()

0 commit comments

Comments
 (0)