Skip to content

Commit 0c02329

Browse files
committed
[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
1 parent 8c5c4d9 commit 0c02329

File tree

5 files changed

+40
-36
lines changed

5 files changed

+40
-36
lines changed

lldb/packages/Python/lldbsuite/test/decorators.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# System modules
2-
from distutils.version import LooseVersion
32
from functools import wraps
3+
from pkg_resources import packaging
44
import ctypes
55
import locale
66
import os
@@ -65,10 +65,10 @@ def fn_neq(x, y):
6565
">=": fn_geq,
6666
"<=": fn_leq,
6767
}
68-
expected_str = ".".join([str(x) for x in expected])
69-
actual_str = ".".join([str(x) for x in actual])
7068

71-
return op_lookup[comparison](LooseVersion(actual_str), LooseVersion(expected_str))
69+
return op_lookup[comparison](
70+
packaging.version.parse(actual), packaging.version.parse(expected)
71+
)
7272

7373

7474
def _match_decorator_property(expected, actual):
@@ -238,7 +238,9 @@ def fn(actual_debug_info=None):
238238
)
239239
)
240240
skip_for_py_version = (py_version is None) or _check_expected_version(
241-
py_version[0], py_version[1], sys.version_info
241+
py_version[0],
242+
py_version[1],
243+
"{}.{}".format(sys.version_info.major, sys.version_info.minor),
242244
)
243245
skip_for_macos_version = (macos_version is None) or (
244246
(platform.mac_ver()[0] != "")

lldb/packages/Python/lldbsuite/test/lldbplatformutil.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import subprocess
88
import sys
99
import os
10-
from distutils.version import LooseVersion
1110
from urllib.parse import urlparse
11+
from pkg_resources import packaging
1212

1313
# LLDB modules
1414
import lldb
@@ -297,27 +297,30 @@ def expectedCompilerVersion(compiler_version):
297297
if compiler_version is None:
298298
return True
299299
operator = str(compiler_version[0])
300-
version = compiler_version[1]
300+
version_str = str(compiler_version[1])
301301

302-
if version is None:
302+
if not version_str:
303303
return True
304304

305-
test_compiler_version = getCompilerVersion()
306-
if test_compiler_version == "unknown":
305+
test_compiler_version_str = getCompilerVersion()
306+
if test_compiler_version_str == "unknown":
307307
# Assume the compiler version is at or near the top of trunk.
308308
return operator in [">", ">=", "!", "!=", "not"]
309309

310+
version = packaging.version.parse(version_str)
311+
test_compiler_version = packaging.version.parse(test_compiler_version_str)
312+
310313
if operator == ">":
311-
return LooseVersion(test_compiler_version) > LooseVersion(version)
314+
return test_compiler_version > version
312315
if operator == ">=" or operator == "=>":
313-
return LooseVersion(test_compiler_version) >= LooseVersion(version)
316+
return test_compiler_version >= version
314317
if operator == "<":
315-
return LooseVersion(test_compiler_version) < LooseVersion(version)
318+
return test_compiler_version < version
316319
if operator == "<=" or operator == "=<":
317-
return LooseVersion(test_compiler_version) <= LooseVersion(version)
320+
return test_compiler_version <= version
318321
if operator == "!=" or operator == "!" or operator == "not":
319-
return str(version) not in str(test_compiler_version)
320-
return str(version) in str(test_compiler_version)
322+
return version_str not in test_compiler_version_str
323+
return version_str in test_compiler_version_str
321324

322325

323326
def expectedCompiler(compilers):
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
"""
2-
This is a sanity check that verifies that test can be sklipped based on settings.
2+
This is a sanity check that verifies that test can be skipped based on settings.
33
"""
44

5-
65
import lldb
76
from lldbsuite.test.lldbtest import *
87
from lldbsuite.test.decorators import *
98

109

1110
class SettingSkipSanityTestCase(TestBase):
1211
NO_DEBUG_INFO_TESTCASE = True
12+
CURRENT_PYTHON_VERSION = "3.0"
1313

14-
@skipIf(py_version=(">=", (3, 0)))
14+
@skipIf(py_version=(">=", CURRENT_PYTHON_VERSION))
1515
def testSkip(self):
16-
"""This setting is on by default"""
17-
self.assertTrue(False, "This test should not run!")
18-
19-
@skipIf(py_version=("<", (3, 0)))
20-
def testNoMatch(self):
21-
self.assertTrue(True, "This test should run!")
16+
self.assertTrue(False, "This test should not run and fail (SKIPPED)")
2217

23-
@skipIf(setting=("target.i-made-this-one-up", "true"))
24-
def testNotExisting(self):
25-
self.assertTrue(True, "This test should run!")
18+
@skipIf(py_version=("<", CURRENT_PYTHON_VERSION))
19+
def testNoSKip(self):
20+
self.assertTrue(True, "This test should run and pass(PASS)")
2621

27-
@expectedFailureAll(py_version=(">=", (3, 0)))
22+
@expectedFailureAll(py_version=(">=", CURRENT_PYTHON_VERSION))
2823
def testXFAIL(self):
29-
self.assertTrue(False, "This test should run and fail!")
24+
self.assertTrue(False, "This test should expectedly fail (XFAIL)")
3025

31-
@expectedFailureAll(py_version=("<", (3, 0)))
26+
@expectedFailureAll(py_version=("<", CURRENT_PYTHON_VERSION))
3227
def testNotXFAIL(self):
33-
self.assertTrue(True, "This test should run and succeed!")
28+
self.assertTrue(True, "This test should pass (PASS)")
29+
30+
@skipIf(setting=("target.i-made-this-one-up", "true"))
31+
def testNotExisting(self):
32+
self.assertTrue(True, "This test should run!")

lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ def check_simulator_ostype(self, sdk, platform_name, arch=platform.machine()):
6161

6262
# Older versions of watchOS (<7.0) only support i386
6363
if platform_name == "watchos":
64-
from distutils.version import LooseVersion
64+
from pkg_resources import packaging
6565

66-
if LooseVersion(vers) < LooseVersion("7.0"):
66+
if packaging.version.parse(vers) < packaging.version.parse("7.0"):
6767
arch = "i386"
6868

6969
triple = "-".join([arch, "apple", platform_name + vers, "simulator"])

lldb/test/Shell/helper/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,9 @@ def _find_windows_sdk_in_registry_view(self, view):
519519

520520
# Windows SDK version numbers consist of 4 dotted components, so we
521521
# have to use LooseVersion, as StrictVersion supports 3 or fewer.
522-
from distutils.version import LooseVersion
522+
from pkg_resources import packaging
523523

524-
sdk_versions.sort(key=lambda x: LooseVersion(x), reverse=True)
524+
sdk_versions.sort(key=lambda x: packaging.version.parse(x), reverse=True)
525525
option_value_name = "OptionId.DesktopCPP" + self.msvc_arch_str
526526
for v in sdk_versions:
527527
try:

0 commit comments

Comments
 (0)