Skip to content

Commit 9ced114

Browse files
committed
fix: afni version check
1 parent 6876a38 commit 9ced114

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

nipype/interfaces/afni/base.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from sys import platform
1111
from distutils import spawn
1212

13-
from ... import logging
13+
from ... import logging, LooseVersion
1414
from ...utils.filemanip import split_filename, fname_presuffix
1515

1616
from ..base import (
@@ -44,32 +44,25 @@ def version():
4444
4545
"""
4646
try:
47-
clout = CommandLine(command='afni_vcheck',
47+
clout = CommandLine(command='afni --version',
4848
terminal_output='allatonce').run()
49-
50-
# Try to parse the version number
51-
currv = clout.runtime.stdout.split('\n')[1].split('=', 1)[1].strip()
5249
except IOError:
5350
# If afni_vcheck is not present, return None
54-
IFLOGGER.warn('afni_vcheck executable not found.')
51+
IFLOGGER.warn('afni executable not found.')
5552
return None
56-
except RuntimeError as e:
57-
# If AFNI is outdated, afni_vcheck throws error.
58-
# Show new version, but parse current anyways.
59-
currv = str(e).split('\n')[4].split('=', 1)[1].strip()
60-
nextv = str(e).split('\n')[6].split('=', 1)[1].strip()
61-
IFLOGGER.warn(
62-
'AFNI is outdated, detected version %s and %s is available.' % (currv, nextv))
63-
64-
if currv.startswith('AFNI_'):
65-
currv = currv[5:]
66-
67-
v = currv.split('.')
68-
try:
69-
v = [int(n) for n in v]
70-
except ValueError:
71-
return currv
72-
return tuple(v)
53+
54+
version_stamp = clout.runtime.stdout.split('\n')[0].split('Version ')[1]
55+
if version_stamp.startswith('AFNI'):
56+
version_stamp = version_stamp.split('AFNI_')[1]
57+
elif version_stamp.startswith('Debian'):
58+
version_stamp = version_stamp.split('Debian-')[1].split('~')[0]
59+
else:
60+
return None
61+
62+
version = LooseVersion(version_stamp.replace('_', '.')).version[:3]
63+
if version[0] < 1000:
64+
version[0] = version[0] + 2000
65+
return tuple(version)
7366

7467
@classmethod
7568
def output_type_to_ext(cls, outputtype):

nipype/interfaces/afni/preprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ def __init__(self, **inputs):
14571457
version = Info.version()
14581458

14591459
# As of AFNI 16.0.00, redirect_x is not needed
1460-
if isinstance(version[0], int) and version[0] > 15:
1460+
if version[0] > 2015:
14611461
self._redirect_x = False
14621462

14631463
def _parse_inputs(self, skip=None):
@@ -2150,7 +2150,7 @@ def __init__(self, **inputs):
21502150
v = Info.version()
21512151

21522152
# As of AFNI 16.0.00, redirect_x is not needed
2153-
if isinstance(v[0], int) and v[0] > 15:
2153+
if v[0] > 2015:
21542154
self._redirect_x = False
21552155

21562156

0 commit comments

Comments
 (0)