Skip to content

Commit 5d442f1

Browse files
committed
Merge pull request #685 from satra/fix/mandatory
fix: make sure mandatory=False items are displayed
2 parents 3d7c048 + c7fdbb5 commit 5d442f1

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

nipype/interfaces/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,12 +779,14 @@ def _inputs_help(cls):
779779
return helpstr
780780

781781
manhelpstr = ['', '\t[Mandatory]']
782-
for name, spec in sorted(inputs.traits(mandatory=True).items()):
782+
mandatory_items = inputs.traits(mandatory=True)
783+
for name, spec in sorted(mandatory_items.items()):
783784
manhelpstr += cls._get_trait_desc(inputs, name, spec)
784785

785786
opthelpstr = ['', '\t[Optional]']
786-
for name, spec in sorted(inputs.traits(mandatory=None,
787-
transient=None).items()):
787+
for name, spec in sorted(inputs.traits(transient=None).items()):
788+
if spec in mandatory_items:
789+
continue
788790
opthelpstr += cls._get_trait_desc(inputs, name, spec)
789791

790792
if manhelpstr:

nipype/interfaces/tests/test_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ def test_BaseInterface():
245245
yield assert_equal, nib.BaseInterface.help(), None
246246
yield assert_equal, nib.BaseInterface._get_filecopy_info(), []
247247

248-
249248
class InputSpec(nib.TraitedSpec):
250249
foo = nib.traits.Int(desc='a random int')
251250
goo = nib.traits.Int(desc='a random int', mandatory=True)
251+
moo = nib.traits.Int(desc='a random int', mandatory=False)
252252
hoo = nib.traits.Int(desc='a random int', usedefault=True)
253253
zoo = nib.File(desc='a file', copyfile=False)
254254
woo = nib.File(desc='a file', copyfile=True)
@@ -258,6 +258,7 @@ class DerivedInterface(nib.BaseInterface):
258258
input_spec = InputSpec
259259

260260
yield assert_equal, DerivedInterface.help(), None
261+
yield assert_true, 'moo' in ''.join(DerivedInterface._inputs_help())
261262
yield assert_equal, DerivedInterface()._outputs(), None
262263
yield assert_equal, DerivedInterface._get_filecopy_info()[0]['key'], 'woo'
263264
yield assert_true, DerivedInterface._get_filecopy_info()[0]['copy']

0 commit comments

Comments
 (0)