2424from datetime import datetime as dt
2525from dateutil .parser import parse as parseutc
2626from warnings import warn
27- from nipype .external import six
2827
2928
3029from .traits_extension import (traits , Undefined , TraitDictObject ,
@@ -542,7 +541,7 @@ def _get_sorteddict(self, object, dictwithhash=False, hash_method=None,
542541 out = tuple (out )
543542 else :
544543 if isdefined (object ):
545- if (hash_files and isinstance (object , six . string_types ) and
544+ if (hash_files and isinstance (object , str ) and
546545 os .path .isfile (object )):
547546 if hash_method is None :
548547 hash_method = config .get ('execution' , 'hash_method' )
@@ -985,7 +984,7 @@ def run(self, **inputs):
985984 else :
986985 inputs_str = ''
987986
988- if len (e .args ) == 1 and isinstance (e .args [0 ], six . string_types ):
987+ if len (e .args ) == 1 and isinstance (e .args [0 ], str ):
989988 e .args = (e .args [0 ] + " " .join ([message , inputs_str ]),)
990989 else :
991990 e .args += (message , )
@@ -1469,6 +1468,7 @@ def _format_arg(self, name, trait_spec, value):
14691468 def _filename_from_source (self , name ):
14701469 trait_spec = self .inputs .trait (name )
14711470 retval = getattr (self .inputs , name )
1471+
14721472 if not isdefined (retval ) or "%s" in retval :
14731473 if not trait_spec .name_source :
14741474 return retval
@@ -1478,26 +1478,37 @@ def _filename_from_source(self, name):
14781478 name_template = trait_spec .name_template
14791479 if not name_template :
14801480 name_template = "%s_generated"
1481- if isinstance (trait_spec .name_source , list ):
1482- for ns in trait_spec .name_source :
1483- if isdefined (getattr (self .inputs , ns )):
1484- name_source = ns
1485- break
1481+
1482+ ns = trait_spec .name_source
1483+ while isinstance (ns , list ):
1484+ if len (ns ) > 1 :
1485+ iflogger .warn ('Only one name_source per trait is allowed' )
1486+ ns = ns [0 ]
1487+
1488+ if not isinstance (ns , basestring ):
1489+ raise ValueError (('name_source of \' %s\' trait sould be an '
1490+ 'input trait name' ) % name )
1491+
1492+ if isdefined (getattr (self .inputs , ns )):
1493+ name_source = ns
1494+ source = getattr (self .inputs , name_source )
1495+ while isinstance (source , list ):
1496+ source = source [0 ]
1497+
1498+ # special treatment for files
1499+ try :
1500+ _ , base , _ = split_filename (source )
1501+ except AttributeError :
1502+ base = source
14861503 else :
1487- name_source = trait_spec .name_source
1488- source = getattr (self .inputs , name_source )
1489- while isinstance (source , list ):
1490- source = source [0 ]
1491- #special treatment for files
1492- try :
1493- _ , base , _ = split_filename (source )
1494- except AttributeError :
1495- base = source
1504+ base = self ._filename_from_source (ns )
1505+
14961506 retval = name_template % base
14971507 _ , _ , ext = split_filename (retval )
14981508 if trait_spec .keep_extension and ext :
14991509 return retval
15001510 return self ._overload_extension (retval , name )
1511+
15011512 return retval
15021513
15031514 def _gen_filename (self , name ):
@@ -1513,7 +1524,7 @@ def _list_outputs(self):
15131524 outputs = self .output_spec ().get ()
15141525 for name , trait_spec in traits .iteritems ():
15151526 out_name = name
1516- if trait_spec .output_name != None :
1527+ if trait_spec .output_name is not None :
15171528 out_name = trait_spec .output_name
15181529 outputs [out_name ] = \
15191530 os .path .abspath (self ._filename_from_source (name ))
0 commit comments