-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[lldb] Use packaging module instead of pkg_resources #93712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) ChangesUse 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 [1] https://pypi.org/project/packaging/ Full diff: https://github.com/llvm/llvm-project/pull/93712.diff 4 Files Affected:
diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py
index 79cc0a2aeacbe..4b85219ce7c19 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 187d16aa1baa6..ecc814b016059 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 d770447f0771c..6dd838dab168b 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 d3c25bd944e98..9db2b133483a8 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:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but heads up for @mysterymath if this causes issues w/ Fuchsia's build
At least at present, this will probably break Fuchsia's build; the Python we ship includes |
I'm not sure but I don't think so. IIUC the expectation that if folks want to use the packaging module, they have to install it themselves (i.e. with pip). I'm not sure all the bots have this package which is the reason I went with the |
|
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/
fad874b
to
e15e578
Compare
GreenDragon now has @labath Does your ✅ mean the debian bot has this package installed? |
We don't have So far we've avoided providing or requiring any additional Python dependencies, since we have relatively strict requirements for software chain of custody. If this change goes forward, we'd probably need to figure out a way to build |
Did a bit of digging around; it looks like at the very least the Arch Linux python package and the Python docker container don't contain the |
Affirmative.
FWIW, there appears to be an actual arch package for this https://archlinux.org/packages/extra/any/python-packaging/, so it shouldn't be (I think -- I'm not an Arch user) necessary to install That said, using a package designed (AIUI) for python versions for parsing versions of gcc/clang does strike me as somewhat... unusual, even if it does work, so maybe there is case to be made for writing something custom (I'm not sure if we really need anything more elaborate than |
Agreed. The first time I took a stab at this, that was the first thing I tried, but I quickly discovered that we had at least one tool (I think it was Python itself?) that contained alphabetical characters (something like |
Homebrew on macOS works similarly, it has a python-packaging package that you install with |
Notably the other packages are optional; the lion's share of the test suite can be run without them. Cursorily it looks like this wouldn't be the case here? Admittedly, Fuchsia is the reason at least one of those callouts has been added; we've struggled reigning in LLVM/LLDB's deps due to the manual nature of our build scripts, difficulty keeping things hermetic, and bureaucratic hassles involved in taking on new deps. But it might be a good idea to have a broader discussion about what the mandatory dep story is/should be for parts of LLVM, rather than doing this piecemeal on patches like this. EDIT: |
Ah yes, I guess one of the versions we are parsing is the version of python itself..
While I don't think we should be adding deps willy-nilly, I don't think this one is more problematic than others in that they are all available through common package management systems. OTOH, it has two things going against it:
This does not constitute an endorsement of one direction of the other, I'm just thinking out loud. |
Thanks for checking @mysterymath. Based on your response it sounds like we have a path forward for the Fuchsia bots. Please let me know when it's safe to land this. I'll add |
@JDevlieghere , we just landed a patch that adds |
This is breaking the github CI as seen here: https://buildkite.com/llvm-project/github-pull-requests/builds/73339#01902659-9fbc-44d2-9a5b-783f5af41b78. Should we add the "packaging" module to https://github.com/llvm/llvm-project/blob/main/lldb/test/requirements.txt ? |
To fix CI after llvm#93712 landed.
To fix CI after #93712 landed.
This should fix the failures that started happening after llvm#93712 landed.
…es (llvm#95971) This should fix the failures that started happening after llvm#93712 landed.
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/
This module is used in various helper scripts since llvm#93712
…m#111747) This module is used in various helper scripts since llvm#93712
…m#111747) This module is used in various helper scripts since llvm#93712
…m#111747) This module is used in various helper scripts since llvm#93712
…m#111747) This module is used in various helper scripts since llvm#93712
…m#111747) This module is used in various helper scripts since llvm#93712
…m#111747) This module is used in various helper scripts since 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/