-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[lldb] Replace the usage of module imp with module importlib #70443
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
imp got removed in Python 3.12 [1] and the community recommends using importlib in newer Python versions. [1] https://docs.python.org/3.12/whatsnew/3.12.html#imp
@llvm/pr-subscribers-lldb Author: Tulio Magno Quites Machado Filho (tuliom) Changesimp got removed in Python 3.12 [1] and the community recommends using importlib in newer Python versions. [1] https://docs.python.org/3.12/whatsnew/3.12.html#imp Full diff: https://github.com/llvm/llvm-project/pull/70443.diff 2 Files Affected:
diff --git a/lldb/scripts/use_lldb_suite.py b/lldb/scripts/use_lldb_suite.py
index 6388d87b181ce03..4cedfa532cf972d 100644
--- a/lldb/scripts/use_lldb_suite.py
+++ b/lldb/scripts/use_lldb_suite.py
@@ -17,11 +17,25 @@ def find_lldb_root():
lldb_root = find_lldb_root()
-import imp
-
-fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
-try:
- imp.load_module("use_lldb_suite_root", fp, pathname, desc)
-finally:
- if fp:
- fp.close()
+
+# Module imp got removed in Python 3.12.
+if (
+ sys.version_info.major == 3 and sys.version_info.minor >= 12
+) or sys.version_info.major > 3:
+ import importlib.machinery
+ import importlib.util
+
+ path = os.path.join(lldb_root, "use_lldb_suite_root.py")
+ loader = importlib.machinery.SourceFileLoader("use_lldb_suite_root", path)
+ spec = importlib.util.spec_from_loader("use_lldb_suite_root", loader=loader)
+ module = importlib.util.module_from_spec(spec)
+ loader.exec_module(module)
+else:
+ import imp
+
+ fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
+ try:
+ imp.load_module("use_lldb_suite_root", fp, pathname, desc)
+ finally:
+ if fp:
+ fp.close()
diff --git a/lldb/test/API/use_lldb_suite.py b/lldb/test/API/use_lldb_suite.py
index e237dd4b8a5607c..c9332d9921b4eb3 100644
--- a/lldb/test/API/use_lldb_suite.py
+++ b/lldb/test/API/use_lldb_suite.py
@@ -20,11 +20,24 @@ def find_lldb_root():
lldb_root = find_lldb_root()
-import imp
-
-fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
-try:
- imp.load_module("use_lldb_suite_root", fp, pathname, desc)
-finally:
- if fp:
- fp.close()
+# Module imp got removed in Python 3.12.
+if (
+ sys.version_info.major == 3 and sys.version_info.minor >= 12
+) or sys.version_info.major > 3:
+ import importlib.machinery
+ import importlib.util
+
+ path = os.path.join(lldb_root, "use_lldb_suite_root.py")
+ loader = importlib.machinery.SourceFileLoader("use_lldb_suite_root", path)
+ spec = importlib.util.spec_from_loader("use_lldb_suite_root", loader=loader)
+ module = importlib.util.module_from_spec(spec)
+ loader.exec_module(module)
+else:
+ import imp
+
+ fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
+ try:
+ imp.load_module("use_lldb_suite_root", fp, pathname, desc)
+ finally:
+ if fp:
+ fp.close()
|
Do you know when @JDevlieghere will know for sure. |
This document mentions 3.1. |
I believe it's also important to mention this PR does not solve issue #70453. |
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.
importlib
has been around since Python 3.1, maybe we shouldn't have the conditional logic to use imp
instead? I'm pretty sure the minimum supported version is 3.6 since that's what LLVM requires.
+1, if you can verify that Python 3.6 supports the |
Do you know what is the reason for requiring such an old Python version? For the record, Ubuntu 18.04 does have Python 3.6, but it has cmake 3.10. |
The minimum supported version of Python is 3.6 because of the requirements of the The CMake portion is a little easier to manage -- You can build a newer version of CMake on Ubuntu 18.04 (that's what we do downstream for the Swift project). |
I confirmed the new code works with Python 3.6 and removed the conditional. |
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.
Thanks for taking the time to make sure it works with Python 3.6! I'm a big fan of this kind of modernization/cleanup work. 😄
) imp got removed in Python 3.12 [1] and the community recommends using importlib in newer Python versions. [1] https://docs.python.org/3.12/whatsnew/3.12.html#imp (cherry picked from commit 2260ebf)
) imp got removed in Python 3.12 [1] and the community recommends using importlib in newer Python versions. [1] https://docs.python.org/3.12/whatsnew/3.12.html#imp (cherry picked from commit 2260ebf)
imp got removed in Python 3.12 [1] and the community recommends using importlib in newer Python versions.
[1] https://docs.python.org/3.12/whatsnew/3.12.html#imp