Add ability to bypass troublesome imports to hooke.util.pluggable.submods.
authorW. Trevor King <wking@drexel.edu>
Fri, 30 Jul 2010 13:37:35 +0000 (09:37 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 30 Jul 2010 13:37:35 +0000 (09:37 -0400)
This allows you to, for example, run the command line UI without
having the GUI's required wxwindows installed.

hooke/hooke.py
hooke/util/pluggable.py

index ccea160687edaa714e5bbbd15204224682104a12..d1c3b9c7a9fd4d4a93e3294ae3bda41f705b2bfd 100644 (file)
@@ -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.
index f13b9a5bd26cc588ee78b31d22d1d0d306ae1f03..ad2d85b89ed37f26a3a8629ee38e4c603f5bdab3 100644 (file)
 # License along with Hooke.  If not, see
 # <http://www.gnu.org/licenses/>.
 
-"""`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)