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.
--- 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 '?'>