demandimport: move HGDEMANDIMPORT test to __init__.py
authorJun Wu <quark@fb.com>
Fri, 18 Aug 2017 11:08:17 -0700
changeset 33859 8fb5212652ec
parent 33858 6f6c87888b22
child 33860 3cfc9070245f
demandimport: move HGDEMANDIMPORT test to __init__.py The logic is now shared between demandimport{2,3}. Differential Revision: https://phab.mercurial-scm.org/D445
hgdemandimport/__init__.py
hgdemandimport/demandimportpy2.py
hgdemandimport/demandimportpy3.py
--- a/hgdemandimport/__init__.py	Tue Aug 15 10:15:31 2017 -0700
+++ b/hgdemandimport/__init__.py	Fri Aug 18 11:08:17 2017 -0700
@@ -13,6 +13,7 @@
 
 from __future__ import absolute_import
 
+import os
 import sys
 
 if sys.version_info[0] >= 3:
@@ -68,6 +69,9 @@
 
 # Re-export.
 isenabled = demandimport.isenabled
-enable = demandimport.enable
 disable = demandimport.disable
 deactivated = demandimport.deactivated
+
+def enable():
+    if os.environ.get('HGDEMANDIMPORT') != 'disable':
+        demandimport.enable()
--- a/hgdemandimport/demandimportpy2.py	Tue Aug 15 10:15:31 2017 -0700
+++ b/hgdemandimport/demandimportpy2.py	Fri Aug 18 11:08:17 2017 -0700
@@ -28,7 +28,6 @@
 
 import __builtin__ as builtins
 import contextlib
-import os
 import sys
 
 contextmanager = contextlib.contextmanager
@@ -285,8 +284,7 @@
 
 def enable():
     "enable global demand-loading of modules"
-    if os.environ.get('HGDEMANDIMPORT') != 'disable':
-        builtins.__import__ = _demandimport
+    builtins.__import__ = _demandimport
 
 def disable():
     "disable global demand-loading of modules"
--- a/hgdemandimport/demandimportpy3.py	Tue Aug 15 10:15:31 2017 -0700
+++ b/hgdemandimport/demandimportpy3.py	Fri Aug 18 11:08:17 2017 -0700
@@ -27,7 +27,6 @@
 from __future__ import absolute_import
 
 import contextlib
-import os
 import sys
 
 import importlib.abc
@@ -81,8 +80,7 @@
         pass
 
 def enable():
-    if os.environ.get('HGDEMANDIMPORT') != 'disable':
-        sys.path_hooks.insert(0, _makefinder)
+    sys.path_hooks.insert(0, _makefinder)
 
 @contextlib.contextmanager
 def deactivated():