[oe-commits] [openembedded-core] 10/12: scripts: Remove deprecated imp module usage

git at git.openembedded.org git at git.openembedded.org
Thu Nov 15 19:02:39 UTC 2018


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch master-next
in repository openembedded-core.

commit c1108425c9dfa5fdac9da954d3c82faa6c175d09
Author: Richard Purdie <richard.purdie at linuxfoundation.org>
AuthorDate: Thu Nov 15 15:04:02 2018 +0000

    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 at linuxfoundation.org>
---
 scripts/lib/scriptutils.py | 11 +++++------
 scripts/pythondeps         |  8 +++-----
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/scripts/lib/scriptutils.py b/scripts/lib/scriptutils.py
index 31e48ea..3c60c3a 100644
--- a/scripts/lib/scriptutils.py
+++ b/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]
diff --git a/scripts/pythondeps b/scripts/pythondeps
index 590b976..3e13a58 100755
--- a/scripts/pythondeps
+++ b/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

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list