[Lldb-commits] [lldb] [lldb] Replace the usage of module imp with module importlib (PR #70443)

2023-10-31 Thread Tulio Magno Quites Machado Filho via lldb-commits

https://github.com/tuliom closed https://github.com/llvm/llvm-project/pull/70443
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Replace the usage of module imp with module importlib (PR #70443)

2023-10-31 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere approved this pull request.


https://github.com/llvm/llvm-project/pull/70443
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Replace the usage of module imp with module importlib (PR #70443)

2023-10-31 Thread Alex Langford via lldb-commits

https://github.com/bulbazord approved this pull request.

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. 😄 

https://github.com/llvm/llvm-project/pull/70443
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Replace the usage of module imp with module importlib (PR #70443)

2023-10-31 Thread Tulio Magno Quites Machado Filho via lldb-commits

tuliom wrote:

I confirmed the new code works with Python 3.6 and removed the conditional.

https://github.com/llvm/llvm-project/pull/70443
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Replace the usage of module imp with module importlib (PR #70443)

2023-10-31 Thread Tulio Magno Quites Machado Filho via lldb-commits

https://github.com/tuliom updated 
https://github.com/llvm/llvm-project/pull/70443

>From 16fd09f102eff20825847e32f225715960d1c082 Mon Sep 17 00:00:00 2001
From: Tulio Magno Quites Machado Filho 
Date: Wed, 25 Oct 2023 10:48:53 -0300
Subject: [PATCH 1/2] [lldb] Replace the usage of module imp with module
 importlib

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
---
 lldb/scripts/use_lldb_suite.py  | 30 ++
 lldb/test/API/use_lldb_suite.py | 29 +
 2 files changed, 43 insertions(+), 16 deletions(-)

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()

>From be8d5a305de8241d51fcca1189a3d56d9cfa9243 Mon Sep 17 00:00:00 2001
From: Tulio Magno Quites Machado Filho 
Date: Tue, 31 Oct 2023 15:05:24 -0300
Subject: [PATCH 2/2] fixup! [lldb] Replace the usage of module imp with module
 importlib

---
 lldb/scripts/use_lldb_suite.py  | 29 -
 lldb/test/API/use_lldb_suite.py | 29 -
 2 files changed, 16 insertions(+), 42 deletions(-)

diff --git a/lldb/scripts/use_lldb_suite.py b/lldb/scripts/use_lldb_suite.py
index 4cedfa532cf972d..a050db0e79e6807 100644
--- a/lldb/scripts/use_lldb_suite.py
+++ b/lldb/scripts/use_lldb_suite.py
@@ -18,24 +18,11 @@ def find_lldb_root():
 
 lldb_root = find_lldb_root()
 
-# 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()
+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)
diff --git a/lldb/test/API/use_lldb_suite.py b/lldb/test/API/us

[Lldb-commits] [lldb] [lldb] Replace the usage of module imp with module importlib (PR #70443)

2023-10-30 Thread Tulio Magno Quites Machado Filho via lldb-commits

tuliom wrote:

Do you know what is the reason for requiring such an old Python version?
I'm asking because it's been hard to find a distro that provides both Python 
3.6 (released in 2016) and cmake 3.20 (released in 2021).

For the record, Ubuntu 18.04 does have Python 3.6, but it has cmake 3.10.

https://github.com/llvm/llvm-project/pull/70443
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Replace the usage of module imp with module importlib (PR #70443)

2023-10-30 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

+1, if you can verify that Python 3.6 supports the `importlib` approach we 
should drop the fallback. 

https://github.com/llvm/llvm-project/pull/70443
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Replace the usage of module imp with module importlib (PR #70443)

2023-10-27 Thread Alex Langford via lldb-commits

https://github.com/bulbazord commented:

`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.

https://github.com/llvm/llvm-project/pull/70443
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Replace the usage of module imp with module importlib (PR #70443)

2023-10-27 Thread Tulio Magno Quites Machado Filho via lldb-commits

tuliom wrote:

I believe it's also important to mention this PR does not solve issue #70453.
But it helps to solve `ModuleNotFoundError: No module named 'imp'` kind of 
issues.

https://github.com/llvm/llvm-project/pull/70443
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Replace the usage of module imp with module importlib (PR #70443)

2023-10-27 Thread Tulio Magno Quites Machado Filho via lldb-commits

tuliom wrote:

[This document](https://docs.python.org/3/library/importlib.html) mentions 3.1.
Many functions were added after 3.6, but none of them are being explicitly used 
in this patch.
I'm afraid the easiest way to guarantee is by testing with Python 3.6.

https://github.com/llvm/llvm-project/pull/70443
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Replace the usage of module imp with module importlib (PR #70443)

2023-10-27 Thread David Spickett via lldb-commits

DavidSpickett wrote:

Do you know when `importlib` was added? I wonder if the overlap is enough to 
not need a fallback. We appear to advertise a 3.6 or 3.7 minimum in our 
documentation, and llvm wants >=3.6 
(https://llvm.org/docs/GettingStarted.html#software).

@JDevlieghere will know for sure.

https://github.com/llvm/llvm-project/pull/70443
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Replace the usage of module imp with module importlib (PR #70443)

2023-10-27 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Tulio Magno Quites Machado Filho (tuliom)


Changes

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

---
Full diff: https://github.com/llvm/llvm-project/pull/70443.diff


2 Files Affected:

- (modified) lldb/scripts/use_lldb_suite.py (+22-8) 
- (modified) lldb/test/API/use_lldb_suite.py (+21-8) 


``diff
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()

``




https://github.com/llvm/llvm-project/pull/70443
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Replace the usage of module imp with module importlib (PR #70443)

2023-10-27 Thread Tulio Magno Quites Machado Filho via lldb-commits

https://github.com/tuliom created 
https://github.com/llvm/llvm-project/pull/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

>From 16fd09f102eff20825847e32f225715960d1c082 Mon Sep 17 00:00:00 2001
From: Tulio Magno Quites Machado Filho 
Date: Wed, 25 Oct 2023 10:48:53 -0300
Subject: [PATCH] [lldb] Replace the usage of module imp with module importlib

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
---
 lldb/scripts/use_lldb_suite.py  | 30 ++
 lldb/test/API/use_lldb_suite.py | 29 +
 2 files changed, 43 insertions(+), 16 deletions(-)

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()

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits