changeset 1345:6bae1852cff4

make version detection work around a strange behavior of imp.find_module
author Frederic Bastien <nouiz@nouiz.org>
date Wed, 27 Oct 2010 10:36:55 -0400
parents 2b8b991ac5fa
children 5e893cd6daae
files pylearn/version.py
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pylearn/version.py	Wed Oct 27 10:33:16 2010 -0400
+++ b/pylearn/version.py	Wed Oct 27 10:36:55 2010 -0400
@@ -215,11 +215,17 @@
 
 def _import_id(tag):
     try :
-        location = _imp.find_module(tag)
         mod = __import__(tag)
     except ImportError, e: #raise when tag is not found
         return e #put this in the cache, import_id will raise it
-
+    
+    try:
+        location = _imp.find_module(tag)
+    except ImportError, e: #raise when tag is not found
+        #sometimes fin_module raise an ImportError even when we can import it
+        if hasattr(mod,'__version__'):
+            return mod.__version__
+        return e
     #the find_module was successful, location is valid
     resource_type = location[2][2]