From e804c8b46d2e784cebec2b14ff2df77e0bc9e425 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Mon, 19 Feb 2024 15:31:08 -0800 Subject: [PATCH] [lldb] Migrate distutils.version.LooseVersion to packaging (#82066) The distutils package has been deprecated and was removed from Python 3.12. The migration page [1] advises to use the packaging module instead. Since Python 3.6 that's vendored into pkg_resources. [1] https://peps.python.org/pep-0632/#migration-advice (cherry picked from commit 0c02329ff375100ddcf2cb104aebe97bb3c9126f) --- .../Python/lldbsuite/test/lldbplatformutil.py | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py index 9f5443ed621f37..73ddb397e7b254 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py +++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py @@ -9,8 +9,8 @@ import subprocess import sys import os -from distutils.version import LooseVersion from urllib.parse import urlparse +from pkg_resources import packaging # LLDB modules import lldb @@ -297,27 +297,30 @@ def expectedCompilerVersion(compiler_version): if compiler_version is None: return True operator = str(compiler_version[0]) - version = compiler_version[1] + version_str = str(compiler_version[1]) - if version is None: + if not version_str: return True - test_compiler_version = getCompilerVersion() - if test_compiler_version == "unknown": + test_compiler_version_str = getCompilerVersion() + if test_compiler_version_str == "unknown": # Assume the compiler version is at or near the top of trunk. return operator in [">", ">=", "!", "!=", "not"] + version = packaging.version.parse(version_str) + test_compiler_version = packaging.version.parse(test_compiler_version_str) + if operator == ">": - return LooseVersion(test_compiler_version) > LooseVersion(version) + return test_compiler_version > version if operator == ">=" or operator == "=>": - return LooseVersion(test_compiler_version) >= LooseVersion(version) + return test_compiler_version >= version if operator == "<": - return LooseVersion(test_compiler_version) < LooseVersion(version) + return test_compiler_version < version if operator == "<=" or operator == "=<": - return LooseVersion(test_compiler_version) <= LooseVersion(version) + return test_compiler_version <= version if operator == "!=" or operator == "!" or operator == "not": - return str(version) not in str(test_compiler_version) - return str(version) in str(test_compiler_version) + return version_str not in test_compiler_version_str + return version_str in test_compiler_version_str def expectedCompiler(compilers):