Skip to content

Commit 80e46d3

Browse files
committed
Merge pull request #690 from satra/fix/inputtemplate
fix: allow for template specification in at the input level
2 parents a298cfd + 57857cd commit 80e46d3

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

nipype/interfaces/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,10 +1450,13 @@ def _format_arg(self, name, trait_spec, value):
14501450
def _filename_from_source(self, name):
14511451
trait_spec = self.inputs.trait(name)
14521452
retval = getattr(self.inputs, name)
1453-
if not isdefined(retval):
1453+
if not isdefined(retval) or "%s" in retval:
14541454
if not trait_spec.name_source:
14551455
return retval
1456-
name_template = trait_spec.name_template
1456+
if isdefined(retval) and "%s" in retval:
1457+
name_template = retval
1458+
else:
1459+
name_template = trait_spec.name_template
14571460
if not name_template:
14581461
name_template = "%s_generated"
14591462
if isinstance(trait_spec.name_source, list):

nipype/interfaces/tests/test_base.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
assert_true, assert_false, with_setup, package_check,
99
skipif)
1010
import nipype.interfaces.base as nib
11+
from nipype.utils.filemanip import split_filename
1112
from nipype.interfaces.base import Undefined, config
1213
from traits.testing.nose_tools import skip
1314

@@ -171,6 +172,26 @@ class DeprecationSpec3(nib.TraitedSpec):
171172
yield assert_equal, spec_instance.foo, Undefined
172173
yield assert_equal, spec_instance.bar, 1
173174

175+
def test_namesource():
176+
tmp_infile = setup_file()
177+
tmpd, nme, ext = split_filename(tmp_infile)
178+
pwd = os.getcwd()
179+
os.chdir(tmpd)
180+
class spec2(nib.CommandLineInputSpec):
181+
moo = nib.File(name_source=['doo'], hash_files=False, argstr="%s",
182+
position=2)
183+
doo = nib.File(exists=True, argstr="%s", position=1)
184+
class TestName(nib.CommandLine):
185+
_cmd = "mycommand"
186+
input_spec = spec2
187+
testobj = TestName()
188+
testobj.inputs.doo = tmp_infile
189+
yield assert_true, '%s_generated' % nme in testobj.cmdline
190+
testobj.inputs.moo = "my_%s_template"
191+
yield assert_true, 'my_%s_template' % nme in testobj.cmdline
192+
os.chdir(pwd)
193+
teardown_file(tmpd)
194+
174195
def checknose():
175196
"""check version of nose for known incompatability"""
176197
mod = __import__('nose')

0 commit comments

Comments
 (0)