Repository: nipy/nipype

Issue:
parameterize_dirs = False broken in python 3
### Summary
Using hashed dir parameterization is not working as expected.

### Actual behavior
```
  File "/Users/wtriplett/git/nipype-py3/nipype/pipeline/engine/workflows.py", line 580, in run
    self._configure_exec_nodes(execgraph)
  File "/Users/wtriplett/git/nipype-py3/nipype/pipeline/engine/workflows.py", line 683, in _configure_exec_nodes
    (op.join(edge[0].output_dir(),
  File "/Users/wtriplett/git/nipype-py3/nipype/pipeline/engine/nodes.py", line 209, in output_dir
    params_str = [self._parameterization_dir(p) for p in params_str]
  File "/Users/wtriplett/git/nipype-py3/nipype/pipeline/engine/nodes.py", line 209, in <listcomp>
    params_str = [self._parameterization_dir(p) for p in params_str]
  File "/Users/wtriplett/git/nipype-py3/nipype/pipeline/engine/nodes.py", line 394, in _parameterization_dir
    return sha1(param).hexdigest()
TypeError: Unicode-objects must be encoded before hashing
```
### Expected behavior
```
... normal execution output...
```
### How to replicate the behavior
```
    config.update_config({'execution': {'parameterize_dirs': False}})
```
### Platform details:
```
{'nibabel_version': '2.1.0', 'scipy_version': '0.18.1', 'networkx_version': '1.11', 'commit_source': 'repository', 'pkg_path': '/Users/wtriplett/
git/nipype-py3/nipype', 'traits_version': '4.6.0', 'numpy_version': '1.11.1', 'sys_platform': 'darwin', 'sys_executable': '/Users/wtriplett/anaco
nda3/bin/python', 'sys_version': '3.5.2 |Anaconda 4.2.0 (x86_64)| (default, Jul  2 2016, 17:52:12) \n[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-
425.0.28)]', 'commit_hash': '2d4726f'}
```


Discussion:

Resolving patch:
diff --git a/nipype/pipeline/engine/nodes.py b/nipype/pipeline/engine/nodes.py
--- a/nipype/pipeline/engine/nodes.py
+++ b/nipype/pipeline/engine/nodes.py
@@ -391,7 +391,7 @@ def _parameterization_dir(self, param):
             - Otherwise, return the parameterization unchanged.
         """
         if len(param) > 32:
-            return sha1(param).hexdigest()
+            return sha1(param.encode()).hexdigest()
         else:
             return param
 


Test patch:
diff --git a/nipype/pipeline/engine/tests/test_engine.py b/nipype/pipeline/engine/tests/test_engine.py
--- a/nipype/pipeline/engine/tests/test_engine.py
+++ b/nipype/pipeline/engine/tests/test_engine.py
@@ -22,7 +22,7 @@
 class InputSpec(nib.TraitedSpec):
     input1 = nib.traits.Int(desc='a random int')
     input2 = nib.traits.Int(desc='a random int')
-
+    input_file = nib.traits.File(desc='Random File')
 
 class OutputSpec(nib.TraitedSpec):
     output1 = nib.traits.List(nib.traits.Int, desc='outputs')
@@ -626,6 +626,33 @@ def func1(in1):
     assert not error_raised
 
 
+def test_parameterize_dirs_false(tmpdir):
+    from ....interfaces.utility import IdentityInterface
+    from ....testing import example_data
+
+    input_file = example_data('fsl_motion_outliers_fd.txt')
+
+    n1 = pe.Node(EngineTestInterface(), name='Node1')
+    n1.iterables = ('input_file', (input_file, input_file))
+    n1.interface.inputs.input1 = 1
+
+    n2 = pe.Node(IdentityInterface(fields='in1'), name='Node2')
+
+    wf = pe.Workflow(name='Test')
+    wf.base_dir = str(tmpdir)
+    wf.config['execution']['parameterize_dirs'] = False
+    wf.connect([(n1, n2, [('output1', 'in1')])])
+
+    error_raised = False
+    try:
+        wf.run()
+    except TypeError as typerr:
+        from nipype.pipeline.engine.base import logger
+        logger.info('Exception: %s' % str(typerr))
+        error_raised = True
+    assert not error_raised
+
+
 def test_serial_input(tmpdir):
     wd = str(tmpdir)
     os.chdir(wd)