https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/93712
>From 4666a6a6470fc91ed17a9e60624a005dc97c4531 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere <jo...@devlieghere.com> Date: Wed, 29 May 2024 10:36:47 -0700 Subject: [PATCH 1/2] [lldb] Use packaging module instead of pkg_resources Use the packaging [1] module for parsing version numbers, instead of pkg_resources which is distributed with setuptools. I recently switched over to using the latter, knowing it was deprecated (in favor of the packaging module) because it comes with Python out of the box. Newer versions of setuptools have removed `pkg_resources` so we have to use packaging. [1] https://pypi.org/project/packaging/ --- lldb/packages/Python/lldbsuite/test/decorators.py | 6 ++---- lldb/packages/Python/lldbsuite/test/lldbplatformutil.py | 7 +++---- .../test/API/tools/lldb-server/TestAppleSimulatorOSType.py | 4 ++-- lldb/test/Shell/helper/build.py | 4 ++-- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py index 79cc0a2aeacbeb..4b85219ce7c19c 100644 --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -1,6 +1,6 @@ # System modules from functools import wraps -from pkg_resources import packaging +from packaging.version import parse import ctypes import locale import os @@ -66,9 +66,7 @@ def fn_neq(x, y): "<=": fn_leq, } - return op_lookup[comparison]( - packaging.version.parse(actual), packaging.version.parse(expected) - ) + return op_lookup[comparison](parse(actual), parse(expected)) def _match_decorator_property(expected, actual): diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py index 187d16aa1baa68..ecc814b0160597 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py +++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py @@ -8,8 +8,7 @@ import subprocess import sys import os -from urllib.parse import urlparse -from pkg_resources import packaging +from packaging.version import parse # LLDB modules import lldb @@ -309,8 +308,8 @@ def expectedCompilerVersion(compiler_version): # 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) + version = parse(version_str) + test_compiler_version = parse(test_compiler_version_str) if operator == ">": return test_compiler_version > version diff --git a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py index d770447f0771cd..6dd838dab168bf 100644 --- a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py +++ b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py @@ -61,9 +61,9 @@ def check_simulator_ostype(self, sdk, platform_name, arch=platform.machine()): # Older versions of watchOS (<7.0) only support i386 if platform_name == "watchos": - from pkg_resources import packaging + from packaging.version import parse - if packaging.version.parse(vers) < packaging.version.parse("7.0"): + if parse(vers) < parse("7.0"): arch = "i386" triple = "-".join([arch, "apple", platform_name + vers, "simulator"]) diff --git a/lldb/test/Shell/helper/build.py b/lldb/test/Shell/helper/build.py index d3c25bd944e983..9db2b133483a8f 100755 --- a/lldb/test/Shell/helper/build.py +++ b/lldb/test/Shell/helper/build.py @@ -519,9 +519,9 @@ def _find_windows_sdk_in_registry_view(self, view): # Windows SDK version numbers consist of 4 dotted components, so we # have to use LooseVersion, as StrictVersion supports 3 or fewer. - from pkg_resources import packaging + from packaging.version import parse - sdk_versions.sort(key=lambda x: packaging.version.parse(x), reverse=True) + sdk_versions.sort(key=lambda x: parse(x), reverse=True) option_value_name = "OptionId.DesktopCPP" + self.msvc_arch_str for v in sdk_versions: try: >From e15e578b70311eb9140020e0cb71179d3d5be088 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere <jo...@devlieghere.com> Date: Thu, 30 May 2024 10:01:01 -0700 Subject: [PATCH 2/2] Address review feedback --- lldb/packages/Python/lldbsuite/test/decorators.py | 4 ++-- .../Python/lldbsuite/test/lldbplatformutil.py | 14 +++++++------- .../tools/lldb-server/TestAppleSimulatorOSType.py | 4 ++-- lldb/test/Shell/helper/build.py | 10 ++++------ 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py index 4b85219ce7c19c..ecc7b81035f11f 100644 --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -1,6 +1,6 @@ # System modules from functools import wraps -from packaging.version import parse +from packaging import version import ctypes import locale import os @@ -66,7 +66,7 @@ def fn_neq(x, y): "<=": fn_leq, } - return op_lookup[comparison](parse(actual), parse(expected)) + return op_lookup[comparison](version.parse(actual), version.parse(expected)) def _match_decorator_property(expected, actual): diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py index ecc814b0160597..21f2095db90f8f 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py +++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py @@ -8,7 +8,7 @@ import subprocess import sys import os -from packaging.version import parse +from packaging import version # LLDB modules import lldb @@ -308,17 +308,17 @@ def expectedCompilerVersion(compiler_version): # Assume the compiler version is at or near the top of trunk. return operator in [">", ">=", "!", "!=", "not"] - version = parse(version_str) - test_compiler_version = parse(test_compiler_version_str) + actual_version = version.parse(version_str) + test_compiler_version = version.parse(test_compiler_version_str) if operator == ">": - return test_compiler_version > version + return test_compiler_version > actual_version if operator == ">=" or operator == "=>": - return test_compiler_version >= version + return test_compiler_version >= actual_version if operator == "<": - return test_compiler_version < version + return test_compiler_version < actual_version if operator == "<=" or operator == "=<": - return test_compiler_version <= version + return test_compiler_version <= actual_version if operator == "!=" or operator == "!" or operator == "not": return version_str not in test_compiler_version_str return version_str in test_compiler_version_str diff --git a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py index 6dd838dab168bf..754579a59c11e5 100644 --- a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py +++ b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py @@ -61,9 +61,9 @@ def check_simulator_ostype(self, sdk, platform_name, arch=platform.machine()): # Older versions of watchOS (<7.0) only support i386 if platform_name == "watchos": - from packaging.version import parse + from packaging import version - if parse(vers) < parse("7.0"): + if version.parse(vers) < version.parse("7.0"): arch = "i386" triple = "-".join([arch, "apple", platform_name + vers, "simulator"]) diff --git a/lldb/test/Shell/helper/build.py b/lldb/test/Shell/helper/build.py index 9db2b133483a8f..b2b8146e88c75b 100755 --- a/lldb/test/Shell/helper/build.py +++ b/lldb/test/Shell/helper/build.py @@ -441,9 +441,9 @@ def _get_vctools_version(self): if not subdirs: return None - from distutils.version import StrictVersion + from packaging import version - subdirs.sort(key=lambda x: StrictVersion(x)) + subdirs.sort(key=lambda x: version.parse(x)) if self.verbose: full_path = os.path.join(vcinstalldir, subdirs[-1]) @@ -517,11 +517,9 @@ def _find_windows_sdk_in_registry_view(self, view): if not sdk_versions: return (None, None) - # Windows SDK version numbers consist of 4 dotted components, so we - # have to use LooseVersion, as StrictVersion supports 3 or fewer. - from packaging.version import parse + from packaging import version - sdk_versions.sort(key=lambda x: parse(x), reverse=True) + sdk_versions.sort(key=lambda x: version.parse(x), reverse=True) option_value_name = "OptionId.DesktopCPP" + self.msvc_arch_str for v in sdk_versions: try: _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits