Skip to content

Commit b20763e

Browse files
authored
Merge pull request #3444 from effigies/fix/ants_version
FIX: Use a more robust strategy for detecting ANTs version
2 parents e31573b + e731468 commit b20763e

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

nipype/interfaces/ants/base.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
# vi: set ft=python sts=4 ts=4 sw=4 et:
44
"""The ants module provides basic functions for interfacing with ANTS tools."""
55
import os
6+
from packaging.version import Version, parse
67

78
# Local imports
8-
from ... import logging, LooseVersion
9+
from ... import logging
910
from ..base import CommandLine, CommandLineInputSpec, traits, isdefined, PackageInfo
1011

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

46-
# 2.2.0-equivalent version string
47-
if "post" in v_string and LooseVersion(v_string) >= LooseVersion(
48-
"2.1.0.post789"
49-
):
50-
return "2.2.0"
51-
else:
52-
return ".".join(v_string.split(".")[:3])
47+
version = parse(v_string)
48+
49+
# Known mislabeled versions
50+
if version.is_postrelease:
51+
if version.base_version == "2.1.0" and version.post >= 789:
52+
return "2.2.0"
53+
54+
# Unless we know of a specific reason to re-version, we will
55+
# treat the base version (before pre/post/dev) as authoritative
56+
return version.base_version
5357

5458

5559
class ANTSCommandInputSpec(CommandLineInputSpec):
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from nipype.interfaces.ants.base import Info
2+
3+
import pytest
4+
5+
# fmt: off
6+
ANTS_VERSIONS = [("""\
7+
ANTs Version: 2.3.3.dev168-g29bdf
8+
Compiled: Jun 9 2020 03:44:55
9+
10+
""", "2.3.3"), ("""\
11+
ANTs Version: v2.3.5.post76-g28dd25c
12+
Compiled: Nov 16 2021 14:57:48
13+
14+
""", "2.3.5"), ("""\
15+
ANTs Version: v2.1.0.post789-g0740f
16+
Compiled: I don't still have this so not going to pretend
17+
18+
""", "2.2.0"),
19+
]
20+
# fmt: on
21+
22+
23+
@pytest.mark.parametrize("raw_info, version", ANTS_VERSIONS)
24+
def test_version_parser(raw_info, version):
25+
assert Info.parse_version(raw_info) == version

0 commit comments

Comments
 (0)