Skip to content

Commit

Permalink
Merge pull request #3194 from fepegar/2615-packageinfo-niftyreg
Browse files Browse the repository at this point in the history
FIX: Use PackageInfo to get NiftyReg version
  • Loading branch information
effigies authored Mar 24, 2020
2 parents c37fcfb + 328bd4e commit 1ca5d4e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions nipype/interfaces/niftyreg/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import os

from ... import logging
from ..base import CommandLine, CommandLineInputSpec, traits, Undefined
from ..base import (CommandLine, CommandLineInputSpec, traits, Undefined,
PackageInfo)
from ...utils.filemanip import split_filename

iflogger = logging.getLogger("nipype.interface")
Expand All @@ -29,6 +30,14 @@ def get_custom_path(command, env_dir="NIFTYREGDIR"):
return os.path.join(os.getenv(env_dir, ""), command)


class Info(PackageInfo):
version_cmd = get_custom_path('reg_aladin') + ' --version'

@staticmethod
def parse_version(raw_info):
return raw_info


class NiftyRegCommandInputSpec(CommandLineInputSpec):
"""Input Spec for niftyreg interfaces."""

Expand All @@ -55,9 +64,8 @@ def __init__(self, required_version=None, **inputs):
self.num_threads = 1
super(NiftyRegCommand, self).__init__(**inputs)
self.required_version = required_version
_version = self.version_from_command()
_version = self.version
if _version:
_version = _version.decode("utf-8")
if self._min_version is not None and StrictVersion(
_version
) < StrictVersion(self._min_version):
Expand Down Expand Up @@ -91,11 +99,9 @@ def _environ_update(self):
self.inputs.omp_core_val = Undefined

def check_version(self):
_version = self.version_from_command()
_version = self.version
if not _version:
raise Exception("Niftyreg not found")
# Decoding to string:
_version = _version.decode("utf-8")
if StrictVersion(_version) < StrictVersion(self._min_version):
err = "A later version of Niftyreg is required (%s < %s)"
raise ValueError(err % (_version, self._min_version))
Expand All @@ -107,10 +113,10 @@ def check_version(self):

@property
def version(self):
return self.version_from_command()
return Info.version()

def exists(self):
return self.version_from_command() is not None
return self.version is not None

def _format_arg(self, name, spec, value):
if name == "omp_core_val":
Expand Down

0 comments on commit 1ca5d4e

Please sign in to comment.