summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2018-11-15 15:04:02 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-11-16 11:46:07 +0000
commitdbe49d0ad197975e80c937e5e8da038d5c19e4c1 (patch)
tree4e4d8cccd82990f32c6fefa7f1a0672ec4653da8
parentf48d111e42398222e6ee8013a37ee35faf43ce09 (diff)
downloadpoky-dbe49d0ad197975e80c937e5e8da038d5c19e4c1.tar.gz
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. (From OE-Core rev: 24809582d4850190d87cd8eb8180d0dce215dbdf) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--scripts/lib/scriptutils.py11
-rwxr-xr-xscripts/pythondeps8
2 files changed, 8 insertions, 11 deletions
diff --git a/scripts/lib/scriptutils.py b/scripts/lib/scriptutils.py
index 31e48ea4dc..3c60c3a1e6 100644
--- a/scripts/lib/scriptutils.py
+++ b/scripts/lib/scriptutils.py
@@ -26,6 +26,8 @@ import string
26import subprocess 26import subprocess
27import sys 27import sys
28import tempfile 28import tempfile
29import importlib
30from importlib import machinery
29 31
30def logger_create(name, stream=None): 32def logger_create(name, stream=None):
31 logger = logging.getLogger(name) 33 logger = logging.getLogger(name)
@@ -50,12 +52,9 @@ def load_plugins(logger, plugins, pluginpath):
50 52
51 def load_plugin(name): 53 def load_plugin(name):
52 logger.debug('Loading plugin %s' % name) 54 logger.debug('Loading plugin %s' % name)
53 fp, pathname, description = imp.find_module(name, [pluginpath]) 55 spec = importlib.machinery.PathFinder.find_spec(name, path=[pluginpath] )
54 try: 56 if spec:
55 return imp.load_module(name, fp, pathname, description) 57 return spec.loader.load_module()
56 finally:
57 if fp:
58 fp.close()
59 58
60 def plugin_name(filename): 59 def plugin_name(filename):
61 return os.path.splitext(os.path.basename(filename))[0] 60 return os.path.splitext(os.path.basename(filename))[0]
diff --git a/scripts/pythondeps b/scripts/pythondeps
index 590b9769e7..3e13a587ee 100755
--- a/scripts/pythondeps
+++ b/scripts/pythondeps
@@ -9,7 +9,8 @@
9 9
10import argparse 10import argparse
11import ast 11import ast
12import imp 12import importlib
13from importlib import machinery
13import logging 14import logging
14import os.path 15import os.path
15import sys 16import sys
@@ -17,10 +18,7 @@ import sys
17 18
18logger = logging.getLogger('pythondeps') 19logger = logging.getLogger('pythondeps')
19 20
20suffixes = [] 21suffixes = importlib.machinery.all_suffixes()
21for triple in imp.get_suffixes():
22 suffixes.append(triple[0])
23
24 22
25class PythonDepError(Exception): 23class PythonDepError(Exception):
26 pass 24 pass