Skip to content

Commit cdb16cb

Browse files
committed
[lldb] Migrate distutils.version.LooseVersion to packaging (llvm#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 0c02329)
1 parent 1555b73 commit cdb16cb

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import absolute_import
22

33
# System modules
4-
from distutils.version import LooseVersion
54
from functools import wraps
5+
from pkg_resources import packaging
66
import ctypes
77
import locale
88
import os
@@ -68,10 +68,10 @@ def fn_neq(x, y):
6868
">=": fn_geq,
6969
"<=": fn_leq,
7070
}
71-
expected_str = ".".join([str(x) for x in expected])
72-
actual_str = ".".join([str(x) for x in actual])
7371

74-
return op_lookup[comparison](LooseVersion(actual_str), LooseVersion(expected_str))
72+
return op_lookup[comparison](
73+
packaging.version.parse(actual), packaging.version.parse(expected)
74+
)
7575

7676

7777
def _match_decorator_property(expected, actual):
@@ -227,7 +227,9 @@ def fn(self):
227227
)
228228
)
229229
skip_for_py_version = (py_version is None) or _check_expected_version(
230-
py_version[0], py_version[1], sys.version_info
230+
py_version[0],
231+
py_version[1],
232+
"{}.{}".format(sys.version_info.major, sys.version_info.minor),
231233
)
232234
skip_for_macos_version = (macos_version is None) or (
233235
(platform.mac_ver()[0] != "")
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)