Subject: [Instant] Fix for more verbose output when instant fails to import a module

From: Johan Hake <[email-masked]>
Date: Wed, 12 Jan 2011 13:58:24 -0800

For consideration?

Johan
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: [email-masked]
# target_branch: bzr+ssh://bazaar.launchpad.net/~instant-\
#   core/instant/main/
# testament_sha1: 9c350817d87fdfcb3f016f5e4f1fa09b178c1757
# timestamp: 2011-01-12 13:56:23 -0800
# base_revision_id: [email-masked]
# 
# Begin patch
=== modified file 'instant/cache.py'
--- instant/cache.py	2010-10-25 12:54:41 +0000
+++ instant/cache.py	2011-01-12 21:55:29 +0000
@@ -32,20 +32,21 @@
 def import_module_directly(path, modulename):
     "Import a module with the given module name that resides in the given path."
     sys.path.insert(0, path)
-
+    e = None
     try:
         module = __import__(modulename)
-    except:
-        instant_warning("In instant.import_module_directly: Failed to import module '%s' from '%s'." % (modulename, path))
+    except Exception, e:
+        instant_warning("In instant.import_module_directly: Failed to import module '%s' from '%s';\n%s:%s;" % (modulename, path, type(e).__name__, e))
         module = None
     finally:
         sys.path.pop(0)
-    return module
+    return module, e

 _memory_cache = {}
 def memory_cached_module(moduleid):
     "Returns the cached module if found."
+    import sys
     module = _memory_cache.get(moduleid, None)
     instant_debug("Found '%s' in memory cache with key '%r'." % (module, moduleid))
     return module
@@ -63,8 +64,8 @@

 def import_and_cache_module(path, modulename, moduleids):
-    module = import_module_directly(path, modulename)
-    instant_assert(module is not None, "Failed to import module found in cache. Modulename: '%s'; Path: '%s'." % (modulename, path))
+    module, e = import_module_directly(path, modulename)
+    instant_assert(module is not None, "Failed to import module found in cache. Modulename: '%s';\nPath: '%s';\n%s:%s;" % (modulename, path, type(e).__name__, e))
     for moduleid in moduleids:
         place_module_in_memory_cache(moduleid, module)
     return module

# Begin bundle