Repository: nipy/nipype

Issue:
InterpolationSyntaxError from get_info()
### Summary

getting an error running nipype workflow or simply `nipype.get_info` (related to #1970)

```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/dorota/anaconda/envs/nipype_test/lib/python2.7/site-packages/nipype/__init__.py", line 48, in get_info
    return _get_pkg_info(os.path.dirname(__file__))
  File "/Users/dorota/anaconda/envs/nipype_test/lib/python2.7/site-packages/nipype/pkg_info.py", line 92, in get_pkg_info
    src, hsh = pkg_commit_hash(pkg_path)
  File "/Users/dorota/anaconda/envs/nipype_test/lib/python2.7/site-packages/nipype/pkg_info.py", line 58, in pkg_commit_hash
    archive_subst = cfg_parser.get('commit hash', 'archive_subst_hash')
  File "/Users/dorota/anaconda/envs/nipype_test/lib/python2.7/site-packages/backports/configparser/__init__.py", line 811, in get
    d)
  File "/Users/dorota/anaconda/envs/nipype_test/lib/python2.7/site-packages/backports/configparser/__init__.py", line 384, in before_get
    self._interpolate_some(parser, option, L, value, section, defaults, 1)
  File "/Users/dorota/anaconda/envs/nipype_test/lib/python2.7/site-packages/backports/configparser/__init__.py", line 434, in _interpolate_some
    "found: %r" % (rest,))
backports.configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: u'%h'
```

### How to replicate the behavior

It can be replicated in conda environment (used `conda create -n nipype_test python=2 nipype`):
`python -c "import nipype; nipype.get_info()"`

If `nipype` is installed with `pip` the error disappears 

InterpolationSyntaxError from get_info()
### Summary

getting an error running nipype workflow or simply `nipype.get_info` (related to #1970)

```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/dorota/anaconda/envs/nipype_test/lib/python2.7/site-packages/nipype/__init__.py", line 48, in get_info
    return _get_pkg_info(os.path.dirname(__file__))
  File "/Users/dorota/anaconda/envs/nipype_test/lib/python2.7/site-packages/nipype/pkg_info.py", line 92, in get_pkg_info
    src, hsh = pkg_commit_hash(pkg_path)
  File "/Users/dorota/anaconda/envs/nipype_test/lib/python2.7/site-packages/nipype/pkg_info.py", line 58, in pkg_commit_hash
    archive_subst = cfg_parser.get('commit hash', 'archive_subst_hash')
  File "/Users/dorota/anaconda/envs/nipype_test/lib/python2.7/site-packages/backports/configparser/__init__.py", line 811, in get
    d)
  File "/Users/dorota/anaconda/envs/nipype_test/lib/python2.7/site-packages/backports/configparser/__init__.py", line 384, in before_get
    self._interpolate_some(parser, option, L, value, section, defaults, 1)
  File "/Users/dorota/anaconda/envs/nipype_test/lib/python2.7/site-packages/backports/configparser/__init__.py", line 434, in _interpolate_some
    "found: %r" % (rest,))
backports.configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: u'%h'
```

### How to replicate the behavior

It can be replicated in conda environment (used `conda create -n nipype_test python=2 nipype`):
`python -c "import nipype; nipype.get_info()"`

If `nipype` is installed with `pip` the error disappears 



Discussion:
error is from [this line](https://github.com/nipy/nipype/blob/master/nipype/pkg_info.py#L58)
error is from [this line](https://github.com/nipy/nipype/blob/master/nipype/pkg_info.py#L58)

Resolving patch:
diff --git a/nipype/pkg_info.py b/nipype/pkg_info.py
--- a/nipype/pkg_info.py
+++ b/nipype/pkg_info.py
@@ -49,10 +49,7 @@ def pkg_commit_hash(pkg_path):
     pth = os.path.join(pkg_path, COMMIT_INFO_FNAME)
     if not os.path.isfile(pth):
         raise IOError('Missing commit info file %s' % pth)
-    if PY3:
-        cfg_parser = configparser.RawConfigParser()
-    else:
-        cfg_parser = configparser.ConfigParser()
+    cfg_parser = configparser.RawConfigParser()
     with open(pth, encoding='utf-8') as fp:
         cfg_parser.readfp(fp)
     archive_subst = cfg_parser.get('commit hash', 'archive_subst_hash')
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -76,10 +76,7 @@ def run(self):
             repo_commit = repo_commit.decode()
 
         # We write the installation commit even if it's empty
-        if PY3:
-            cfg_parser = configparser.RawConfigParser()
-        else:
-            cfg_parser = configparser.ConfigParser()
+        cfg_parser = configparser.RawConfigParser()
         cfg_parser.read(pjoin('nipype', 'COMMIT_INFO.txt'))
         cfg_parser.set('commit hash', 'install_hash', repo_commit.strip())
         out_pth = pjoin(self.build_lib, 'nipype', 'COMMIT_INFO.txt')


Test patch:
diff --git a/nipype/tests/test_nipype.py b/nipype/tests/test_nipype.py
--- a/nipype/tests/test_nipype.py
+++ b/nipype/tests/test_nipype.py
@@ -1,4 +1,6 @@
 from .. import get_info
+from ..info import get_nipype_gitversion
+import pytest
 
 
 def test_nipype_info():
@@ -10,5 +12,8 @@ def test_nipype_info():
     assert exception_not_raised
 
 
-# def test_fail_always():
-#     assert False
+@pytest.mark.skipif(not get_nipype_gitversion(), 
+                    reason="not able to get version from get_nipype_gitversion")
+def test_git_hash():
+    # removing the first "g" from gitversion
+    get_nipype_gitversion()[1:] == get_info()['commit_hash']