24
24
from datetime import datetime as dt
25
25
from dateutil .parser import parse as parseutc
26
26
from warnings import warn
27
- from nipype .external import six
28
27
29
28
30
29
from .traits_extension import (traits , Undefined , TraitDictObject ,
@@ -542,7 +541,7 @@ def _get_sorteddict(self, object, dictwithhash=False, hash_method=None,
542
541
out = tuple (out )
543
542
else :
544
543
if isdefined (object ):
545
- if (hash_files and isinstance (object , six . string_types ) and
544
+ if (hash_files and isinstance (object , str ) and
546
545
os .path .isfile (object )):
547
546
if hash_method is None :
548
547
hash_method = config .get ('execution' , 'hash_method' )
@@ -985,7 +984,7 @@ def run(self, **inputs):
985
984
else :
986
985
inputs_str = ''
987
986
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 ):
989
988
e .args = (e .args [0 ] + " " .join ([message , inputs_str ]),)
990
989
else :
991
990
e .args += (message , )
@@ -1469,6 +1468,7 @@ def _format_arg(self, name, trait_spec, value):
1469
1468
def _filename_from_source (self , name ):
1470
1469
trait_spec = self .inputs .trait (name )
1471
1470
retval = getattr (self .inputs , name )
1471
+
1472
1472
if not isdefined (retval ) or "%s" in retval :
1473
1473
if not trait_spec .name_source :
1474
1474
return retval
@@ -1478,26 +1478,37 @@ def _filename_from_source(self, name):
1478
1478
name_template = trait_spec .name_template
1479
1479
if not name_template :
1480
1480
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
1486
1503
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
+
1496
1506
retval = name_template % base
1497
1507
_ , _ , ext = split_filename (retval )
1498
1508
if trait_spec .keep_extension and ext :
1499
1509
return retval
1500
1510
return self ._overload_extension (retval , name )
1511
+
1501
1512
return retval
1502
1513
1503
1514
def _gen_filename (self , name ):
@@ -1513,7 +1524,7 @@ def _list_outputs(self):
1513
1524
outputs = self .output_spec ().get ()
1514
1525
for name , trait_spec in traits .iteritems ():
1515
1526
out_name = name
1516
- if trait_spec .output_name != None :
1527
+ if trait_spec .output_name is not None :
1517
1528
out_name = trait_spec .output_name
1518
1529
outputs [out_name ] = \
1519
1530
os .path .abspath (self ._filename_from_source (name ))
0 commit comments