utils: Avoid warnings about deprecated imp module
PATCH 1/2 utils: Avoid warnings about deprecated imp module
The imp module is deprecated, port the code over to use importlib.
bitbake/lib/bb/utils.py:30: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
Signed-off-by Richard Purdie <[email protected]>
--- lib/bb/utils.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
lib/bb/utils.py +5 -8
@@ -27,7 +27,7 @@ import bb import bb.msg import multiprocessing import fcntl -import imp +import importlib import itertools import subprocess import glob
@@ -43,7 +43,7 @@ from contextlib import contextmanager from ctypes import cdll logger = logging.getLogger("BitBake.Util") -python_extensions = [e for e, _, _ in imp.get_suffixes()] +python_extensions = importlib.machinery.all_suffixes() def clean_context():
@@ -1544,12 +1544,9 @@ def export_proxies(d): def load_plugins(logger, plugins, pluginpath): def load_plugin(name): logger.debug(1, '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() logger.debug(1, 'Loading plugins from %s...' % pluginpath)
Signature · 1 line
2.17.1
PATCH 2/2 utils: Avoid regex value escape warnings
Avoid warnings such as:bitbake/lib/bb/utils.py:72: DeprecationWarning: invalid escape sequence \d
numeric_regexp = re.compile('^(\d+)(.*)$')bitbake/lib/bb/utils.py:1165: DeprecationWarning: invalid escape sequence \(
var_res[var] = re.compile('^(%s%s)[ \\t]*\([ \\t]*\)[ \\t]*{' % (var[:-2].rstrip(), override_re))
Signed-off-by Richard Purdie <[email protected]>
--- lib/bb/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
lib/bb/utils.py +5 -5
@@ -68,8 +68,8 @@ class VersionStringException(Exception): def explode_version(s): r = [] - alpha_regexp = re.compile('^([a-zA-Z]+)(.*)$') - numeric_regexp = re.compile('^(\d+)(.*)$') + alpha_regexp = re.compile(r'^([a-zA-Z]+)(.*)$') + numeric_regexp = re.compile(r'^(\d+)(.*)$') while (s != ''): if s[0] in string.digits: m = numeric_regexp.match(s)
@@ -1157,14 +1157,14 @@ def edit_metadata(meta_lines, variables, varfunc, match_overrides=False): var_res = {} if match_overrides: - override_re = '(_[a-zA-Z0-9-_$(){}]+)?' + override_re = r'(_[a-zA-Z0-9-_$(){}]+)?' else: override_re = '' for var in variables: if var.endswith('()'): - var_res[var] = re.compile('^(%s%s)[ \\t]*\([ \\t]*\)[ \\t]*{' % (var[:-2].rstrip(), override_re)) + var_res[var] = re.compile(r'^(%s%s)[ \\t]*\([ \\t]*\)[ \\t]*{' % (var[:-2].rstrip(), override_re)) else: - var_res[var] = re.compile('^(%s%s)[ \\t]*[?+:.]*=[+.]*[ \\t]*(["\'])' % (var, override_re)) + var_res[var] = re.compile(r'^(%s%s)[ \\t]*[?+:.]*=[+.]*[ \\t]*(["\'])' % (var, override_re)) updated = False varset_start = ''
Signature · 1 line
2.17.1