Skip to content

Commit 993deb3

Browse files
committed
Merge pull request #450 from satra/enh/booleantraits
Enh/booleantraits
2 parents 1c69d33 + 23d9502 commit 993deb3

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

nipype/interfaces/base.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,20 +1132,14 @@ def _format_arg(self, name, trait_spec, value):
11321132
Formats a trait containing argstr metadata
11331133
"""
11341134
argstr = trait_spec.argstr
1135+
iflogger.debug('%s_%s' %(name, str(value)))
11351136
if trait_spec.is_trait_type(traits.Bool):
11361137
if value:
11371138
# Boolean options have no format string. Just append options
11381139
# if True.
11391140
return argstr
11401141
else:
1141-
# If we end up here we're trying to add a Boolean to
1142-
# the arg string but whose value is False. This
1143-
# should not happen, something went wrong upstream.
1144-
# Raise an error.
1145-
msg = "Object '%s' attempting to format argument " \
1146-
"string for attr '%s' with value '%s'." \
1147-
% (self, trait_spec.name, value)
1148-
raise ValueError(msg)
1142+
return None
11491143
#traits.Either turns into traits.TraitCompound and does not have any inner_traits
11501144
elif trait_spec.is_trait_type(traits.List) \
11511145
or (trait_spec.is_trait_type(traits.TraitCompound) \
@@ -1201,6 +1195,8 @@ def _parse_inputs(self, skip=None):
12011195
else:
12021196
continue
12031197
arg = self._format_arg(name, spec, value)
1198+
if arg is None:
1199+
continue
12041200
pos = spec.position
12051201
if pos is not None:
12061202
if pos >= 0:

nipype/interfaces/slicer/generate_classes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def generate_class(module,launcher):
101101
#self._outputs_nodes = []
102102

103103
class_string = "\"\"\""
104-
105-
104+
105+
106106

107107
for desc_str in ['title', 'category', 'description', 'version',
108108
'documentation-url', 'license', 'contributor',

nipype/interfaces/tests/test_base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class CommandLineInputSpec1(nib.CommandLineInputSpec):
259259
position=-1)
260260
noo = nib.traits.Int(argstr='-x %d', desc='an int')
261261
roo = nib.traits.Str(desc='not on command line')
262+
soo = nib.traits.Bool(argstr="-soo")
262263
nib.CommandLine.input_spec = CommandLineInputSpec1
263264
ci4 = nib.CommandLine(command='cmd')
264265
ci4.inputs.foo = 'foo'
@@ -267,10 +268,15 @@ class CommandLineInputSpec1(nib.CommandLineInputSpec):
267268
ci4.inputs.moo = [1, 2, 3]
268269
ci4.inputs.noo = 0
269270
ci4.inputs.roo = 'hello'
271+
ci4.inputs.soo = False
270272
cmd = ci4._parse_inputs()
271273
yield assert_equal, cmd[0], '-g'
272274
yield assert_equal, cmd[-1], '-i 1 -i 2 -i 3'
273275
yield assert_true, 'hello' not in ' '.join(cmd)
276+
yield assert_true, '-soo' not in ' '.join(cmd)
277+
ci4.inputs.soo = True
278+
cmd = ci4._parse_inputs()
279+
yield assert_true, '-soo' in ' '.join(cmd)
274280

275281
class CommandLineInputSpec2(nib.CommandLineInputSpec):
276282
foo = nib.File(argstr='%s', desc='a str', genfile=True)

0 commit comments

Comments
 (0)