From d864072b1b3076fc5c9478f629102e3168a3b928 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 30 Jul 2010 09:37:35 -0400 Subject: [PATCH] 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. --- hooke/hooke.py | 1 - hooke/util/pluggable.py | 13 +++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) 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) -- 2.26.2