Repository: nipy/nipype

Issue:
NiftyReg interface raises ValueError: invalid version number
### Summary
Version number is "invalid" when I try to create a `RegAladin` node.

### Actual behavior
```python-traceback
C:\Users\fernando\tmp
(vesseg) λ python r.py
180612-15:47:29,796 interface WARNING:
         version_from_command member of CommandLine was Deprecated in nipype-1.0.0 and deleted in 1.1.0
Traceback (most recent call last):
  File "r.py", line 7, in <module>
    aladin = niftyreg.RegAladin()
  File "C:\Users\fernando\Miniconda3\envs\vesseg\lib\site-packages\nipype\interfaces\niftyreg\base.py", line 66, in __init__
    StrictVersion(_version) < StrictVersion(self._min_version):
  File "C:\Users\fernando\Miniconda3\envs\vesseg\lib\distutils\version.py", line 40, in __init__
    self.parse(vstring)
  File "C:\Users\fernando\Miniconda3\envs\vesseg\lib\distutils\version.py", line 137, in parse
    raise ValueError("invalid version number '%s'" % vstring)
ValueError: invalid version number '1.5.58
'
```

I have temporarily hacked this by replacing [this line](https://github.com/nipy/nipype/blob/master/nipype/interfaces/niftyreg/base.py#L59):
```python
_version = self.version_from_command()
```
by:
```python
_version = bytes('1.5.58', "utf-8")
```

### How to replicate the behavior
Run
```python
from nipype.interfaces import niftyreg
aladin = niftyreg.RegAladin()
```

### Platform details:
```python
In [1]: import nipype

In [2]: nipype.get_info()
Out[2]:
{'pkg_path': 'C:\\Users\\fernando\\Miniconda3\\envs\\vesseg\\lib\\site-packages\\nipype',
 'commit_source': 'archive substitution',
 'commit_hash': '%h',
 'nipype_version': '1.0.4',
 'sys_version': '3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)]',
 'sys_executable': 'C:\\Users\\fernando\\Miniconda3\\envs\\vesseg\\python.exe',
 'sys_platform': 'win32',
 'numpy_version': '1.14.3',
 'scipy_version': '1.1.0',
 'networkx_version': '2.1',
 'nibabel_version': '2.2.1',
 'traits_version': '4.6.0'}

In [3]: nipype.__version__
Out[3]: '1.0.4'
```

### Execution environment
I'm not sure what this means. I'm running Python from a `conda` environment.


NiftyReg interface raises ValueError: invalid version number
### Summary
Version number is "invalid" when I try to create a `RegAladin` node.

### Actual behavior
```python-traceback
C:\Users\fernando\tmp
(vesseg) λ python r.py
180612-15:47:29,796 interface WARNING:
         version_from_command member of CommandLine was Deprecated in nipype-1.0.0 and deleted in 1.1.0
Traceback (most recent call last):
  File "r.py", line 7, in <module>
    aladin = niftyreg.RegAladin()
  File "C:\Users\fernando\Miniconda3\envs\vesseg\lib\site-packages\nipype\interfaces\niftyreg\base.py", line 66, in __init__
    StrictVersion(_version) < StrictVersion(self._min_version):
  File "C:\Users\fernando\Miniconda3\envs\vesseg\lib\distutils\version.py", line 40, in __init__
    self.parse(vstring)
  File "C:\Users\fernando\Miniconda3\envs\vesseg\lib\distutils\version.py", line 137, in parse
    raise ValueError("invalid version number '%s'" % vstring)
ValueError: invalid version number '1.5.58
'
```

I have temporarily hacked this by replacing [this line](https://github.com/nipy/nipype/blob/master/nipype/interfaces/niftyreg/base.py#L59):
```python
_version = self.version_from_command()
```
by:
```python
_version = bytes('1.5.58', "utf-8")
```

### How to replicate the behavior
Run
```python
from nipype.interfaces import niftyreg
aladin = niftyreg.RegAladin()
```

### Platform details:
```python
In [1]: import nipype

In [2]: nipype.get_info()
Out[2]:
{'pkg_path': 'C:\\Users\\fernando\\Miniconda3\\envs\\vesseg\\lib\\site-packages\\nipype',
 'commit_source': 'archive substitution',
 'commit_hash': '%h',
 'nipype_version': '1.0.4',
 'sys_version': '3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)]',
 'sys_executable': 'C:\\Users\\fernando\\Miniconda3\\envs\\vesseg\\python.exe',
 'sys_platform': 'win32',
 'numpy_version': '1.14.3',
 'scipy_version': '1.1.0',
 'networkx_version': '2.1',
 'nibabel_version': '2.2.1',
 'traits_version': '4.6.0'}

In [3]: nipype.__version__
Out[3]: '1.0.4'
```

### Execution environment
I'm not sure what this means. I'm running Python from a `conda` environment.




Discussion:
@mmodat @byvernault mentioning in case you want to take a crack at this
I don't get this error anymore:
```python
In [9]: nipype.get_info()
Out[9]:
{'pkg_path': '/Users/fernando/miniconda3/lib/python3.6/site-packages/nipype',
 'commit_source': 'installation',
 'commit_hash': '9578f4ddc',
 'nipype_version': '1.1.0',
 'sys_version': '3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37) \n[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]',
 'sys_executable': '/Users/fernando/miniconda3/bin/python',
 'sys_platform': 'darwin',
 'numpy_version': '1.14.5',
 'scipy_version': '1.1.0',
 'networkx_version': '2.1',
 'nibabel_version': '2.4.0dev',
 'traits_version': '4.6.0'}
```

But I get a warning:
```
python
180728-13:10:24,671 nipype.interface WARNING:
	 version_from_command member of CommandLine was Deprecated in nipype-1.0.0 and deleted in 1.1.0
```

Hi. I'll update the call to version_from_command.
@mmodat As `version_from_command` has been deprecated, would it be possible to rework your versioning to use an `Info` object (sub-classing [PackageInfo](https://github.com/nipy/nipype/blob/715ad0ab06da09aba8956ba922a24fd058b749c0/nipype/interfaces/base/core.py#L1324-L1357))?

If you have a command that will produce the package version, you add a `version_cmd` class attribute; if there's a file in the distribution you can use `version_file`. In either case, you then write a simple `parse_version` static method that will produce a version string. I'll append several examples below:

https://github.com/nipy/nipype/blob/715ad0ab06da09aba8956ba922a24fd058b749c0/nipype/interfaces/ants/base.py#L33-L54

https://github.com/nipy/nipype/blob/715ad0ab06da09aba8956ba922a24fd058b749c0/nipype/interfaces/dcm2nii.py#L17-L25

https://github.com/nipy/nipype/blob/715ad0ab06da09aba8956ba922a24fd058b749c0/nipype/interfaces/fsl/base.py#L43-L72

https://github.com/nipy/nipype/blob/715ad0ab06da09aba8956ba922a24fd058b749c0/nipype/interfaces/freesurfer/base.py#L31-L83

https://github.com/nipy/nipype/blob/715ad0ab06da09aba8956ba922a24fd058b749c0/nipype/interfaces/spm/base.py#L127-L149
@mmodat Sorry to bother you, but any chance of trying to fix this for the October release?
I came across with the same issue when 
`from nipype.interfaces import niftyreg`
`node = niftyreg.regF3D()`.
@mmodat @byvernault mentioning in case you want to take a crack at this
I don't get this error anymore:
```python
In [9]: nipype.get_info()
Out[9]:
{'pkg_path': '/Users/fernando/miniconda3/lib/python3.6/site-packages/nipype',
 'commit_source': 'installation',
 'commit_hash': '9578f4ddc',
 'nipype_version': '1.1.0',
 'sys_version': '3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37) \n[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]',
 'sys_executable': '/Users/fernando/miniconda3/bin/python',
 'sys_platform': 'darwin',
 'numpy_version': '1.14.5',
 'scipy_version': '1.1.0',
 'networkx_version': '2.1',
 'nibabel_version': '2.4.0dev',
 'traits_version': '4.6.0'}
```

But I get a warning:
```
python
180728-13:10:24,671 nipype.interface WARNING:
	 version_from_command member of CommandLine was Deprecated in nipype-1.0.0 and deleted in 1.1.0
```

Hi. I'll update the call to version_from_command.
@mmodat As `version_from_command` has been deprecated, would it be possible to rework your versioning to use an `Info` object (sub-classing [PackageInfo](https://github.com/nipy/nipype/blob/715ad0ab06da09aba8956ba922a24fd058b749c0/nipype/interfaces/base/core.py#L1324-L1357))?

If you have a command that will produce the package version, you add a `version_cmd` class attribute; if there's a file in the distribution you can use `version_file`. In either case, you then write a simple `parse_version` static method that will produce a version string. I'll append several examples below:

https://github.com/nipy/nipype/blob/715ad0ab06da09aba8956ba922a24fd058b749c0/nipype/interfaces/ants/base.py#L33-L54

https://github.com/nipy/nipype/blob/715ad0ab06da09aba8956ba922a24fd058b749c0/nipype/interfaces/dcm2nii.py#L17-L25

https://github.com/nipy/nipype/blob/715ad0ab06da09aba8956ba922a24fd058b749c0/nipype/interfaces/fsl/base.py#L43-L72

https://github.com/nipy/nipype/blob/715ad0ab06da09aba8956ba922a24fd058b749c0/nipype/interfaces/freesurfer/base.py#L31-L83

https://github.com/nipy/nipype/blob/715ad0ab06da09aba8956ba922a24fd058b749c0/nipype/interfaces/spm/base.py#L127-L149
@mmodat Sorry to bother you, but any chance of trying to fix this for the October release?
I came across with the same issue when 
`from nipype.interfaces import niftyreg`
`node = niftyreg.regF3D()`.

Resolving patch:
diff --git a/nipype/interfaces/niftyreg/base.py b/nipype/interfaces/niftyreg/base.py
--- a/nipype/interfaces/niftyreg/base.py
+++ b/nipype/interfaces/niftyreg/base.py
@@ -19,7 +19,8 @@
 import os
 
 from ... import logging
-from ..base import CommandLine, CommandLineInputSpec, traits, Undefined
+from ..base import (CommandLine, CommandLineInputSpec, traits, Undefined,
+                    PackageInfo)
 from ...utils.filemanip import split_filename
 
 iflogger = logging.getLogger("nipype.interface")
@@ -29,6 +30,14 @@ def get_custom_path(command, env_dir="NIFTYREGDIR"):
     return os.path.join(os.getenv(env_dir, ""), command)
 
 
+class Info(PackageInfo):
+    version_cmd = get_custom_path('reg_aladin') + ' --version'
+
+    @staticmethod
+    def parse_version(raw_info):
+        return raw_info
+
+
 class NiftyRegCommandInputSpec(CommandLineInputSpec):
     """Input Spec for niftyreg interfaces."""
 
@@ -55,9 +64,8 @@ def __init__(self, required_version=None, **inputs):
         self.num_threads = 1
         super(NiftyRegCommand, self).__init__(**inputs)
         self.required_version = required_version
-        _version = self.version_from_command()
+        _version = self.version
         if _version:
-            _version = _version.decode("utf-8")
             if self._min_version is not None and StrictVersion(
                 _version
             ) < StrictVersion(self._min_version):
@@ -91,11 +99,9 @@ def _environ_update(self):
             self.inputs.omp_core_val = Undefined
 
     def check_version(self):
-        _version = self.version_from_command()
+        _version = self.version
         if not _version:
             raise Exception("Niftyreg not found")
-        # Decoding to string:
-        _version = _version.decode("utf-8")
         if StrictVersion(_version) < StrictVersion(self._min_version):
             err = "A later version of Niftyreg is required (%s < %s)"
             raise ValueError(err % (_version, self._min_version))
@@ -107,10 +113,10 @@ def check_version(self):
 
     @property
     def version(self):
-        return self.version_from_command()
+        return Info.version()
 
     def exists(self):
-        return self.version_from_command() is not None
+        return self.version is not None
 
     def _format_arg(self, name, spec, value):
         if name == "omp_core_val":


Test patch: