Skip to content

Commit 197ea62

Browse files
committed
FIX: Make vendored LooseVersion comparable to distutils.version.LooseVersion
1 parent 673ba95 commit 197ea62

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

nipype/external/version.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
of the same class, thus must follow the same rules)
3939
"""
4040

41+
import sys
4142
import re
4243

4344

@@ -211,14 +212,27 @@ def __repr__(self):
211212
return "LooseVersion ('%s')" % str(self)
212213

213214
def _cmp(self, other):
214-
if isinstance(other, str):
215-
other = LooseVersion(other)
216-
elif not isinstance(other, LooseVersion):
217-
return NotImplemented
215+
other = self._coerce(other)
218216

219217
if self.version == other.version:
220218
return 0
221219
if self.version < other.version:
222220
return -1
223221
if self.version > other.version:
224222
return 1
223+
224+
@staticmethod
225+
def _coerce(other):
226+
if isinstance(other, LooseVersion):
227+
return other
228+
elif isinstance(other, str):
229+
return LooseVersion(other)
230+
elif "distutils" in sys.modules:
231+
# Using this check to avoid importing distutils and suppressing the warning
232+
try:
233+
from distutils.version import LooseVersion as deprecated
234+
except ImportError:
235+
return NotImplemented
236+
if isinstance(other, deprecated):
237+
return LooseVersion(str(other))
238+
return NotImplemented

0 commit comments

Comments
 (0)