5656
5757
5858class Str (traits .Unicode ):
59- pass
60-
59+ """Replacement for the default traits.Str based in bytes"""
6160
6261traits .Str = Str
6362
6463
6564class NipypeInterfaceError (Exception ):
65+ """Custom error for interfaces"""
66+
6667 def __init__ (self , value ):
6768 self .value = value
6869
@@ -1016,31 +1017,6 @@ def _check_version_requirements(self, trait_object, raise_exception=True):
10161017 version , max_ver ))
10171018 return unavailable_traits
10181019
1019- def _run_wrapper (self , runtime ):
1020- if self ._redirect_x :
1021- try :
1022- from xvfbwrapper import Xvfb
1023- except ImportError :
1024- iflogger .error ('Xvfb wrapper could not be imported' )
1025- raise
1026-
1027- vdisp = Xvfb (nolisten = 'tcp' )
1028- vdisp .start ()
1029- try :
1030- vdisp_num = vdisp .new_display
1031- except AttributeError : # outdated version of xvfbwrapper
1032- vdisp_num = vdisp .vdisplay_num
1033-
1034- iflogger .info ('Redirecting X to :%d' % vdisp_num )
1035- runtime .environ ['DISPLAY' ] = ':%d' % vdisp_num
1036-
1037- runtime = self ._run_interface (runtime )
1038-
1039- if self ._redirect_x :
1040- vdisp .stop ()
1041-
1042- return runtime
1043-
10441020 def _run_interface (self , runtime ):
10451021 """ Core function that executes interface
10461022 """
@@ -1082,6 +1058,9 @@ def run(self, **inputs):
10821058 store_provenance = str2bool (config .get (
10831059 'execution' , 'write_provenance' , 'false' ))
10841060 env = deepcopy (dict (os .environ ))
1061+ if self ._redirect_x :
1062+ env ['DISPLAY' ] = config .get_display ()
1063+
10851064 runtime = Bunch (cwd = os .getcwd (),
10861065 returncode = None ,
10871066 duration = None ,
@@ -1104,8 +1083,9 @@ def run(self, **inputs):
11041083 # Grab inputs now, as they should not change during execution
11051084 inputs = self .inputs .get_traitsfree ()
11061085 outputs = None
1086+
11071087 try :
1108- runtime = self ._run_wrapper (runtime )
1088+ runtime = self ._run_interface (runtime )
11091089 outputs = self .aggregate_outputs (runtime )
11101090 except Exception as e :
11111091 import traceback
@@ -1315,21 +1295,14 @@ def _canonicalize_env(env):
13151295 return out_env
13161296
13171297
1318- def run_command (runtime , output = None , timeout = 0.01 , redirect_x = False ):
1298+ def run_command (runtime , output = None , timeout = 0.01 ):
13191299 """Run a command, read stdout and stderr, prefix with timestamp.
13201300
13211301 The returned runtime contains a merged stdout+stderr log with timestamps
13221302 """
13231303
13241304 # Init variables
13251305 cmdline = runtime .cmdline
1326-
1327- if redirect_x :
1328- exist_xvfb , _ = _exists_in_path ('xvfb-run' , runtime .environ )
1329- if not exist_xvfb :
1330- raise RuntimeError ('Xvfb was not found, X redirection aborted' )
1331- cmdline = 'xvfb-run -a ' + cmdline
1332-
13331306 env = _canonicalize_env (runtime .environ )
13341307
13351308 default_encoding = locale .getdefaultlocale ()[1 ]
@@ -1586,17 +1559,7 @@ def raise_exception(self, runtime):
15861559 ** runtime .dictcopy ()))
15871560
15881561 def _get_environ (self ):
1589- out_environ = {}
1590- if not self ._redirect_x :
1591- try :
1592- display_var = config .get ('execution' , 'display_variable' )
1593- out_environ = {'DISPLAY' : display_var }
1594- except NoOptionError :
1595- pass
1596- iflogger .debug (out_environ )
1597- if isdefined (self .inputs .environ ):
1598- out_environ .update (self .inputs .environ )
1599- return out_environ
1562+ return getattr (self .inputs , 'environ' , {})
16001563
16011564 def version_from_command (self , flag = '-v' ):
16021565 cmdname = self .cmd .split ()[0 ]
@@ -1613,10 +1576,6 @@ def version_from_command(self, flag='-v'):
16131576 o , e = proc .communicate ()
16141577 return o
16151578
1616- def _run_wrapper (self , runtime ):
1617- runtime = self ._run_interface (runtime )
1618- return runtime
1619-
16201579 def _run_interface (self , runtime , correct_return_codes = (0 ,)):
16211580 """Execute command via subprocess
16221581
@@ -1648,8 +1607,7 @@ def _run_interface(self, runtime, correct_return_codes=(0,)):
16481607
16491608 runtime .command_path = cmd_path
16501609 runtime .dependencies = get_dependencies (executable_name , runtime .environ )
1651- runtime = run_command (runtime , output = self .terminal_output ,
1652- redirect_x = self ._redirect_x )
1610+ runtime = run_command (runtime , output = self .inputs .terminal_output )
16531611 if runtime .returncode is None or \
16541612 runtime .returncode not in correct_return_codes :
16551613 self .raise_exception (runtime )
0 commit comments