From 06247bfb5c75cbd4d05aced911e8b2a5dac459fe Mon Sep 17 00:00:00 2001 From: Loris Zinsou Date: Fri, 1 Nov 2019 17:28:15 +0100 Subject: [PATCH 1/2] tools: fix Python 3 deprecation warning in test.py --- tools/test.py | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/tools/test.py b/tools/test.py index 04babded24b590..b0e75b3b6a128c 100755 --- a/tools/test.py +++ b/tools/test.py @@ -29,7 +29,6 @@ from __future__ import print_function -import imp import logging import optparse import os @@ -45,6 +44,30 @@ import errno import copy + +if sys.version_info >= (3, 5): + from importlib import machinery, util + def get_module(name, path): + loader_details = ( + machinery.SourceFileLoader, + machinery.SOURCE_SUFFIXES + ) + spec = machinery.FileFinder(path, loader_details).find_spec(name) + module = util.module_from_spec(spec) + spec.loader.exec_module(module) + return module +else: + import imp + def get_module(name, path): + file = None + try: + (file, pathname, description) = imp.find_module(name, [path]) + return imp.load_module(name, file, pathname, description) + finally: + if file: + file.close() + + from io import open from os.path import join, dirname, abspath, basename, isdir, exists from datetime import datetime @@ -791,18 +814,13 @@ def GetConfiguration(self, context): if self.is_loaded: return self.config self.is_loaded = True - file = None - try: - (file, pathname, description) = imp.find_module('testcfg', [ self.path ]) - module = imp.load_module('testcfg', file, pathname, description) - self.config = module.GetConfiguration(context, self.path) - if hasattr(self.config, 'additional_flags'): - self.config.additional_flags += context.node_args - else: - self.config.additional_flags = context.node_args - finally: - if file: - file.close() + + module = get_module('testcfg', self.path) + self.config = module.GetConfiguration(context, self.path) + if hasattr(self.config, 'additional_flags'): + self.config.additional_flags += context.node_args + else: + self.config.additional_flags = context.node_args return self.config def GetBuildRequirements(self, path, context): From fa6ac9b5824ad63a2922d48a80b31a7f5ee98a27 Mon Sep 17 00:00:00 2001 From: Loris Zinsou Date: Fri, 1 Nov 2019 21:48:58 +0100 Subject: [PATCH 2/2] tools: indent test.py with 2 spaces --- tools/test.py | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/tools/test.py b/tools/test.py index b0e75b3b6a128c..b928662decf36c 100755 --- a/tools/test.py +++ b/tools/test.py @@ -46,26 +46,23 @@ if sys.version_info >= (3, 5): - from importlib import machinery, util - def get_module(name, path): - loader_details = ( - machinery.SourceFileLoader, - machinery.SOURCE_SUFFIXES - ) - spec = machinery.FileFinder(path, loader_details).find_spec(name) - module = util.module_from_spec(spec) - spec.loader.exec_module(module) - return module + from importlib import machinery, util + def get_module(name, path): + loader_details = (machinery.SourceFileLoader, machinery.SOURCE_SUFFIXES) + spec = machinery.FileFinder(path, loader_details).find_spec(name) + module = util.module_from_spec(spec) + spec.loader.exec_module(module) + return module else: - import imp - def get_module(name, path): - file = None - try: - (file, pathname, description) = imp.find_module(name, [path]) - return imp.load_module(name, file, pathname, description) - finally: - if file: - file.close() + import imp + def get_module(name, path): + file = None + try: + (file, pathname, description) = imp.find_module(name, [path]) + return imp.load_module(name, file, pathname, description) + finally: + if file: + file.close() from io import open