D445: demandimport: move HGDEMANDIMPORT test to __init__.py
quark (Jun Wu)
phabricator at mercurial-scm.org
Fri Aug 18 18:12:01 UTC 2017
quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
The logic is now shared between demandimport{2,3}.
REPOSITORY
rHG Mercurial
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