D445: demandimport: move HGDEMANDIMPORT test to __init__.py

quark (Jun Wu) phabricator at mercurial-scm.org
Sat Aug 19 02:57:04 EDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG8fb5212652ec: demandimport: move HGDEMANDIMPORT test to __init__.py (authored by quark).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D445?vs=1077&id=1086

REVISION DETAIL
  https://phab.mercurial-scm.org/D445

AFFECTED FILES
  hgdemandimport/__init__.py
  hgdemandimport/demandimportpy2.py
  hgdemandimport/demandimportpy3.py

CHANGE DETAILS

diff --git a/hgdemandimport/demandimportpy3.py b/hgdemandimport/demandimportpy3.py
--- a/hgdemandimport/demandimportpy3.py
+++ b/hgdemandimport/demandimportpy3.py
@@ -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():
diff --git a/hgdemandimport/demandimportpy2.py b/hgdemandimport/demandimportpy2.py
--- a/hgdemandimport/demandimportpy2.py
+++ b/hgdemandimport/demandimportpy2.py
@@ -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"
diff --git a/hgdemandimport/__init__.py b/hgdemandimport/__init__.py
--- a/hgdemandimport/__init__.py
+++ b/hgdemandimport/__init__.py
@@ -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()



To: quark, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list