[prev in list] [next in list] [prev in thread] [next in thread]
List: openembedded-core
Subject: [OE-core][dunfell 15/29] oeqa/runtime: load modules using importlib
From: "Steve Sakoman" <steve () sakoman ! com>
Date: 2021-10-31 16:57:34
Message-ID: 015f0b03dc384851b3f250a1818a952d8c09079a.1635699172.git.steve () sakoman ! com
[Download RAW message or body]
Content-Transfer-Encoding: 8bit
From: Ross Burton <ross@burtonini.com>
Instead of using __import__() which is low-level and discouraged, use
importlib.
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 9f501d22eab5dbd565f3f5783f4f484a6d1f70a2)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
---
meta/lib/oeqa/runtime/context.py | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/meta/lib/oeqa/runtime/context.py b/meta/lib/oeqa/runtime/context.py
index 3826f27642..7908ce1fd4 100644
--- a/meta/lib/oeqa/runtime/context.py
+++ b/meta/lib/oeqa/runtime/context.py
@@ -175,16 +175,12 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
# Search for and return a controller or None from given module name
@staticmethod
def _loadControllerFromModule(target, modulename):
- obj = None
- # import module, allowing it to raise import exception
- module = __import__(modulename, globals(), locals(), [target])
- # look for target class in the module, catching any exceptions as it
- # is valid that a module may not have the target class.
try:
- obj = getattr(module, target)
- except:
- obj = None
- return obj
+ import importlib
+ module = importlib.import_module(modulename)
+ return getattr(module, target)
+ except AttributeError:
+ return None
@staticmethod
def readPackagesManifest(manifest):
--
2.25.1
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#157673): https://lists.openembedded.org/g/openembedded-core/message/157673
Mute This Topic: https://lists.openembedded.org/mt/86721269/4454766
Group Owner: openembedded-core+owner@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [openembedded-core@marc.info]
-=-=-=-=-=-=-=-=-=-=-=-
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic