changeset 2497:976b6b2a1613

do not try to package lsprof if not available.
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Fri, 23 Jun 2006 19:20:22 -0700
parents 6dbb8ae0a0b3
children 1e2ec4fd16df
files mercurial/lsprof.py mercurial/packagescan.py
diffstat 2 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/lsprof.py	Fri Jun 23 18:23:42 2006 -0700
+++ b/mercurial/lsprof.py	Fri Jun 23 19:20:22 2006 -0700
@@ -4,7 +4,13 @@
 # small modifications made
 
 import sys
-from _lsprof import Profiler, profiler_entry, profiler_subentry
+try:
+    from _lsprof import Profiler, profiler_entry, profiler_subentry
+except ImportError, inst:
+    import packagescan
+    if packagescan.scan_in_progress:
+        raise packagescan.SkipPackage('_lsprof not available')
+    raise
 
 __all__ = ['profile', 'Stats']
 
--- a/mercurial/packagescan.py	Fri Jun 23 18:23:42 2006 -0700
+++ b/mercurial/packagescan.py	Fri Jun 23 19:20:22 2006 -0700
@@ -60,8 +60,16 @@
                 if type(scope[f]) == types.ModuleType:
                     requiredmodules[scope[f].__name__] = 1
 
+class SkipPackage(Exception):
+    def __init__(self, reason):
+        self.reason = reason
+
+scan_in_progress = False
+
 def scan(libpath,packagename):
     """ helper for finding all required modules of package <packagename> """
+    global scan_in_progress
+    scan_in_progress = True
     # Use the package in the build directory
     libpath = os.path.abspath(libpath)
     sys.path.insert(0,libpath)
@@ -85,7 +93,11 @@
         tmp = {}
         mname,ext = os.path.splitext(m)
         fullname = packagename+'.'+mname
-        __import__(fullname,tmp,tmp)
+        try:
+            __import__(fullname,tmp,tmp)
+        except SkipPackage, inst:
+            print >> sys.stderr, 'skipping %s: %s' % (fullname, inst.reason)
+            continue
         requiredmodules[fullname] = 1
     # Import all extension modules and by that run the fake demandload
     for m in extmodulefiles: