Skip to content

Commit 22ea97d

Browse files
authored
[lldb] Use packaging module instead of pkg_resources (llvm#93712)
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/
1 parent c54f5f6 commit 22ea97d

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# System modules
22
from functools import wraps
3-
from pkg_resources import packaging
3+
from packaging import version
44
import ctypes
55
import locale
66
import os
@@ -66,9 +66,7 @@ def fn_neq(x, y):
6666
"<=": fn_leq,
6767
}
6868

69-
return op_lookup[comparison](
70-
packaging.version.parse(actual), packaging.version.parse(expected)
71-
)
69+
return op_lookup[comparison](version.parse(actual), version.parse(expected))
7270

7371

7472
def _match_decorator_property(expected, actual):

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import subprocess
99
import sys
1010
import os
11-
from urllib.parse import urlparse
12-
from pkg_resources import packaging
11+
from packaging import version
1312

1413
# LLDB modules
1514
import lldb
@@ -309,17 +308,17 @@ def expectedCompilerVersion(compiler_version):
309308
# Assume the compiler version is at or near the top of trunk.
310309
return operator in [">", ">=", "!", "!=", "not"]
311310

312-
version = packaging.version.parse(version_str)
313-
test_compiler_version = packaging.version.parse(test_compiler_version_str)
311+
actual_version = version.parse(version_str)
312+
test_compiler_version = version.parse(test_compiler_version_str)
314313

315314
if operator == ">":
316-
return test_compiler_version > version
315+
return test_compiler_version > actual_version
317316
if operator == ">=" or operator == "=>":
318-
return test_compiler_version >= version
317+
return test_compiler_version >= actual_version
319318
if operator == "<":
320-
return test_compiler_version < version
319+
return test_compiler_version < actual_version
321320
if operator == "<=" or operator == "=<":
322-
return test_compiler_version <= version
321+
return test_compiler_version <= actual_version
323322
if operator == "!=" or operator == "!" or operator == "not":
324323
return version_str not in test_compiler_version_str
325324
return version_str in test_compiler_version_str

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

+2-2
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 pkg_resources import packaging
64+
from packaging import version
6565

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

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

lldb/test/Shell/helper/build.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,9 @@ def _get_vctools_version(self):
441441
if not subdirs:
442442
return None
443443

444-
from distutils.version import StrictVersion
444+
from packaging import version
445445

446-
subdirs.sort(key=lambda x: StrictVersion(x))
446+
subdirs.sort(key=lambda x: version.parse(x))
447447

448448
if self.verbose:
449449
full_path = os.path.join(vcinstalldir, subdirs[-1])
@@ -517,11 +517,9 @@ def _find_windows_sdk_in_registry_view(self, view):
517517
if not sdk_versions:
518518
return (None, None)
519519

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

524-
sdk_versions.sort(key=lambda x: packaging.version.parse(x), reverse=True)
522+
sdk_versions.sort(key=lambda x: version.parse(x), reverse=True)
525523
option_value_name = "OptionId.DesktopCPP" + self.msvc_arch_str
526524
for v in sdk_versions:
527525
try:

0 commit comments

Comments
 (0)