Skip to content
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
20 changes: 12 additions & 8 deletions nipype/interfaces/ants/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""The ants module provides basic functions for interfacing with ANTS tools."""
import os
from packaging.version import Version, parse

# Local imports
from ... import logging, LooseVersion
from ... import logging
from ..base import CommandLine, CommandLineInputSpec, traits, isdefined, PackageInfo

iflogger = logging.getLogger("nipype.interface")
Expand Down Expand Up @@ -43,13 +44,16 @@ def parse_version(raw_info):
# -githash may or may not be appended
v_string = v_string.split("-")[0]

# 2.2.0-equivalent version string
if "post" in v_string and LooseVersion(v_string) >= LooseVersion(
"2.1.0.post789"
):
return "2.2.0"
else:
return ".".join(v_string.split(".")[:3])
version = parse(v_string)

# Known mislabeled versions
if version.is_postrelease:
if version.base_version == "2.1.0" and version.post >= 789:
return "2.2.0"

# Unless we know of a specific reason to re-version, we will
# treat the base version (before pre/post/dev) as authoritative
return version.base_version


class ANTSCommandInputSpec(CommandLineInputSpec):
Expand Down
25 changes: 25 additions & 0 deletions nipype/interfaces/ants/tests/test_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from nipype.interfaces.ants.base import Info

import pytest

# fmt: off
ANTS_VERSIONS = [("""\
ANTs Version: 2.3.3.dev168-g29bdf
Compiled: Jun 9 2020 03:44:55

""", "2.3.3"), ("""\
ANTs Version: v2.3.5.post76-g28dd25c
Compiled: Nov 16 2021 14:57:48

""", "2.3.5"), ("""\
ANTs Version: v2.1.0.post789-g0740f
Compiled: I don't still have this so not going to pretend

""", "2.2.0"),
]
# fmt: on


@pytest.mark.parametrize("raw_info, version", ANTS_VERSIONS)
def test_version_parser(raw_info, version):
assert Info.parse_version(raw_info) == version