Skip to content

Commit 2602cb6

Browse files
committed
Merge pull request #1337 from oesteban/fix/AfniVersionAfter16
[ENH] Improved AFNI version parsing after recent publication of 16.0.01
2 parents 6ca964d + 2ed1624 commit 2602cb6

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

nipype/interfaces/afni/base.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77

88
import os
9-
import warnings
109

10+
from ... import logging
1111
from ...utils.filemanip import split_filename
1212
from ..base import (
1313
CommandLine, traits, CommandLineInputSpec, isdefined, File, TraitedSpec)
1414

15-
warn = warnings.warn
15+
# Use nipype's logging system
16+
iflogger = logging.getLogger('interface')
1617

1718

1819
class Info(object):
@@ -40,26 +41,29 @@ def version():
4041
try:
4142
clout = CommandLine(command='afni_vcheck',
4243
terminal_output='allatonce').run()
44+
45+
# Try to parse the version number
46+
currv = clout.runtime.stdout.split('\n')[1].split('=', 1)[1].strip()
4347
except IOError:
4448
# If afni_vcheck is not present, return None
45-
warn('afni_vcheck executable not found.')
49+
iflogger.warn('afni_vcheck executable not found.')
4650
return None
4751
except RuntimeError as e:
48-
# If AFNI is outdated, afni_vcheck throws error
49-
warn('AFNI is outdated')
50-
return str(e).split('\n')[4].split('=', 1)[1].strip()
51-
52-
# Try to parse the version number
53-
out = clout.runtime.stdout.split('\n')[1].split('=', 1)[1].strip()
52+
# If AFNI is outdated, afni_vcheck throws error.
53+
# Show new version, but parse current anyways.
54+
currv = str(e).split('\n')[4].split('=', 1)[1].strip()
55+
nextv = str(e).split('\n')[6].split('=', 1)[1].strip()
56+
iflogger.warn(
57+
'AFNI is outdated, detected version %s and %s is available.' % (currv, nextv))
5458

55-
if out.startswith('AFNI_'):
56-
out = out[5:]
59+
if currv.startswith('AFNI_'):
60+
currv = currv[5:]
5761

58-
v = out.split('.')
62+
v = currv.split('.')
5963
try:
6064
v = [int(n) for n in v]
6165
except ValueError:
62-
return out
66+
return currv
6367
return tuple(v)
6468

6569
@classmethod

nipype/interfaces/afni/preprocess.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
>>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))
99
>>> os.chdir(datadir)
1010
"""
11-
import warnings
1211

1312
import os
1413
import re
14+
from warnings import warn
1515

1616
from .base import AFNICommand, AFNICommandInputSpec, AFNICommandOutputSpec
1717
from ..base import CommandLineInputSpec, CommandLine, OutputMultiPath
@@ -20,8 +20,6 @@
2020
from ...utils.filemanip import (load_json, save_json, split_filename)
2121
from ...utils.filemanip import fname_presuffix
2222

23-
warn = warnings.warn
24-
2523

2624
class To3DInputSpec(AFNICommandInputSpec):
2725
out_file = File(name_template="%s", desc='output image file name',

0 commit comments

Comments
 (0)