From: W. Trevor King Date: Fri, 30 Jul 2010 13:37:35 +0000 (-0400) Subject: Add ability to bypass troublesome imports to hooke.util.pluggable.submods. X-Git-Url: http://git.tremily.us/?p=hooke.git;a=commitdiff_plain;h=d864072b1b3076fc5c9478f629102e3168a3b928 Add ability to bypass troublesome imports to hooke.util.pluggable.submods. This allows you to, for example, run the command line UI without having the GUI's required wxwindows installed. --- diff --git a/hooke/hooke.py b/hooke/hooke.py index ccea160..d1c3b9c 100644 --- a/hooke/hooke.py +++ b/hooke/hooke.py @@ -94,7 +94,6 @@ class Hooke (object): def load_log(self): config_file = StringIO.StringIO() self.config.write(config_file) - x = config_file.getvalue() logging.config.fileConfig(StringIO.StringIO(config_file.getvalue())) # Don't attach the logger because it contains an unpicklable # thread.lock. Instead, grab it directly every time you need it. diff --git a/hooke/util/pluggable.py b/hooke/util/pluggable.py index f13b9a5..ad2d85b 100644 --- a/hooke/util/pluggable.py +++ b/hooke/util/pluggable.py @@ -16,9 +16,11 @@ # License along with Hooke. If not, see # . -"""`pluggable` +"""``pluggable`` provides utility functions for extensible plugin modules. """ +import logging + from ..compat.odict import odict from .graph import Node, Graph @@ -68,7 +70,14 @@ def submods(this_modname, submodnames): assert count > 0, 'No %s entries: %s' % (submodname, submodnames) assert count == 1, 'Multiple (%d) %s entries: %s' \ % (count, submodname, submodnames) - this_mod = __import__(this_modname, fromlist=[submodname]) + try: + this_mod = __import__(this_modname, fromlist=[submodname]) + except ImportError, e: + # Use the root logger because the 'hooke' logger is + # configured by a Hooke instance after module imports. + logging.warn('could not import %s from %s: %s' + % (submodname, this_modname, e)) + continue submod = getattr(this_mod, submodname) yield (submodname, submod)