Skip to content

Commit b1b5595

Browse files
tuliommedismailben
authored andcommitted
[lldb] Replace the usage of module imp with module importlib (llvm#70443)
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)
1 parent 0202db8 commit b1b5595

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

lldb/scripts/use_lldb_suite.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ def find_lldb_root():
1616
return lldb_root
1717

1818
lldb_root = find_lldb_root()
19-
import imp
20-
fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
21-
try:
22-
imp.load_module("use_lldb_suite_root", fp, pathname, desc)
23-
finally:
24-
if fp:
25-
fp.close()
19+
20+
import importlib.machinery
21+
import importlib.util
22+
23+
path = os.path.join(lldb_root, "use_lldb_suite_root.py")
24+
loader = importlib.machinery.SourceFileLoader("use_lldb_suite_root", path)
25+
spec = importlib.util.spec_from_loader("use_lldb_suite_root", loader=loader)
26+
module = importlib.util.module_from_spec(spec)
27+
loader.exec_module(module)

lldb/test/API/use_lldb_suite.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def find_lldb_root():
2020

2121
lldb_root = find_lldb_root()
2222

23-
import imp
23+
import importlib.machinery
24+
import importlib.util
2425

25-
fp, pathname, desc = imp.find_module("use_lldb_suite_root", [lldb_root])
26-
try:
27-
imp.load_module("use_lldb_suite_root", fp, pathname, desc)
28-
finally:
29-
if fp:
30-
fp.close()
26+
path = os.path.join(lldb_root, "use_lldb_suite_root.py")
27+
loader = importlib.machinery.SourceFileLoader("use_lldb_suite_root", path)
28+
spec = importlib.util.spec_from_loader("use_lldb_suite_root", loader=loader)
29+
module = importlib.util.module_from_spec(spec)
30+
loader.exec_module(module)

0 commit comments

Comments
 (0)