We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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.



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `nipype/interfaces/niftyreg/base.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
3 # vi: set ft=python sts=4 ts=4 sw=4 et:
4 """
5 The niftyreg module provides classes for interfacing with `niftyreg
6 <http://sourceforge.net/projects/niftyreg/>`_ command line tools.
7 
8 These are the base tools for working with niftyreg.
9 
10 Registration tools are found in niftyreg/reg.py
11 Every other tool is found in niftyreg/regutils.py
12 
13 Examples
14 --------
15 See the docstrings of the individual classes for examples.
16 
17 """
18 from distutils.version import StrictVersion
19 import os
20 
21 from ... import logging
22 from ..base import CommandLine, CommandLineInputSpec, traits, Undefined
23 from ...utils.filemanip import split_filename
24 
25 iflogger = logging.getLogger("nipype.interface")
26 
27 
28 def get_custom_path(command, env_dir="NIFTYREGDIR"):
29     return os.path.join(os.getenv(env_dir, ""), command)
30 
31 
32 class NiftyRegCommandInputSpec(CommandLineInputSpec):
33     """Input Spec for niftyreg interfaces."""
34 
35     # Set the number of omp thread to use
36     omp_core_val = traits.Int(
37         int(os.environ.get("OMP_NUM_THREADS", "1")),
38         desc="Number of openmp thread to use",
39         argstr="-omp %i",
40         usedefault=True,
41     )
42 
43 
44 class NiftyRegCommand(CommandLine):
45     """
46     Base support interface for NiftyReg commands.
47     """
48 
49     _suffix = "_nr"
50     _min_version = "1.5.30"
51 
52     input_spec = NiftyRegCommandInputSpec
53 
54     def __init__(self, required_version=None, **inputs):
55         self.num_threads = 1
56         super(NiftyRegCommand, self).__init__(**inputs)
57         self.required_version = required_version
58         _version = self.version_from_command()
59         if _version:
60             _version = _version.decode("utf-8")
61             if self._min_version is not None and StrictVersion(
62                 _version
63             ) < StrictVersion(self._min_version):
64                 msg = "A later version of Niftyreg is required (%s < %s)"
65                 iflogger.warning(msg, _version, self._min_version)
66             if required_version is not None:
67                 if StrictVersion(_version) != StrictVersion(required_version):
68                     msg = "The version of NiftyReg differs from the required"
69                     msg += "(%s != %s)"
70                     iflogger.warning(msg, _version, self.required_version)
71         self.inputs.on_trait_change(self._omp_update, "omp_core_val")
72         self.inputs.on_trait_change(self._environ_update, "environ")
73         self._omp_update()
74 
75     def _omp_update(self):
76         if self.inputs.omp_core_val:
77             self.inputs.environ["OMP_NUM_THREADS"] = str(self.inputs.omp_core_val)
78             self.num_threads = self.inputs.omp_core_val
79         else:
80             if "OMP_NUM_THREADS" in self.inputs.environ:
81                 del self.inputs.environ["OMP_NUM_THREADS"]
82             self.num_threads = 1
83 
84     def _environ_update(self):
85         if self.inputs.environ:
86             if "OMP_NUM_THREADS" in self.inputs.environ:
87                 self.inputs.omp_core_val = int(self.inputs.environ["OMP_NUM_THREADS"])
88             else:
89                 self.inputs.omp_core_val = Undefined
90         else:
91             self.inputs.omp_core_val = Undefined
92 
93     def check_version(self):
94         _version = self.version_from_command()
95         if not _version:
96             raise Exception("Niftyreg not found")
97         # Decoding to string:
98         _version = _version.decode("utf-8")
99         if StrictVersion(_version) < StrictVersion(self._min_version):
100             err = "A later version of Niftyreg is required (%s < %s)"
101             raise ValueError(err % (_version, self._min_version))
102         if self.required_version:
103             if StrictVersion(_version) != StrictVersion(self.required_version):
104                 err = "The version of NiftyReg differs from the required"
105                 err += "(%s != %s)"
106                 raise ValueError(err % (_version, self.required_version))
107 
108     @property
109     def version(self):
110         return self.version_from_command()
111 
112     def exists(self):
113         return self.version_from_command() is not None
114 
115     def _format_arg(self, name, spec, value):
116         if name == "omp_core_val":
117             self.numthreads = value
118         return super(NiftyRegCommand, self)._format_arg(name, spec, value)
119 
120     def _gen_fname(self, basename, out_dir=None, suffix=None, ext=None):
121         if basename == "":
122             msg = "Unable to generate filename for command %s. " % self.cmd
123             msg += "basename is not set!"
124             raise ValueError(msg)
125         _, final_bn, final_ext = split_filename(basename)
126         if out_dir is None:
127             out_dir = os.getcwd()
128         if ext is not None:
129             final_ext = ext
130         if suffix is not None:
131             final_bn = "".join((final_bn, suffix))
132         return os.path.abspath(os.path.join(out_dir, final_bn + final_ext))
133
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
     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 @@
         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 @@
             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 @@
 
     @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":

{"golden_diff": "diff --git a/nipype/interfaces/niftyreg/base.py b/nipype/interfaces/niftyreg/base.py\n--- a/nipype/interfaces/niftyreg/base.py\n+++ b/nipype/interfaces/niftyreg/base.py\n@@ -19,7 +19,8 @@\n import os\n \n from ... import logging\n-from ..base import CommandLine, CommandLineInputSpec, traits, Undefined\n+from ..base import (CommandLine, CommandLineInputSpec, traits, Undefined,\n+                    PackageInfo)\n from ...utils.filemanip import split_filename\n \n iflogger = logging.getLogger(\"nipype.interface\")\n@@ -29,6 +30,14 @@\n     return os.path.join(os.getenv(env_dir, \"\"), command)\n \n \n+class Info(PackageInfo):\n+    version_cmd = get_custom_path('reg_aladin') + ' --version'\n+\n+    @staticmethod\n+    def parse_version(raw_info):\n+        return raw_info\n+\n+\n class NiftyRegCommandInputSpec(CommandLineInputSpec):\n     \"\"\"Input Spec for niftyreg interfaces.\"\"\"\n \n@@ -55,9 +64,8 @@\n         self.num_threads = 1\n         super(NiftyRegCommand, self).__init__(**inputs)\n         self.required_version = required_version\n-        _version = self.version_from_command()\n+        _version = self.version\n         if _version:\n-            _version = _version.decode(\"utf-8\")\n             if self._min_version is not None and StrictVersion(\n                 _version\n             ) < StrictVersion(self._min_version):\n@@ -91,11 +99,9 @@\n             self.inputs.omp_core_val = Undefined\n \n     def check_version(self):\n-        _version = self.version_from_command()\n+        _version = self.version\n         if not _version:\n             raise Exception(\"Niftyreg not found\")\n-        # Decoding to string:\n-        _version = _version.decode(\"utf-8\")\n         if StrictVersion(_version) < StrictVersion(self._min_version):\n             err = \"A later version of Niftyreg is required (%s < %s)\"\n             raise ValueError(err % (_version, self._min_version))\n@@ -107,10 +113,10 @@\n \n     @property\n     def version(self):\n-        return self.version_from_command()\n+        return Info.version()\n \n     def exists(self):\n-        return self.version_from_command() is not None\n+        return self.version is not None\n \n     def _format_arg(self, name, spec, value):\n         if name == \"omp_core_val\":\n", "issue": "NiftyReg interface raises ValueError: invalid version number\n### Summary\r\nVersion number is \"invalid\" when I try to create a `RegAladin` node.\r\n\r\n### Actual behavior\r\n```python-traceback\r\nC:\\Users\\fernando\\tmp\r\n(vesseg) \u03bb python r.py\r\n180612-15:47:29,796 interface WARNING:\r\n         version_from_command member of CommandLine was Deprecated in nipype-1.0.0 and deleted in 1.1.0\r\nTraceback (most recent call last):\r\n  File \"r.py\", line 7, in <module>\r\n    aladin = niftyreg.RegAladin()\r\n  File \"C:\\Users\\fernando\\Miniconda3\\envs\\vesseg\\lib\\site-packages\\nipype\\interfaces\\niftyreg\\base.py\", line 66, in __init__\r\n    StrictVersion(_version) < StrictVersion(self._min_version):\r\n  File \"C:\\Users\\fernando\\Miniconda3\\envs\\vesseg\\lib\\distutils\\version.py\", line 40, in __init__\r\n    self.parse(vstring)\r\n  File \"C:\\Users\\fernando\\Miniconda3\\envs\\vesseg\\lib\\distutils\\version.py\", line 137, in parse\r\n    raise ValueError(\"invalid version number '%s'\" % vstring)\r\nValueError: invalid version number '1.5.58\r\n'\r\n```\r\n\r\nI have temporarily hacked this by replacing [this line](https://github.com/nipy/nipype/blob/master/nipype/interfaces/niftyreg/base.py#L59):\r\n```python\r\n_version = self.version_from_command()\r\n```\r\nby:\r\n```python\r\n_version = bytes('1.5.58', \"utf-8\")\r\n```\r\n\r\n### How to replicate the behavior\r\nRun\r\n```python\r\nfrom nipype.interfaces import niftyreg\r\naladin = niftyreg.RegAladin()\r\n```\r\n\r\n### Platform details:\r\n```python\r\nIn [1]: import nipype\r\n\r\nIn [2]: nipype.get_info()\r\nOut[2]:\r\n{'pkg_path': 'C:\\\\Users\\\\fernando\\\\Miniconda3\\\\envs\\\\vesseg\\\\lib\\\\site-packages\\\\nipype',\r\n 'commit_source': 'archive substitution',\r\n 'commit_hash': '%h',\r\n 'nipype_version': '1.0.4',\r\n 'sys_version': '3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)]',\r\n 'sys_executable': 'C:\\\\Users\\\\fernando\\\\Miniconda3\\\\envs\\\\vesseg\\\\python.exe',\r\n 'sys_platform': 'win32',\r\n 'numpy_version': '1.14.3',\r\n 'scipy_version': '1.1.0',\r\n 'networkx_version': '2.1',\r\n 'nibabel_version': '2.2.1',\r\n 'traits_version': '4.6.0'}\r\n\r\nIn [3]: nipype.__version__\r\nOut[3]: '1.0.4'\r\n```\r\n\r\n### Execution environment\r\nI'm not sure what this means. I'm running Python from a `conda` environment.\r\n\r\n\nNiftyReg interface raises ValueError: invalid version number\n### Summary\r\nVersion number is \"invalid\" when I try to create a `RegAladin` node.\r\n\r\n### Actual behavior\r\n```python-traceback\r\nC:\\Users\\fernando\\tmp\r\n(vesseg) \u03bb python r.py\r\n180612-15:47:29,796 interface WARNING:\r\n         version_from_command member of CommandLine was Deprecated in nipype-1.0.0 and deleted in 1.1.0\r\nTraceback (most recent call last):\r\n  File \"r.py\", line 7, in <module>\r\n    aladin = niftyreg.RegAladin()\r\n  File \"C:\\Users\\fernando\\Miniconda3\\envs\\vesseg\\lib\\site-packages\\nipype\\interfaces\\niftyreg\\base.py\", line 66, in __init__\r\n    StrictVersion(_version) < StrictVersion(self._min_version):\r\n  File \"C:\\Users\\fernando\\Miniconda3\\envs\\vesseg\\lib\\distutils\\version.py\", line 40, in __init__\r\n    self.parse(vstring)\r\n  File \"C:\\Users\\fernando\\Miniconda3\\envs\\vesseg\\lib\\distutils\\version.py\", line 137, in parse\r\n    raise ValueError(\"invalid version number '%s'\" % vstring)\r\nValueError: invalid version number '1.5.58\r\n'\r\n```\r\n\r\nI have temporarily hacked this by replacing [this line](https://github.com/nipy/nipype/blob/master/nipype/interfaces/niftyreg/base.py#L59):\r\n```python\r\n_version = self.version_from_command()\r\n```\r\nby:\r\n```python\r\n_version = bytes('1.5.58', \"utf-8\")\r\n```\r\n\r\n### How to replicate the behavior\r\nRun\r\n```python\r\nfrom nipype.interfaces import niftyreg\r\naladin = niftyreg.RegAladin()\r\n```\r\n\r\n### Platform details:\r\n```python\r\nIn [1]: import nipype\r\n\r\nIn [2]: nipype.get_info()\r\nOut[2]:\r\n{'pkg_path': 'C:\\\\Users\\\\fernando\\\\Miniconda3\\\\envs\\\\vesseg\\\\lib\\\\site-packages\\\\nipype',\r\n 'commit_source': 'archive substitution',\r\n 'commit_hash': '%h',\r\n 'nipype_version': '1.0.4',\r\n 'sys_version': '3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)]',\r\n 'sys_executable': 'C:\\\\Users\\\\fernando\\\\Miniconda3\\\\envs\\\\vesseg\\\\python.exe',\r\n 'sys_platform': 'win32',\r\n 'numpy_version': '1.14.3',\r\n 'scipy_version': '1.1.0',\r\n 'networkx_version': '2.1',\r\n 'nibabel_version': '2.2.1',\r\n 'traits_version': '4.6.0'}\r\n\r\nIn [3]: nipype.__version__\r\nOut[3]: '1.0.4'\r\n```\r\n\r\n### Execution environment\r\nI'm not sure what this means. I'm running Python from a `conda` environment.\r\n\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-\n# vi: set ft=python sts=4 ts=4 sw=4 et:\n\"\"\"\nThe niftyreg module provides classes for interfacing with `niftyreg\n<http://sourceforge.net/projects/niftyreg/>`_ command line tools.\n\nThese are the base tools for working with niftyreg.\n\nRegistration tools are found in niftyreg/reg.py\nEvery other tool is found in niftyreg/regutils.py\n\nExamples\n--------\nSee the docstrings of the individual classes for examples.\n\n\"\"\"\nfrom distutils.version import StrictVersion\nimport os\n\nfrom ... import logging\nfrom ..base import CommandLine, CommandLineInputSpec, traits, Undefined\nfrom ...utils.filemanip import split_filename\n\niflogger = logging.getLogger(\"nipype.interface\")\n\n\ndef get_custom_path(command, env_dir=\"NIFTYREGDIR\"):\n    return os.path.join(os.getenv(env_dir, \"\"), command)\n\n\nclass NiftyRegCommandInputSpec(CommandLineInputSpec):\n    \"\"\"Input Spec for niftyreg interfaces.\"\"\"\n\n    # Set the number of omp thread to use\n    omp_core_val = traits.Int(\n        int(os.environ.get(\"OMP_NUM_THREADS\", \"1\")),\n        desc=\"Number of openmp thread to use\",\n        argstr=\"-omp %i\",\n        usedefault=True,\n    )\n\n\nclass NiftyRegCommand(CommandLine):\n    \"\"\"\n    Base support interface for NiftyReg commands.\n    \"\"\"\n\n    _suffix = \"_nr\"\n    _min_version = \"1.5.30\"\n\n    input_spec = NiftyRegCommandInputSpec\n\n    def __init__(self, required_version=None, **inputs):\n        self.num_threads = 1\n        super(NiftyRegCommand, self).__init__(**inputs)\n        self.required_version = required_version\n        _version = self.version_from_command()\n        if _version:\n            _version = _version.decode(\"utf-8\")\n            if self._min_version is not None and StrictVersion(\n                _version\n            ) < StrictVersion(self._min_version):\n                msg = \"A later version of Niftyreg is required (%s < %s)\"\n                iflogger.warning(msg, _version, self._min_version)\n            if required_version is not None:\n                if StrictVersion(_version) != StrictVersion(required_version):\n                    msg = \"The version of NiftyReg differs from the required\"\n                    msg += \"(%s != %s)\"\n                    iflogger.warning(msg, _version, self.required_version)\n        self.inputs.on_trait_change(self._omp_update, \"omp_core_val\")\n        self.inputs.on_trait_change(self._environ_update, \"environ\")\n        self._omp_update()\n\n    def _omp_update(self):\n        if self.inputs.omp_core_val:\n            self.inputs.environ[\"OMP_NUM_THREADS\"] = str(self.inputs.omp_core_val)\n            self.num_threads = self.inputs.omp_core_val\n        else:\n            if \"OMP_NUM_THREADS\" in self.inputs.environ:\n                del self.inputs.environ[\"OMP_NUM_THREADS\"]\n            self.num_threads = 1\n\n    def _environ_update(self):\n        if self.inputs.environ:\n            if \"OMP_NUM_THREADS\" in self.inputs.environ:\n                self.inputs.omp_core_val = int(self.inputs.environ[\"OMP_NUM_THREADS\"])\n            else:\n                self.inputs.omp_core_val = Undefined\n        else:\n            self.inputs.omp_core_val = Undefined\n\n    def check_version(self):\n        _version = self.version_from_command()\n        if not _version:\n            raise Exception(\"Niftyreg not found\")\n        # Decoding to string:\n        _version = _version.decode(\"utf-8\")\n        if StrictVersion(_version) < StrictVersion(self._min_version):\n            err = \"A later version of Niftyreg is required (%s < %s)\"\n            raise ValueError(err % (_version, self._min_version))\n        if self.required_version:\n            if StrictVersion(_version) != StrictVersion(self.required_version):\n                err = \"The version of NiftyReg differs from the required\"\n                err += \"(%s != %s)\"\n                raise ValueError(err % (_version, self.required_version))\n\n    @property\n    def version(self):\n        return self.version_from_command()\n\n    def exists(self):\n        return self.version_from_command() is not None\n\n    def _format_arg(self, name, spec, value):\n        if name == \"omp_core_val\":\n            self.numthreads = value\n        return super(NiftyRegCommand, self)._format_arg(name, spec, value)\n\n    def _gen_fname(self, basename, out_dir=None, suffix=None, ext=None):\n        if basename == \"\":\n            msg = \"Unable to generate filename for command %s. \" % self.cmd\n            msg += \"basename is not set!\"\n            raise ValueError(msg)\n        _, final_bn, final_ext = split_filename(basename)\n        if out_dir is None:\n            out_dir = os.getcwd()\n        if ext is not None:\n            final_ext = ext\n        if suffix is not None:\n            final_bn = \"\".join((final_bn, suffix))\n        return os.path.abspath(os.path.join(out_dir, final_bn + final_ext))\n", "path": "nipype/interfaces/niftyreg/base.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-\n# vi: set ft=python sts=4 ts=4 sw=4 et:\n\"\"\"\nThe niftyreg module provides classes for interfacing with `niftyreg\n<http://sourceforge.net/projects/niftyreg/>`_ command line tools.\n\nThese are the base tools for working with niftyreg.\n\nRegistration tools are found in niftyreg/reg.py\nEvery other tool is found in niftyreg/regutils.py\n\nExamples\n--------\nSee the docstrings of the individual classes for examples.\n\n\"\"\"\nfrom distutils.version import StrictVersion\nimport os\n\nfrom ... import logging\nfrom ..base import (CommandLine, CommandLineInputSpec, traits, Undefined,\n                    PackageInfo)\nfrom ...utils.filemanip import split_filename\n\niflogger = logging.getLogger(\"nipype.interface\")\n\n\ndef get_custom_path(command, env_dir=\"NIFTYREGDIR\"):\n    return os.path.join(os.getenv(env_dir, \"\"), command)\n\n\nclass Info(PackageInfo):\n    version_cmd = get_custom_path('reg_aladin') + ' --version'\n\n    @staticmethod\n    def parse_version(raw_info):\n        return raw_info\n\n\nclass NiftyRegCommandInputSpec(CommandLineInputSpec):\n    \"\"\"Input Spec for niftyreg interfaces.\"\"\"\n\n    # Set the number of omp thread to use\n    omp_core_val = traits.Int(\n        int(os.environ.get(\"OMP_NUM_THREADS\", \"1\")),\n        desc=\"Number of openmp thread to use\",\n        argstr=\"-omp %i\",\n        usedefault=True,\n    )\n\n\nclass NiftyRegCommand(CommandLine):\n    \"\"\"\n    Base support interface for NiftyReg commands.\n    \"\"\"\n\n    _suffix = \"_nr\"\n    _min_version = \"1.5.30\"\n\n    input_spec = NiftyRegCommandInputSpec\n\n    def __init__(self, required_version=None, **inputs):\n        self.num_threads = 1\n        super(NiftyRegCommand, self).__init__(**inputs)\n        self.required_version = required_version\n        _version = self.version\n        if _version:\n            if self._min_version is not None and StrictVersion(\n                _version\n            ) < StrictVersion(self._min_version):\n                msg = \"A later version of Niftyreg is required (%s < %s)\"\n                iflogger.warning(msg, _version, self._min_version)\n            if required_version is not None:\n                if StrictVersion(_version) != StrictVersion(required_version):\n                    msg = \"The version of NiftyReg differs from the required\"\n                    msg += \"(%s != %s)\"\n                    iflogger.warning(msg, _version, self.required_version)\n        self.inputs.on_trait_change(self._omp_update, \"omp_core_val\")\n        self.inputs.on_trait_change(self._environ_update, \"environ\")\n        self._omp_update()\n\n    def _omp_update(self):\n        if self.inputs.omp_core_val:\n            self.inputs.environ[\"OMP_NUM_THREADS\"] = str(self.inputs.omp_core_val)\n            self.num_threads = self.inputs.omp_core_val\n        else:\n            if \"OMP_NUM_THREADS\" in self.inputs.environ:\n                del self.inputs.environ[\"OMP_NUM_THREADS\"]\n            self.num_threads = 1\n\n    def _environ_update(self):\n        if self.inputs.environ:\n            if \"OMP_NUM_THREADS\" in self.inputs.environ:\n                self.inputs.omp_core_val = int(self.inputs.environ[\"OMP_NUM_THREADS\"])\n            else:\n                self.inputs.omp_core_val = Undefined\n        else:\n            self.inputs.omp_core_val = Undefined\n\n    def check_version(self):\n        _version = self.version\n        if not _version:\n            raise Exception(\"Niftyreg not found\")\n        if StrictVersion(_version) < StrictVersion(self._min_version):\n            err = \"A later version of Niftyreg is required (%s < %s)\"\n            raise ValueError(err % (_version, self._min_version))\n        if self.required_version:\n            if StrictVersion(_version) != StrictVersion(self.required_version):\n                err = \"The version of NiftyReg differs from the required\"\n                err += \"(%s != %s)\"\n                raise ValueError(err % (_version, self.required_version))\n\n    @property\n    def version(self):\n        return Info.version()\n\n    def exists(self):\n        return self.version is not None\n\n    def _format_arg(self, name, spec, value):\n        if name == \"omp_core_val\":\n            self.numthreads = value\n        return super(NiftyRegCommand, self)._format_arg(name, spec, value)\n\n    def _gen_fname(self, basename, out_dir=None, suffix=None, ext=None):\n        if basename == \"\":\n            msg = \"Unable to generate filename for command %s. \" % self.cmd\n            msg += \"basename is not set!\"\n            raise ValueError(msg)\n        _, final_bn, final_ext = split_filename(basename)\n        if out_dir is None:\n            out_dir = os.getcwd()\n        if ext is not None:\n            final_ext = ext\n        if suffix is not None:\n            final_bn = \"\".join((final_bn, suffix))\n        return os.path.abspath(os.path.join(out_dir, final_bn + final_ext))\n", "path": "nipype/interfaces/niftyreg/base.py"}]}