demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable
authorMads Kiilerich <madski@unity3d.com>
Tue, 08 Apr 2014 01:35:13 +0200
changeset 21025 54af51c18c4c
parent 21024 7731a2281cf0
child 21026 7ee03e190c1d
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.
mercurial/demandimport.py
tests/test-demandimport.py
tests/test-demandimport.py.out
--- 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 '?'>