From 50a2c0e368c09c34e9b40fb432a29402dd400fbe Mon Sep 17 00:00:00 2001 From: Daniel Kutik Date: Fri, 25 Nov 2022 13:32:05 +0100 Subject: [PATCH] wrapper.py: Replacing load_module() with exec_module() Fixed "DeprecationWarning: the load_module() method is deprecated and slated for removal in Python 3.12; use exec_module() instead." in wrapper.py. Additionally removed Python 2 code (imp.load_source()). Test: tox Signed-off-by: Daniel Kutik Change-Id: Ib7cc19b1c545f6449e034c4b01b582cf6cf4b581 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/353237 Reviewed-by: Mike Frysinger --- wrapper.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/wrapper.py b/wrapper.py index b1aa4c50..65dcf3c6 100644 --- a/wrapper.py +++ b/wrapper.py @@ -12,12 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -try: - from importlib.machinery import SourceFileLoader - _loader = lambda *args: SourceFileLoader(*args).load_module() -except ImportError: - import imp - _loader = lambda *args: imp.load_source(*args) +import importlib.machinery +import importlib.util import os @@ -31,5 +27,9 @@ _wrapper_module = None def Wrapper(): global _wrapper_module if not _wrapper_module: - _wrapper_module = _loader('wrapper', WrapperPath()) + modname = 'wrapper' + loader = importlib.machinery.SourceFileLoader(modname, WrapperPath()) + spec = importlib.util.spec_from_loader(modname, loader) + _wrapper_module = importlib.util.module_from_spec(spec) + loader.exec_module(_wrapper_module) return _wrapper_module