Skip to content

Commit fe29433

Browse files
committed
fix: keep_extension metadata behavior has now been fixed
1 parent 0da735e commit fe29433

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

doc/devel/cmd_interface_devel.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,13 @@ output_name (optional)
198198
name of the output (if this is not set same name as the input will be
199199
assumed)
200200

201-
keep_extension (optional - not used)
202-
if you want the extension from the input to be kept
201+
keep_extension (optional)
202+
if you want the extension from the input or name_template to be kept. The
203+
name_template extension always overrides the input extension.
203204

204205
In addition one can add functionality to your class or base class, to allow
205-
changing extensions specific to package or interface
206+
changing extensions specific to package or interface. This overload function is
207+
trigerred only if keep_extension is not defined.
206208

207209
.. testcode::
208210

nipype/interfaces/base.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,7 @@ def _filename_from_source(self, name, chain=None):
15601560

15611561
trait_spec = self.inputs.trait(name)
15621562
retval = getattr(self.inputs, name)
1563-
1563+
source_ext = None
15641564
if not isdefined(retval) or "%s" in retval:
15651565
if not trait_spec.name_source:
15661566
return retval
@@ -1589,7 +1589,7 @@ def _filename_from_source(self, name, chain=None):
15891589

15901590
# special treatment for files
15911591
try:
1592-
_, base, _ = split_filename(source)
1592+
_, base, source_ext = split_filename(source)
15931593
except AttributeError:
15941594
base = source
15951595
else:
@@ -1598,14 +1598,17 @@ def _filename_from_source(self, name, chain=None):
15981598

15991599
chain.append(name)
16001600
base = self._filename_from_source(ns, chain)
1601+
if isdefined(base):
1602+
_, _, source_ext = split_filename(base)
16011603

16021604
chain = None
16031605
retval = name_template % base
16041606
_, _, ext = split_filename(retval)
1605-
if trait_spec.keep_extension and ext:
1606-
return retval
1607-
return self._overload_extension(retval, name)
1608-
1607+
if trait_spec.keep_extension and (ext or source_ext):
1608+
if (ext is None or not ext) and source_ext:
1609+
retval = retval + source_ext
1610+
else:
1611+
retval = self._overload_extension(retval, name)
16091612
return retval
16101613

16111614
def _gen_filename(self, name):

0 commit comments

Comments
 (0)