Patchwork [3,of,6,misc] demandimport: make it possible to disable by setting HGDEMANDIMPORT=disable

login
register
mail settings
Submitter Mads Kiilerich
Date April 13, 2014, 5:13 p.m.
Message ID <9d250940811ae2c5556b.1397409227@localhost.localdomain>
Download mbox | patch
Permalink /patch/4331/
State Accepted
Commit 0a49af9ec1c8cb6950f11af653b72a21e1344a34
Headers show

Comments

Mads Kiilerich - April 13, 2014, 5:13 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1396913713 -7200
#      Tue Apr 08 01:35:13 2014 +0200
# Node ID 9d250940811ae2c5556b00ac5e02ff1e06565d41
# Parent  0759c3fdc3e3847e95ef34729a7a133e1fd374f7
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.

Patch

diff --git a/mercurial/demandimport.py b/mercurial/demandimport.py
--- a/mercurial/demandimport.py
+++ b/mercurial/demandimport.py
@@ -24,7 +24,7 @@  These imports will not be delayed:
   b = __import__(a)
 '''
 
-import __builtin__
+import __builtin__, os
 _origimport = __import__
 
 nothing = object()
@@ -167,7 +167,8 @@  def isenabled():
 
 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"
diff --git a/tests/test-demandimport.py b/tests/test-demandimport.py
--- a/tests/test-demandimport.py
+++ b/tests/test-demandimport.py
@@ -37,3 +37,9 @@  print "fred =", f(fred)
 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)
diff --git a/tests/test-demandimport.py.out b/tests/test-demandimport.py.out
--- a/tests/test-demandimport.py.out
+++ b/tests/test-demandimport.py.out
@@ -13,3 +13,4 @@  fred = <proxied module 're'>
 re = <unloaded module 'sys'>
 re.stderr = <open file '<whatever>', mode 'w' at 0x?>
 re = <proxied module 'sys'>
+node = <module 'mercurial.node' from '?'>