Show More
@@ -1,83 +1,84 b'' | |||||
1 | # hgdemandimport - global demand-loading of modules for Mercurial |
|
1 | # hgdemandimport - global demand-loading of modules for Mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2017 Facebook Inc. |
|
3 | # Copyright 2017 Facebook Inc. | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | '''demandimport - automatic demand-loading of modules''' |
|
8 | '''demandimport - automatic demand-loading of modules''' | |
9 |
|
9 | |||
10 | # This is in a separate package from mercurial because in Python 3, |
|
10 | # This is in a separate package from mercurial because in Python 3, | |
11 | # demand loading is per-package. Keeping demandimport in the mercurial package |
|
11 | # demand loading is per-package. Keeping demandimport in the mercurial package | |
12 | # would disable demand loading for any modules in mercurial. |
|
12 | # would disable demand loading for any modules in mercurial. | |
13 |
|
13 | |||
14 | from __future__ import absolute_import |
|
14 | from __future__ import absolute_import | |
15 |
|
15 | |||
16 | import os |
|
16 | import os | |
17 | import sys |
|
17 | import sys | |
18 |
|
18 | |||
19 | if sys.version_info[0] >= 3: |
|
19 | if sys.version_info[0] >= 3: | |
20 | from . import demandimportpy3 as demandimport |
|
20 | from . import demandimportpy3 as demandimport | |
21 | else: |
|
21 | else: | |
22 | from . import demandimportpy2 as demandimport |
|
22 | from . import demandimportpy2 as demandimport | |
23 |
|
23 | |||
24 | # Full module names which can't be lazy imported. |
|
24 | # Full module names which can't be lazy imported. | |
25 | # Extensions can add to this set. |
|
25 | # Extensions can add to this set. | |
26 | IGNORES = { |
|
26 | IGNORES = { | |
27 | '__future__', |
|
27 | '__future__', | |
28 | '_hashlib', |
|
28 | '_hashlib', | |
29 | # ImportError during pkg_resources/__init__.py:fixup_namespace_package |
|
29 | # ImportError during pkg_resources/__init__.py:fixup_namespace_package | |
30 | '_imp', |
|
30 | '_imp', | |
31 | '_xmlplus', |
|
31 | '_xmlplus', | |
32 | 'fcntl', |
|
32 | 'fcntl', | |
33 | 'nt', # pathlib2 tests the existence of built-in 'nt' module |
|
33 | 'nt', # pathlib2 tests the existence of built-in 'nt' module | |
34 | 'win32com.gen_py', |
|
34 | 'win32com.gen_py', | |
35 | 'win32com.shell', # 'appdirs' tries to import win32com.shell |
|
35 | 'win32com.shell', # 'appdirs' tries to import win32com.shell | |
36 | '_winreg', # 2.7 mimetypes needs immediate ImportError |
|
36 | '_winreg', # 2.7 mimetypes needs immediate ImportError | |
37 | 'pythoncom', |
|
37 | 'pythoncom', | |
38 | # imported by tarfile, not available under Windows |
|
38 | # imported by tarfile, not available under Windows | |
39 | 'pwd', |
|
39 | 'pwd', | |
40 | 'grp', |
|
40 | 'grp', | |
41 | # imported by profile, itself imported by hotshot.stats, |
|
41 | # imported by profile, itself imported by hotshot.stats, | |
42 | # not available under Windows |
|
42 | # not available under Windows | |
43 | 'resource', |
|
43 | 'resource', | |
44 | # this trips up many extension authors |
|
44 | # this trips up many extension authors | |
45 | 'gtk', |
|
45 | 'gtk', | |
46 | # setuptools' pkg_resources.py expects "from __main__ import x" to |
|
46 | # setuptools' pkg_resources.py expects "from __main__ import x" to | |
47 | # raise ImportError if x not defined |
|
47 | # raise ImportError if x not defined | |
48 | '__main__', |
|
48 | '__main__', | |
49 | '_ast', # https://bugs.python.org/issue41631 |
|
49 | '_ast', # https://bugs.python.org/issue41631 | |
50 | '_ssl', # conditional imports in the stdlib, issue1964 |
|
50 | '_ssl', # conditional imports in the stdlib, issue1964 | |
51 | '_sre', # issue4920 |
|
51 | '_sre', # issue4920 | |
52 | 'rfc822', |
|
52 | 'rfc822', | |
53 | 'mimetools', |
|
53 | 'mimetools', | |
54 | 'sqlalchemy.events', # has import-time side effects (issue5085) |
|
54 | 'sqlalchemy.events', # has import-time side effects (issue5085) | |
|
55 | 'sqlalchemy.dialects', # similar problems as above | |||
55 | # setuptools 8 expects this module to explode early when not on windows |
|
56 | # setuptools 8 expects this module to explode early when not on windows | |
56 | 'distutils.msvc9compiler', |
|
57 | 'distutils.msvc9compiler', | |
57 | '__builtin__', |
|
58 | '__builtin__', | |
58 | 'builtins', |
|
59 | 'builtins', | |
59 | 'urwid.command_map', # for pudb |
|
60 | 'urwid.command_map', # for pudb | |
60 | 'lzma', |
|
61 | 'lzma', | |
61 | } |
|
62 | } | |
62 |
|
63 | |||
63 | _pypy = '__pypy__' in sys.builtin_module_names |
|
64 | _pypy = '__pypy__' in sys.builtin_module_names | |
64 |
|
65 | |||
65 | if _pypy: |
|
66 | if _pypy: | |
66 | # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5) |
|
67 | # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5) | |
67 | IGNORES.add('_ctypes.pointer') |
|
68 | IGNORES.add('_ctypes.pointer') | |
68 |
|
69 | |||
69 | demandimport.init(IGNORES) |
|
70 | demandimport.init(IGNORES) | |
70 |
|
71 | |||
71 | # Re-export. |
|
72 | # Re-export. | |
72 | isenabled = demandimport.isenabled |
|
73 | isenabled = demandimport.isenabled | |
73 | disable = demandimport.disable |
|
74 | disable = demandimport.disable | |
74 | deactivated = demandimport.deactivated |
|
75 | deactivated = demandimport.deactivated | |
75 |
|
76 | |||
76 |
|
77 | |||
77 | def enable(): |
|
78 | def enable(): | |
78 | # chg pre-imports modules so do not enable demandimport for it |
|
79 | # chg pre-imports modules so do not enable demandimport for it | |
79 | if ( |
|
80 | if ( | |
80 | 'CHGINTERNALMARK' not in os.environ |
|
81 | 'CHGINTERNALMARK' not in os.environ | |
81 | and os.environ.get('HGDEMANDIMPORT') != 'disable' |
|
82 | and os.environ.get('HGDEMANDIMPORT') != 'disable' | |
82 | ): |
|
83 | ): | |
83 | demandimport.enable() |
|
84 | demandimport.enable() |
General Comments 0
You need to be logged in to leave comments.
Login now