From 69c95b5341dc205db46cdbbef5b3f5538cfa21c3 Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Thu, 22 Dec 2022 18:31:36 +0100 Subject: [PATCH] Provide a replacement for distutils.version.LooseVersion --- waflib/Tools/python.py | 7 +++---- waflib/Utils.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/waflib/Tools/python.py b/waflib/Tools/python.py index 046b8390..48e2be50 100644 --- a/waflib/Tools/python.py +++ b/waflib/Tools/python.py @@ -585,13 +585,12 @@ def check_python_module(conf, module_name, condition=''): if ret == 'unknown version': conf.fatal('Could not check the %s version' % module_name) - from distutils.version import LooseVersion def num(*k): if isinstance(k[0], int): - return LooseVersion('.'.join([str(x) for x in k])) + return Utils.loose_version('.'.join([str(x) for x in k])) else: - return LooseVersion(k[0]) - d = {'num': num, 'ver': LooseVersion(ret)} + return Utils.loose_version(k[0]) + d = {'num': num, 'ver': Utils.loose_version(ret)} ev = eval(condition, {}, d) if not ev: conf.fatal('The %s version does not satisfy the requirements' % module_name) diff --git a/waflib/Utils.py b/waflib/Utils.py index 31618cb8..ea0f7a9d 100644 --- a/waflib/Utils.py +++ b/waflib/Utils.py @@ -870,6 +870,19 @@ def lib64(): return '64' return '' +def loose_version(ver_str): + # private for the time being! + # see #2402 + lst = re.split(r'([.]|\\d+|[a-zA-Z])', ver_str) + ver = [] + for i, val in enumerate(lst): + try: + ver.append(int(val)) + except ValueError: + if val != '.': + ver.append(val) + return ver + def sane_path(p): # private function for the time being! return os.path.abspath(os.path.expanduser(p))