@@ -37,10 +37,30 @@ def version():
3737 Version number as string or None if AFNI not found
3838
3939 """
40- clout = CommandLine (command = 'afni_vcheck' ,
41- terminal_output = 'allatonce' ).run ()
42- out = clout .runtime .stdout
43- return out .split ('\n ' )[1 ]
40+ try :
41+ clout = CommandLine (command = 'afni_vcheck' ,
42+ terminal_output = 'allatonce' ).run ()
43+ except IOError :
44+ # If afni_vcheck is not present, return None
45+ warn ('afni_vcheck executable not found.' )
46+ return None
47+ 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 ()
54+
55+ if out .startswith ('AFNI_' ):
56+ out = out [5 :]
57+
58+ v = out .split ('.' )
59+ try :
60+ v = [int (n ) for n in v ]
61+ except ValueError :
62+ return out
63+ return tuple (v )
4464
4565 @classmethod
4666 def outputtype_to_ext (cls , outputtype ):
@@ -160,3 +180,10 @@ def _list_outputs(self):
160180 if ext == "" :
161181 outputs [name ] = outputs [name ] + "+orig.BRIK"
162182 return outputs
183+
184+
185+ def no_afni ():
186+ """ Checks if AFNI is available """
187+ if Info .version () is None :
188+ return True
189+ return False
0 commit comments