Skip to content

[ENH] Improved AFNI version parsing after recent publication of 16.0.01 #1337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions nipype/interfaces/afni/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@


import os
import warnings

from ... import logging
from ...utils.filemanip import split_filename
from ..base import (
CommandLine, traits, CommandLineInputSpec, isdefined, File, TraitedSpec)

warn = warnings.warn
# Use nipype's logging system
iflogger = logging.getLogger('interface')


class Info(object):
Expand Down Expand Up @@ -40,26 +41,29 @@ def version():
try:
clout = CommandLine(command='afni_vcheck',
terminal_output='allatonce').run()

# Try to parse the version number
currv = clout.runtime.stdout.split('\n')[1].split('=', 1)[1].strip()
except IOError:
# If afni_vcheck is not present, return None
warn('afni_vcheck executable not found.')
iflogger.warn('afni_vcheck executable not found.')
return None
except RuntimeError as e:
# If AFNI is outdated, afni_vcheck throws error
warn('AFNI is outdated')
return str(e).split('\n')[4].split('=', 1)[1].strip()

# Try to parse the version number
out = clout.runtime.stdout.split('\n')[1].split('=', 1)[1].strip()
# If AFNI is outdated, afni_vcheck throws error.
# Show new version, but parse current anyways.
currv = str(e).split('\n')[4].split('=', 1)[1].strip()
nextv = str(e).split('\n')[6].split('=', 1)[1].strip()
iflogger.warn(
'AFNI is outdated, detected version %s and %s is available.' % (currv, nextv))

if out.startswith('AFNI_'):
out = out[5:]
if currv.startswith('AFNI_'):
currv = currv[5:]

v = out.split('.')
v = currv.split('.')
try:
v = [int(n) for n in v]
except ValueError:
return out
return currv
return tuple(v)

@classmethod
Expand Down
4 changes: 1 addition & 3 deletions nipype/interfaces/afni/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
>>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))
>>> os.chdir(datadir)
"""
import warnings

import os
import re
from warnings import warn

from .base import AFNICommand, AFNICommandInputSpec, AFNICommandOutputSpec
from ..base import CommandLineInputSpec, CommandLine, OutputMultiPath
Expand All @@ -20,8 +20,6 @@
from ...utils.filemanip import (load_json, save_json, split_filename)
from ...utils.filemanip import fname_presuffix

warn = warnings.warn


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