changeset 21025:54af51c18c4c

demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable Convenient for debugging weird problems that are caused by demandimport or obfuscated by it. This is an undocumented developer feature.
author Mads Kiilerich <madski@unity3d.com>
date Tue, 08 Apr 2014 01:35:13 +0200
parents 7731a2281cf0
children 7ee03e190c1d
files mercurial/demandimport.py tests/test-demandimport.py tests/test-demandimport.py.out
diffstat 3 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/demandimport.py	Sun Apr 13 19:01:00 2014 +0200
+++ b/mercurial/demandimport.py	Tue Apr 08 01:35:13 2014 +0200
@@ -24,7 +24,7 @@
   b = __import__(a)
 '''
 
-import __builtin__
+import __builtin__, os
 _origimport = __import__
 
 nothing = object()
@@ -167,7 +167,8 @@
 
 def enable():
     "enable global demand-loading of modules"
-    __builtin__.__import__ = _demandimport
+    if os.environ.get('HGDEMANDIMPORT') != 'disable':
+        __builtin__.__import__ = _demandimport
 
 def disable():
     "disable global demand-loading of modules"
--- a/tests/test-demandimport.py	Sun Apr 13 19:01:00 2014 +0200
+++ b/tests/test-demandimport.py	Tue Apr 08 01:35:13 2014 +0200
@@ -37,3 +37,9 @@
 print "re =", f(re)
 print "re.stderr =", f(re.stderr)
 print "re =", f(re)
+
+demandimport.disable()
+os.environ['HGDEMANDIMPORT'] = 'disable'
+demandimport.enable()
+from mercurial import node
+print "node =", f(node)
--- a/tests/test-demandimport.py.out	Sun Apr 13 19:01:00 2014 +0200
+++ b/tests/test-demandimport.py.out	Tue Apr 08 01:35:13 2014 +0200
@@ -13,3 +13,4 @@
 re = <unloaded module 'sys'>
 re.stderr = <open file '<whatever>', mode 'w' at 0x?>
 re = <proxied module 'sys'>
+node = <module 'mercurial.node' from '?'>