[lldb] Replace the usage of module imp with module importlib (#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
This commit is contained in:
Tulio Magno Quites Machado Filho 2023-10-31 17:08:55 -03:00 committed by GitHub
parent b799080f19
commit 2260ebf7b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 14 deletions

View File

@ -17,11 +17,12 @@ 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()
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)

View File

@ -20,11 +20,11 @@ def find_lldb_root():
lldb_root = find_lldb_root()
import imp
import importlib.machinery
import importlib.util
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()
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)