Skip to content
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

FIX: Use PackageInfo to get NiftyReg version #3194

Merged
merged 2 commits into from
Mar 24, 2020
Merged
Changes from 1 commit
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
20 changes: 14 additions & 6 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,7 +99,7 @@ def _environ_update(self):
self.inputs.omp_core_val = Undefined

def check_version(self):
_version = self.version_from_command()
_version = self.version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L106 assumes this is a bytes object. I think it's going to be a str?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. I got an error because it was a str so I removed the old L60: https://github.com/nipy/nipype/pull/3194/files/199dc2e3e1a6c5dd0f8f35b6a6497015325ee85f#diff-84c9861899b85298fccffbb72fe8fe9eL60.

I'll remove this one too.

if not _version:
raise Exception("Niftyreg not found")
# Decoding to string:
Expand All @@ -107,10 +115,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