|
4 | 4 | from __future__ import (print_function, division, unicode_literals,
|
5 | 5 | absolute_import)
|
6 | 6 |
|
7 |
| -from ... import logging |
8 |
| -from ..base import (CommandLineInputSpec, CommandLine, traits, File, isdefined) |
| 7 | +from ... import logging, LooseVersion |
| 8 | +from ...utils.filemanip import which |
| 9 | +from ..base import (CommandLineInputSpec, CommandLine, traits, File, isdefined, PackageInfo) |
9 | 10 | iflogger = logging.getLogger('nipype.interface')
|
10 | 11 |
|
11 | 12 |
|
| 13 | +class Info(PackageInfo): |
| 14 | + version_cmd = 'mrconvert --version' |
| 15 | + |
| 16 | + @staticmethod |
| 17 | + def parse_version(raw_info): |
| 18 | + # info is like: "== mrconvert 0.3.15-githash" |
| 19 | + for line in raw_info.splitlines(): |
| 20 | + if line.startswith('== mrconvert '): |
| 21 | + v_string = line.split()[2] |
| 22 | + break |
| 23 | + else: |
| 24 | + return None |
| 25 | + |
| 26 | + # -githash may or may not be appended |
| 27 | + v_string = v_string.split('-')[0] |
| 28 | + |
| 29 | + return '.'.join(v_string.split('.')[:3]) |
| 30 | + |
| 31 | + @classmethod |
| 32 | + def looseversion(cls): |
| 33 | + """ Return a comparable version object |
| 34 | +
|
| 35 | + If no version found, use LooseVersion('0.0.0') |
| 36 | + """ |
| 37 | + return LooseVersion(cls.version() or '0.0.0') |
| 38 | + |
| 39 | + |
12 | 40 | class MRTrix3BaseInputSpec(CommandLineInputSpec):
|
13 | 41 | nthreads = traits.Int(
|
14 | 42 | argstr='-nthreads %d',
|
@@ -78,3 +106,7 @@ def _parse_inputs(self, skip=None):
|
78 | 106 | pass
|
79 | 107 |
|
80 | 108 | return super(MRTrix3Base, self)._parse_inputs(skip=skip)
|
| 109 | + |
| 110 | + @property |
| 111 | + def version(self): |
| 112 | + return Info.version() |
0 commit comments