Repository: nipy/nipype

Issue:
Irrelevant Environment Variables causing hash problems
Changing the environment variable DISPLAY will cause nodes to begin to rerun unnecessarily.
The 'environ' input claims to have differing values:

Error from a multisubject connectivity pipeline study (for a cmtk.Parcellate node):

" values differ in fields: environ: {'DISPLAY': ':1', 'SUBJECTS_DIR': '/media/Mobsol/subjects'} != {u'SUBJECTS_DIR': u'/media/Mobsol/subjects'}"

Removing:

display_variable = :1

from the nipype.cfg file fixed it.

Maybe we can work around this problem with a list of relevant environment variables (e.g. FSLOUTPUTTYPE, FSL_DIR, etc..)?



Discussion:

Resolving patch:
diff --git a/nipype/interfaces/base.py b/nipype/interfaces/base.py
--- a/nipype/interfaces/base.py
+++ b/nipype/interfaces/base.py
@@ -1033,11 +1033,6 @@ def __init__(self, command=None, **inputs):
             raise Exception("Missing command")
         if command:
             self._cmd = command
-        try:
-            display_var = config.get('execution', 'display_variable')
-            self.inputs.environ['DISPLAY'] = display_var
-        except NoOptionError:
-            pass
 
     @property
     def cmd(self):
@@ -1087,7 +1082,16 @@ def _run_interface(self, runtime):
         setattr(runtime, 'stdout', None)
         setattr(runtime, 'stderr', None)
         setattr(runtime, 'cmdline', self.cmdline)
-        runtime.environ.update(self.inputs.environ)
+        out_environ = {}
+        try:
+            display_var = config.get('execution', 'display_variable')
+            out_environ = {'DISPLAY': display_var}
+        except NoOptionError:
+            pass
+        iflogger.info(out_environ)
+        if isdefined(self.inputs.environ):
+            out_environ.update(self.inputs.environ)
+        runtime.environ.update(out_environ)
         if not self._exists_in_path(self.cmd.split()[0]):
             raise IOError("%s could not be found on host %s" % (self.cmd.split()[0],
                                                                 runtime.hostname))
diff --git a/nipype/utils/config.py b/nipype/utils/config.py
--- a/nipype/utils/config.py
+++ b/nipype/utils/config.py
@@ -32,6 +32,7 @@
 [execution]
 create_report = true
 crashdump_dir = %s
+display_variable = :1
 hash_method = timestamp
 job_finished_timeout = 5
 keep_inputs = false


Test patch:
diff --git a/nipype/interfaces/tests/test_base.py b/nipype/interfaces/tests/test_base.py
--- a/nipype/interfaces/tests/test_base.py
+++ b/nipype/interfaces/tests/test_base.py
@@ -263,3 +263,18 @@ def _gen_filename(self, name):
     ci6 = DerivedClass(command='cmd')
     yield assert_equal, ci6._parse_inputs()[0], 'filename'
     nib.CommandLine.input_spec = nib.CommandLineInputSpec
+
+
+def test_Commandline_environ():
+    from nipype import config
+    config.set_default_config()
+    ci3 = nib.CommandLine(command='echo')
+    res = ci3.run()
+    yield assert_equal, res.runtime.environ['DISPLAY'], ':1'
+    config.set('execution', 'display_variable', ':3')
+    res = ci3.run()
+    yield assert_false, 'DISPLAY' in ci3.inputs.environ
+    yield assert_equal, res.runtime.environ['DISPLAY'], ':3'
+    ci3.inputs.environ = {'DISPLAY' : ':2'}
+    res = ci3.run()
+    yield assert_equal, res.runtime.environ['DISPLAY'], ':2'