Issue 2330: For forward compatibility, use "import profile" and have
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 9 Apr 2010 16:57:36 +0000 (16:57 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 9 Apr 2010 16:57:36 +0000 (16:57 +0000)
the SCons.compat layer import cProfile as profile when it's available.

git-svn-id: http://scons.tigris.org/svn/scons/trunk@4777 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Script/Main.py
src/engine/SCons/compat/__init__.py

index 9b8c94b69cddcc625b83eea7266c7846bacb366d..7909b0bbcfdf6f0e1391e665da2aa91939d4a476 100644 (file)
@@ -37,6 +37,8 @@ from __future__ import generators  ### KEEP FOR COMPATIBILITY FIXERS
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
+import SCons.compat
+
 import os
 import os.path
 import sys
@@ -1226,10 +1228,8 @@ def _exec_main(parser, values):
         import pdb
         pdb.Pdb().runcall(_main, parser)
     elif options.profile_file:
-        try:
-            from cProfile import Profile
-        except ImportError, e:
-            from profile import Profile
+        # compat layer imports "cProfile" for us if it's available.
+        from profile import Profile
 
         # Some versions of Python 2.4 shipped a profiler that had the
         # wrong 'c_exception' entry in its dispatch table.  Make sure
index 7e93a71efa73355a7d493a5082a4876fabb1aef1..4553d21250c51729ec528371ac3cd105c2bdd16e 100644 (file)
@@ -193,6 +193,20 @@ except AttributeError:
     os.path.lexists = lexists
 
 
+try:
+    # Use the "imp" module to protect the import from fixers.
+    import imp
+    cProfile = imp.load_module('cProfile', *imp.find_module('cProfile'))
+except ImportError:
+    # The "cProfile" module has already been eliminated in favor of
+    # having "import profile" import the fast version when available.
+    pass
+else:
+    import sys
+    sys.modules['profile'] = cProfile
+    del cProfile
+
+
 try:
     import platform
 except ImportError: