Browse Source

scripts: Remove deprecated imp module usage

The imp module is deprecated, port the code over to use importlib
as recently done for bb.utils as well.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Richard Purdie 5 years ago
parent
commit
f3ba6cee59
2 changed files with 8 additions and 11 deletions
  1. 5 6
      scripts/lib/scriptutils.py
  2. 3 5
      scripts/pythondeps

+ 5 - 6
scripts/lib/scriptutils.py

@@ -26,6 +26,8 @@ import string
 import subprocess
 import sys
 import tempfile
+import importlib
+from importlib import machinery
 
 def logger_create(name, stream=None):
     logger = logging.getLogger(name)
@@ -50,12 +52,9 @@ def load_plugins(logger, plugins, pluginpath):
 
     def load_plugin(name):
         logger.debug('Loading plugin %s' % name)
-        fp, pathname, description = imp.find_module(name, [pluginpath])
-        try:
-            return imp.load_module(name, fp, pathname, description)
-        finally:
-            if fp:
-                fp.close()
+        spec = importlib.machinery.PathFinder.find_spec(name, path=[pluginpath] )
+        if spec:
+            return spec.loader.load_module()
 
     def plugin_name(filename):
         return os.path.splitext(os.path.basename(filename))[0]

+ 3 - 5
scripts/pythondeps

@@ -9,7 +9,8 @@
 
 import argparse
 import ast
-import imp
+import importlib
+from importlib import machinery
 import logging
 import os.path
 import sys
@@ -17,10 +18,7 @@ import sys
 
 logger = logging.getLogger('pythondeps')
 
-suffixes = []
-for triple in imp.get_suffixes():
-    suffixes.append(triple[0])
-
+suffixes = importlib.machinery.all_suffixes()
 
 class PythonDepError(Exception):
     pass