Show More
@@ -21,8 +21,9 b' if sys.version_info[0] >= 3:' | |||||
21 | else: |
|
21 | else: | |
22 | from . import demandimportpy2 as demandimport |
|
22 | from . import demandimportpy2 as demandimport | |
23 |
|
23 | |||
24 | # Extensions can add to this list if necessary. |
|
24 | # Full module names which can't be lazy imported. | |
25 | ignore = [ |
|
25 | # Extensions can add to this set. | |
|
26 | IGNORES = { | |||
26 | '__future__', |
|
27 | '__future__', | |
27 | '_hashlib', |
|
28 | '_hashlib', | |
28 | # ImportError during pkg_resources/__init__.py:fixup_namespace_package |
|
29 | # ImportError during pkg_resources/__init__.py:fixup_namespace_package | |
@@ -55,17 +56,15 b' ignore = [' | |||||
55 | '__builtin__', |
|
56 | '__builtin__', | |
56 | 'builtins', |
|
57 | 'builtins', | |
57 | 'urwid.command_map', # for pudb |
|
58 | 'urwid.command_map', # for pudb | |
58 | ] |
|
59 | } | |
59 |
|
60 | |||
60 | _pypy = '__pypy__' in sys.builtin_module_names |
|
61 | _pypy = '__pypy__' in sys.builtin_module_names | |
61 |
|
62 | |||
62 | if _pypy: |
|
63 | if _pypy: | |
63 | ignore.extend([ |
|
64 | # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5) | |
64 | # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5) |
|
65 | IGNORES.add('_ctypes.pointer') | |
65 | '_ctypes.pointer', |
|
|||
66 | ]) |
|
|||
67 |
|
66 | |||
68 |
demandimport.init( |
|
67 | demandimport.init(IGNORES) | |
69 |
|
68 | |||
70 | # Re-export. |
|
69 | # Re-export. | |
71 | isenabled = demandimport.isenabled |
|
70 | isenabled = demandimport.isenabled |
@@ -162,7 +162,7 b' class _demandmod(object):' | |||||
162 | _pypy = '__pypy__' in sys.builtin_module_names |
|
162 | _pypy = '__pypy__' in sys.builtin_module_names | |
163 |
|
163 | |||
164 | def _demandimport(name, globals=None, locals=None, fromlist=None, level=-1): |
|
164 | def _demandimport(name, globals=None, locals=None, fromlist=None, level=-1): | |
165 | if locals is None or name in ignore or fromlist == ('*',): |
|
165 | if locals is None or name in ignores or fromlist == ('*',): | |
166 | # these cases we can't really delay |
|
166 | # these cases we can't really delay | |
167 | return _hgextimport(_origimport, name, globals, locals, fromlist, level) |
|
167 | return _hgextimport(_origimport, name, globals, locals, fromlist, level) | |
168 | elif not fromlist: |
|
168 | elif not fromlist: | |
@@ -209,7 +209,7 b' def _demandimport(name, globals=None, lo' | |||||
209 | # while processing the import statement. |
|
209 | # while processing the import statement. | |
210 | return |
|
210 | return | |
211 | mn = '%s.%s' % (mod.__name__, attr) |
|
211 | mn = '%s.%s' % (mod.__name__, attr) | |
212 | if mn in ignore: |
|
212 | if mn in ignores: | |
213 | importfunc = _origimport |
|
213 | importfunc = _origimport | |
214 | else: |
|
214 | else: | |
215 | importfunc = _demandmod |
|
215 | importfunc = _demandmod | |
@@ -273,11 +273,11 b' def _demandimport(name, globals=None, lo' | |||||
273 |
|
273 | |||
274 | return mod |
|
274 | return mod | |
275 |
|
275 | |||
276 |
ignore = |
|
276 | ignores = set() | |
277 |
|
277 | |||
278 |
def init(ignore |
|
278 | def init(ignoreset): | |
279 | global ignore |
|
279 | global ignores | |
280 |
ignore = ignore |
|
280 | ignores = ignoreset | |
281 |
|
281 | |||
282 | def isenabled(): |
|
282 | def isenabled(): | |
283 | return builtins.__import__ == _demandimport |
|
283 | return builtins.__import__ == _demandimport |
@@ -40,7 +40,7 b' class _lazyloaderex(importlib.util.LazyL' | |||||
40 | """ |
|
40 | """ | |
41 | def exec_module(self, module): |
|
41 | def exec_module(self, module): | |
42 | """Make the module load lazily.""" |
|
42 | """Make the module load lazily.""" | |
43 | if _deactivated or module.__name__ in ignore: |
|
43 | if _deactivated or module.__name__ in ignores: | |
44 | self.loader.exec_module(module) |
|
44 | self.loader.exec_module(module) | |
45 | else: |
|
45 | else: | |
46 | super().exec_module(module) |
|
46 | super().exec_module(module) | |
@@ -62,11 +62,11 b' def _makefinder(path):' | |||||
62 | (_bytecode_loader, importlib.machinery.BYTECODE_SUFFIXES), |
|
62 | (_bytecode_loader, importlib.machinery.BYTECODE_SUFFIXES), | |
63 | ) |
|
63 | ) | |
64 |
|
64 | |||
65 |
ignore = |
|
65 | ignores = set() | |
66 |
|
66 | |||
67 |
def init(ignore |
|
67 | def init(ignoreset): | |
68 | global ignore |
|
68 | global ignores | |
69 |
ignore = ignore |
|
69 | ignores = ignoreset | |
70 |
|
70 | |||
71 | def isenabled(): |
|
71 | def isenabled(): | |
72 | return _makefinder in sys.path_hooks and not _deactivated |
|
72 | return _makefinder in sys.path_hooks and not _deactivated |
@@ -19,7 +19,7 b' from mercurial import (' | |||||
19 | from . import common |
|
19 | from . import common | |
20 |
|
20 | |||
21 | # these do not work with demandimport, blacklist |
|
21 | # these do not work with demandimport, blacklist | |
22 |
demandimport. |
|
22 | demandimport.IGNORES.update([ | |
23 | 'bzrlib.transactions', |
|
23 | 'bzrlib.transactions', | |
24 | 'bzrlib.urlutils', |
|
24 | 'bzrlib.urlutils', | |
25 | 'ElementPath', |
|
25 | 'ElementPath', |
@@ -11,7 +11,7 b'' | |||||
11 | from __future__ import absolute_import |
|
11 | from __future__ import absolute_import | |
12 |
|
12 | |||
13 | from mercurial import demandimport |
|
13 | from mercurial import demandimport | |
14 |
demandimport. |
|
14 | demandimport.IGNORES.update(['pkgutil', 'pkg_resources', '__main__']) | |
15 |
|
15 | |||
16 | from mercurial import ( |
|
16 | from mercurial import ( | |
17 | encoding, |
|
17 | encoding, |
General Comments 0
You need to be logged in to leave comments.
Login now