Skip to content

Commit ab91510

Browse files
authored
Merge branch 'master' into logger
2 parents 05bf324 + b443e47 commit ab91510

File tree

5 files changed

+64
-78
lines changed

5 files changed

+64
-78
lines changed

nipype/interfaces/afni/base.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,26 @@
1414
from ...utils.filemanip import split_filename, fname_presuffix
1515

1616
from ..base import (
17-
CommandLine, traits, CommandLineInputSpec, isdefined, File, TraitedSpec)
17+
CommandLine, traits, CommandLineInputSpec, isdefined, File, TraitedSpec,
18+
PackageInfo)
1819
from ...external.due import BibTeX
1920

2021
# Use nipype's logging system
2122
IFLOGGER = logging.getLogger('interface')
2223

2324

24-
class Info(object):
25+
class Info(PackageInfo):
2526
"""Handle afni output type and version information.
2627
"""
2728
__outputtype = 'AFNI'
2829
ftypes = {'NIFTI': '.nii',
2930
'AFNI': '',
3031
'NIFTI_GZ': '.nii.gz'}
32+
version_cmd = 'afni --version'
3133

3234
@staticmethod
33-
def version():
34-
"""Check for afni version on system
35-
36-
Parameters
37-
----------
38-
None
39-
40-
Returns
41-
-------
42-
version : str
43-
Version number as string or None if AFNI not found
44-
45-
"""
46-
try:
47-
clout = CommandLine(command='afni --version',
48-
resource_monitor=False,
49-
terminal_output='allatonce').run()
50-
except IOError:
51-
# If afni_vcheck is not present, return None
52-
IFLOGGER.warn('afni executable not found.')
53-
return None
54-
55-
version_stamp = clout.runtime.stdout.split('\n')[0].split('Version ')[1]
35+
def parse_version(raw_info):
36+
version_stamp = raw_info.split('\n')[0].split('Version ')[1]
5637
if version_stamp.startswith('AFNI'):
5738
version_stamp = version_stamp.split('AFNI_')[1]
5839
elif version_stamp.startswith('Debian'):

nipype/interfaces/afni/preprocess.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3519,7 +3519,6 @@ def _list_outputs(self):
35193519
else:
35203520
ext = prefix[ext_ind:]
35213521
suffix = ''
3522-
print(ext,"ext")
35233522
outputs['warped_source'] = fname_presuffix(prefix, suffix=suffix,
35243523
use_ext=False) + ext
35253524
if not self.inputs.nowarp:

nipype/interfaces/ants/base.py

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from builtins import str
77

88
import os
9-
import subprocess
109

1110
# Local imports
1211
from ... import logging, LooseVersion
13-
from ..base import CommandLine, CommandLineInputSpec, traits, isdefined
12+
from ..base import (CommandLine, CommandLineInputSpec, traits, isdefined,
13+
PackageInfo)
1414
iflogger = logging.getLogger('interface')
1515

1616
# -Using -1 gives primary responsibilty to ITKv4 to do the correct
@@ -29,32 +29,21 @@
2929
ALT_ITKv4_THREAD_LIMIT_VARIABLE = 'ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS'
3030

3131

32-
class Info(object):
33-
_version = None
32+
class Info(PackageInfo):
33+
version_cmd = os.path.join(os.getenv('ANTSPATH', ''),
34+
'antsRegistration') + ' --version'
3435

35-
@property
36-
def version(self):
37-
if self._version is None:
38-
try:
39-
basedir = os.environ['ANTSPATH']
40-
except KeyError:
41-
return None
42-
43-
cmd = os.path.join(basedir, 'antsRegistration')
44-
try:
45-
res = subprocess.check_output([cmd, '--version']).decode('utf-8')
46-
except OSError:
47-
return None
48-
49-
for line in res.splitlines():
50-
if line.startswith('ANTs Version: '):
51-
self._version = line.split()[2]
52-
break
53-
else:
54-
return None
36+
@staticmethod
37+
def parse_version(raw_info):
38+
for line in raw_info.splitlines():
39+
if line.startswith('ANTs Version: '):
40+
v_string = line.split()[2]
41+
break
42+
else:
43+
return None
5544

5645
# -githash may or may not be appended
57-
v_string = self._version.split('-')[0]
46+
v_string = v_string.split('-')[0]
5847

5948
# 2.2.0-equivalent version string
6049
if 'post' in v_string and LooseVersion(v_string) >= LooseVersion('2.1.0.post789'):
@@ -125,4 +114,4 @@ def set_default_num_threads(cls, num_threads):
125114

126115
@property
127116
def version(self):
128-
return Info().version
117+
return Info.version()

nipype/interfaces/base.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,41 @@ def _format_arg(self, name, spec, value):
19241924
return super(SEMLikeCommandLine, self)._format_arg(name, spec, value)
19251925

19261926

1927+
class PackageInfo(object):
1928+
_version = None
1929+
version_cmd = None
1930+
version_file = None
1931+
1932+
@classmethod
1933+
def version(klass):
1934+
if klass._version is None:
1935+
if klass.version_cmd is not None:
1936+
try:
1937+
clout = CommandLine(command=klass.version_cmd,
1938+
resource_monitor=False,
1939+
terminal_output='allatonce').run()
1940+
except IOError:
1941+
return None
1942+
1943+
raw_info = clout.runtime.stdout
1944+
elif klass.version_file is not None:
1945+
try:
1946+
with open(klass.version_file, 'rt') as fobj:
1947+
raw_info = fobj.read()
1948+
except OSError:
1949+
return None
1950+
else:
1951+
return None
1952+
1953+
klass._version = klass.parse_version(raw_info)
1954+
1955+
return klass._version
1956+
1957+
@staticmethod
1958+
def parse_version(raw_info):
1959+
raise NotImplementedError
1960+
1961+
19271962
class MultiPath(traits.List):
19281963
""" Abstract class - shared functionality of input and output MultiPath
19291964
"""

nipype/interfaces/freesurfer/base.py

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
from ...utils.filemanip import fname_presuffix
2424
from ..base import (CommandLine, Directory,
2525
CommandLineInputSpec, isdefined,
26-
traits, TraitedSpec, File)
26+
traits, TraitedSpec, File,
27+
PackageInfo)
2728

2829
__docformat__ = 'restructuredtext'
2930

3031

31-
class Info(object):
32+
class Info(PackageInfo):
3233
""" Freesurfer subject directory and version information.
3334
3435
Examples
@@ -39,32 +40,13 @@ class Info(object):
3940
>>> Info.subjectsdir() # doctest: +SKIP
4041
4142
"""
43+
if os.getenv('FREESURFER_HOME'):
44+
version_file = os.path.join(os.getenv('FREESURFER_HOME'),
45+
'build-stamp.txt')
4246

4347
@staticmethod
44-
def version():
45-
"""Check for freesurfer version on system
46-
47-
Find which freesurfer is being used....and get version from
48-
/path/to/freesurfer/build-stamp.txt
49-
50-
Returns
51-
-------
52-
53-
version : string
54-
version number as string
55-
or None if freesurfer version not found
56-
57-
"""
58-
fs_home = os.getenv('FREESURFER_HOME')
59-
if fs_home is None:
60-
return None
61-
versionfile = os.path.join(fs_home, 'build-stamp.txt')
62-
if not os.path.exists(versionfile):
63-
return None
64-
fid = open(versionfile, 'rt')
65-
version = fid.readline()
66-
fid.close()
67-
return version
48+
def parse_version(raw_info):
49+
return raw_info.splitlines()[0]
6850

6951
@classmethod
7052
def looseversion(cls):

0 commit comments

Comments
 (0)