5454
5555
5656class Str (traits .Unicode ):
57- pass
58-
57+ """Replacement for the default traits.Str based in bytes"""
5958
6059traits .Str = Str
6160
6261
6362class NipypeInterfaceError (Exception ):
63+ """Custom error for interfaces"""
64+
6465 def __init__ (self , value ):
6566 self .value = value
6667
@@ -1014,31 +1015,6 @@ def _check_version_requirements(self, trait_object, raise_exception=True):
10141015 version , max_ver ))
10151016 return unavailable_traits
10161017
1017- def _run_wrapper (self , runtime ):
1018- if self ._redirect_x :
1019- try :
1020- from xvfbwrapper import Xvfb
1021- except ImportError :
1022- iflogger .error ('Xvfb wrapper could not be imported' )
1023- raise
1024-
1025- vdisp = Xvfb (nolisten = 'tcp' )
1026- vdisp .start ()
1027- try :
1028- vdisp_num = vdisp .new_display
1029- except AttributeError : # outdated version of xvfbwrapper
1030- vdisp_num = vdisp .vdisplay_num
1031-
1032- iflogger .info ('Redirecting X to :%d' % vdisp_num )
1033- runtime .environ ['DISPLAY' ] = ':%d' % vdisp_num
1034-
1035- runtime = self ._run_interface (runtime )
1036-
1037- if self ._redirect_x :
1038- vdisp .stop ()
1039-
1040- return runtime
1041-
10421018 def _run_interface (self , runtime ):
10431019 """ Core function that executes interface
10441020 """
@@ -1080,6 +1056,9 @@ def run(self, **inputs):
10801056 store_provenance = str2bool (config .get (
10811057 'execution' , 'write_provenance' , 'false' ))
10821058 env = deepcopy (dict (os .environ ))
1059+ if self ._redirect_x :
1060+ env ['DISPLAY' ] = config .get_display ()
1061+
10831062 runtime = Bunch (cwd = os .getcwd (),
10841063 returncode = None ,
10851064 duration = None ,
@@ -1102,8 +1081,9 @@ def run(self, **inputs):
11021081 # Grab inputs now, as they should not change during execution
11031082 inputs = self .inputs .get_traitsfree ()
11041083 outputs = None
1084+
11051085 try :
1106- runtime = self ._run_wrapper (runtime )
1086+ runtime = self ._run_interface (runtime )
11071087 outputs = self .aggregate_outputs (runtime )
11081088 except Exception as e :
11091089 import traceback
@@ -1313,21 +1293,14 @@ def _canonicalize_env(env):
13131293 return out_env
13141294
13151295
1316- def run_command (runtime , output = None , timeout = 0.01 , redirect_x = False ):
1296+ def run_command (runtime , output = None , timeout = 0.01 ):
13171297 """Run a command, read stdout and stderr, prefix with timestamp.
13181298
13191299 The returned runtime contains a merged stdout+stderr log with timestamps
13201300 """
13211301
13221302 # Init variables
13231303 cmdline = runtime .cmdline
1324-
1325- if redirect_x :
1326- exist_xvfb , _ = _exists_in_path ('xvfb-run' , runtime .environ )
1327- if not exist_xvfb :
1328- raise RuntimeError ('Xvfb was not found, X redirection aborted' )
1329- cmdline = 'xvfb-run -a ' + cmdline
1330-
13311304 env = _canonicalize_env (runtime .environ )
13321305
13331306 default_encoding = locale .getdefaultlocale ()[1 ]
@@ -1564,17 +1537,7 @@ def help(cls, returnhelp=False):
15641537 print (allhelp )
15651538
15661539 def _get_environ (self ):
1567- out_environ = {}
1568- if not self ._redirect_x :
1569- try :
1570- display_var = config .get ('execution' , 'display_variable' )
1571- out_environ = {'DISPLAY' : display_var }
1572- except NoOptionError :
1573- pass
1574- iflogger .debug (out_environ )
1575- if isdefined (self .inputs .environ ):
1576- out_environ .update (self .inputs .environ )
1577- return out_environ
1540+ return getattr (self .inputs , 'environ' , {})
15781541
15791542 def version_from_command (self , flag = '-v' ):
15801543 cmdname = self .cmd .split ()[0 ]
@@ -1591,10 +1554,6 @@ def version_from_command(self, flag='-v'):
15911554 o , e = proc .communicate ()
15921555 return o
15931556
1594- def _run_wrapper (self , runtime ):
1595- runtime = self ._run_interface (runtime )
1596- return runtime
1597-
15981557 def _run_interface (self , runtime , correct_return_codes = (0 ,)):
15991558 """Execute command via subprocess
16001559
@@ -1622,8 +1581,7 @@ def _run_interface(self, runtime, correct_return_codes=(0,)):
16221581 setattr (runtime , 'command_path' , cmd_path )
16231582 setattr (runtime , 'dependencies' , get_dependencies (executable_name ,
16241583 runtime .environ ))
1625- runtime = run_command (runtime , output = self .inputs .terminal_output ,
1626- redirect_x = self ._redirect_x )
1584+ runtime = run_command (runtime , output = self .inputs .terminal_output )
16271585 if runtime .returncode is None or \
16281586 runtime .returncode not in correct_return_codes :
16291587 self .raise_exception (runtime )
0 commit comments