##// END OF EJS Templates
demandimport: delete demandimportpy2 module...
Gregory Szorc -
r49802:425585f0 default
parent child Browse files
Show More
@@ -1,83 +1,80 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
14
15 import os
15 import os
16 import sys
16 import sys
17
17
18 if sys.version_info[0] >= 3:
19 from . import demandimportpy3 as demandimport
18 from . import demandimportpy3 as demandimport
20 else:
21 from . import demandimportpy2 as demandimport
22
19
23 # Full module names which can't be lazy imported.
20 # Full module names which can't be lazy imported.
24 # Extensions can add to this set.
21 # Extensions can add to this set.
25 IGNORES = {
22 IGNORES = {
26 '__future__',
23 '__future__',
27 '_hashlib',
24 '_hashlib',
28 # ImportError during pkg_resources/__init__.py:fixup_namespace_package
25 # ImportError during pkg_resources/__init__.py:fixup_namespace_package
29 '_imp',
26 '_imp',
30 '_xmlplus',
27 '_xmlplus',
31 'fcntl',
28 'fcntl',
32 'nt', # pathlib2 tests the existence of built-in 'nt' module
29 'nt', # pathlib2 tests the existence of built-in 'nt' module
33 'win32com.gen_py',
30 'win32com.gen_py',
34 'win32com.shell', # 'appdirs' tries to import win32com.shell
31 'win32com.shell', # 'appdirs' tries to import win32com.shell
35 '_winreg', # 2.7 mimetypes needs immediate ImportError
32 '_winreg', # 2.7 mimetypes needs immediate ImportError
36 'pythoncom',
33 'pythoncom',
37 # imported by tarfile, not available under Windows
34 # imported by tarfile, not available under Windows
38 'pwd',
35 'pwd',
39 'grp',
36 'grp',
40 # imported by profile, itself imported by hotshot.stats,
37 # imported by profile, itself imported by hotshot.stats,
41 # not available under Windows
38 # not available under Windows
42 'resource',
39 'resource',
43 # this trips up many extension authors
40 # this trips up many extension authors
44 'gtk',
41 'gtk',
45 # setuptools' pkg_resources.py expects "from __main__ import x" to
42 # setuptools' pkg_resources.py expects "from __main__ import x" to
46 # raise ImportError if x not defined
43 # raise ImportError if x not defined
47 '__main__',
44 '__main__',
48 '_ast', # https://bugs.python.org/issue41631
45 '_ast', # https://bugs.python.org/issue41631
49 '_ssl', # conditional imports in the stdlib, issue1964
46 '_ssl', # conditional imports in the stdlib, issue1964
50 '_sre', # issue4920
47 '_sre', # issue4920
51 'rfc822',
48 'rfc822',
52 'mimetools',
49 'mimetools',
53 'sqlalchemy.events', # has import-time side effects (issue5085)
50 'sqlalchemy.events', # has import-time side effects (issue5085)
54 'sqlalchemy.dialects', # similar problems as above
51 'sqlalchemy.dialects', # similar problems as above
55 # setuptools 8 expects this module to explode early when not on windows
52 # setuptools 8 expects this module to explode early when not on windows
56 'distutils.msvc9compiler',
53 'distutils.msvc9compiler',
57 '__builtin__',
54 '__builtin__',
58 'builtins',
55 'builtins',
59 'urwid.command_map', # for pudb
56 'urwid.command_map', # for pudb
60 'lzma',
57 'lzma',
61 }
58 }
62
59
63 _pypy = '__pypy__' in sys.builtin_module_names
60 _pypy = '__pypy__' in sys.builtin_module_names
64
61
65 if _pypy:
62 if _pypy:
66 # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5)
63 # _ctypes.pointer is shadowed by "from ... import pointer" (PyPy 5)
67 IGNORES.add('_ctypes.pointer')
64 IGNORES.add('_ctypes.pointer')
68
65
69 demandimport.init(IGNORES)
66 demandimport.init(IGNORES)
70
67
71 # Re-export.
68 # Re-export.
72 isenabled = demandimport.isenabled
69 isenabled = demandimport.isenabled
73 disable = demandimport.disable
70 disable = demandimport.disable
74 deactivated = demandimport.deactivated
71 deactivated = demandimport.deactivated
75
72
76
73
77 def enable():
74 def enable():
78 # chg pre-imports modules so do not enable demandimport for it
75 # chg pre-imports modules so do not enable demandimport for it
79 if (
76 if (
80 'CHGINTERNALMARK' not in os.environ
77 'CHGINTERNALMARK' not in os.environ
81 and os.environ.get('HGDEMANDIMPORT') != 'disable'
78 and os.environ.get('HGDEMANDIMPORT') != 'disable'
82 ):
79 ):
83 demandimport.enable()
80 demandimport.enable()
@@ -1,25 +1,24 b''
1 #require test-repo pure
1 #require test-repo pure
2
2
3 $ . "$TESTDIR/helpers-testrepo.sh"
3 $ . "$TESTDIR/helpers-testrepo.sh"
4 $ cd "$TESTDIR"/..
4 $ cd "$TESTDIR"/..
5
5
6 $ testrepohg files 'set:(**.py) - grep(pygments)' \
6 $ testrepohg files 'set:(**.py) - grep(pygments)' \
7 > -X hgdemandimport/demandimportpy2.py \
8 > -X hgext/fsmonitor/pywatchman \
7 > -X hgext/fsmonitor/pywatchman \
9 > -X mercurial/cffi \
8 > -X mercurial/cffi \
10 > -X mercurial/thirdparty \
9 > -X mercurial/thirdparty \
11 > | sed 's|\\|/|g' | xargs "$PYTHON" contrib/check-py3-compat.py \
10 > | sed 's|\\|/|g' | xargs "$PYTHON" contrib/check-py3-compat.py \
12 > | sed 's/[0-9][0-9]*)$/*)/'
11 > | sed 's/[0-9][0-9]*)$/*)/'
13 hgext/convert/transport.py: error importing: <*Error> No module named 'svn.client' (error at transport.py:*) (glob) (?)
12 hgext/convert/transport.py: error importing: <*Error> No module named 'svn.client' (error at transport.py:*) (glob) (?)
14 hgext/infinitepush/sqlindexapi.py: error importing: <*Error> No module named 'mysql' (error at sqlindexapi.py:*) (glob) (?)
13 hgext/infinitepush/sqlindexapi.py: error importing: <*Error> No module named 'mysql' (error at sqlindexapi.py:*) (glob) (?)
15 mercurial/scmwindows.py: error importing: <ValueError> _type_ 'v' not supported (error at win32.py:*) (no-windows !)
14 mercurial/scmwindows.py: error importing: <ValueError> _type_ 'v' not supported (error at win32.py:*) (no-windows !)
16 mercurial/win32.py: error importing: <ValueError> _type_ 'v' not supported (error at win32.py:*) (no-windows !)
15 mercurial/win32.py: error importing: <ValueError> _type_ 'v' not supported (error at win32.py:*) (no-windows !)
17 mercurial/windows.py: error importing: <*Error> No module named 'msvcrt' (error at windows.py:*) (glob) (no-windows !)
16 mercurial/windows.py: error importing: <*Error> No module named 'msvcrt' (error at windows.py:*) (glob) (no-windows !)
18 mercurial/posix.py: error importing: <*Error> No module named 'fcntl' (error at posix.py:*) (glob) (windows !)
17 mercurial/posix.py: error importing: <*Error> No module named 'fcntl' (error at posix.py:*) (glob) (windows !)
19 mercurial/scmposix.py: error importing: <*Error> No module named 'fcntl' (error at scmposix.py:*) (glob) (windows !)
18 mercurial/scmposix.py: error importing: <*Error> No module named 'fcntl' (error at scmposix.py:*) (glob) (windows !)
20
19
21 #if pygments
20 #if pygments
22 $ testrepohg files 'set:(**.py) and grep(pygments)' | sed 's|\\|/|g' \
21 $ testrepohg files 'set:(**.py) and grep(pygments)' | sed 's|\\|/|g' \
23 > | xargs "$PYTHON" contrib/check-py3-compat.py \
22 > | xargs "$PYTHON" contrib/check-py3-compat.py \
24 > | sed 's/[0-9][0-9]*)$/*)/'
23 > | sed 's/[0-9][0-9]*)$/*)/'
25 #endif
24 #endif
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now