From 292c8b2b06c71ef4f08b3b99a3545365261ef2d2 Mon Sep 17 00:00:00 2001 From: Diego Roversi Date: Fri, 20 Sep 2019 11:26:13 +0200 Subject: fix dynamic import --- display/modes.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'display') diff --git a/display/modes.py b/display/modes.py index 0ac680e..c43638d 100644 --- a/display/modes.py +++ b/display/modes.py @@ -1,4 +1,7 @@ import sys +import importlib +import traceback +# import display.dpy_pygame KeyPressed = 2 KeyReleased = 3 @@ -32,20 +35,27 @@ class Mode: self.url = url def getmodule(self): - return __import__(self.prefix + self.name.lower(), globals(), - locals(), ['available']) +# import dpy_pygame + print( f"getmodule __import__ {self.prefix}{self.name.lower()}", file=sys.stderr ) + return importlib.import_module( "display." + self.prefix + self.name.lower() ) + #__import__(self.prefix + self.name.lower(), globals(), + # locals(), ['available']) def imperror(self): try: return self.__imperror except AttributeError: try: + print( f"getmodule = {self}" ) module = self.getmodule() - except ImportError: + except ImportError as e: result = 'not installed' + print("== ImportError traceback:", file=sys.stderr ) + traceback.print_exc(file=sys.stderr) else: result = hasattr(module, 'imperror') and module.imperror() self.__imperror = result + print( f"imperror result={result}" ) return result def unique_id(self): -- cgit v1.2.3