Skip to content

Commit fd729e3

Browse files
committed
RF: Use a more robust version parsing strategy for ANTs
1 parent f7ff56f commit fd729e3

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

nipype/interfaces/ants/base.py

Lines changed: 13 additions & 11 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")
@@ -42,16 +43,17 @@ def parse_version(raw_info):
4243

4344
# -githash may or may not be appended
4445
v_string = v_string.split("-")[0]
45-
# if there is a 'v' at the beginning, it may be stripped
46-
v_string = v_string.lstrip('v')
47-
48-
# 2.2.0-equivalent version string
49-
if "post" in v_string and LooseVersion(v_string) >= LooseVersion(
50-
"2.1.0.post789"
51-
):
52-
return "2.2.0"
53-
else:
54-
return ".".join(v_string.split(".")[:3])
46+
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
5557

5658

5759
class ANTSCommandInputSpec(CommandLineInputSpec):

0 commit comments

Comments
 (0)