Skip to content

Commit a244471

Browse files
committed
ENH: Add AntsCommand.version property
1 parent 90d1d35 commit a244471

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

nipype/interfaces/ants/base.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
"""The ants module provides basic functions for interfacing with ANTS tools."""
55
from __future__ import print_function, division, unicode_literals, absolute_import
66
from builtins import str
7+
8+
import os
9+
import subprocess
10+
711
# Local imports
8-
from ... import logging
12+
from ... import logging, LooseVersion
913
from ..base import CommandLine, CommandLineInputSpec, traits, isdefined
1014
logger = logging.getLogger('interface')
1115

@@ -25,6 +29,33 @@
2529
ALT_ITKv4_THREAD_LIMIT_VARIABLE = 'ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS'
2630

2731

32+
class Info(object):
33+
_version = None
34+
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+
v_string = res.splitlines()[0].split(': ')[1]
50+
# 2.2.0-equivalent version string
51+
if LooseVersion(v_string) >= LooseVersion('2.1.0.post789-g0740f'):
52+
self._version = '2.2.0'
53+
else:
54+
self._version = '.'.join(v_string.split('.')[:3])
55+
56+
return self._version
57+
58+
2859
class ANTSCommandInputSpec(CommandLineInputSpec):
2960
"""Base Input Specification for all ANTS Commands
3061
"""
@@ -84,3 +115,7 @@ def set_default_num_threads(cls, num_threads):
84115
<instance>.inputs.num_threads
85116
"""
86117
cls._num_threads = num_threads
118+
119+
@property
120+
def version(self):
121+
return Info().version

0 commit comments

Comments
 (0)