comparison hgdemandimport/demandimportpy3.py @ 44117:c5e0a9b97b8a

hgdemandimport: disable on Python 3.5 The demand importer functionality isn't working at all on Python 3.5. I'm not sure what's wrong. Since it isn't working, let's disable it completely. ``` $ HGRCPATH= hyperfine -w 1 -r 50 -- "~/.pyenv/versions/3.5.9/bin/python ./hg version" \ "HGDEMANDIMPORT=disable ~/.pyenv/versions/3.5.9/bin/python ./hg version" Benchmark #1: ~/.pyenv/versions/3.5.9/bin/python ./hg version Time (mean ± σ): 163.7 ms ± 2.2 ms [User: 148.5 ms, System: 15.7 ms] Range (min … max): 161.0 ms … 170.2 ms 50 runs Benchmark #2: HGDEMANDIMPORT=disable ~/.pyenv/versions/3.5.9/bin/python ./hg version Time (mean ± σ): 164.3 ms ± 1.4 ms [User: 148.2 ms, System: 16.6 ms] Range (min … max): 161.4 ms … 169.8 ms 50 runs ``` Differential Revision: https://phab.mercurial-scm.org/D7953
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 20 Jan 2020 23:42:19 -0800
parents 2d31ef3fb494
children f81c17ec303c
comparison
equal deleted inserted replaced
44116:b5aaa09be18c 44117:c5e0a9b97b8a
34 34
35 from . import tracing 35 from . import tracing
36 36
37 _deactivated = False 37 _deactivated = False
38 38
39 # Python 3.5's LazyLoader doesn't work for some reason.
40 # https://bugs.python.org/issue26186 is a known issue with extension
41 # importing. But it appears to not have a meaningful effect with
42 # Mercurial.
43 _supported = sys.version_info[0:2] >= (3, 6)
44
39 45
40 class _lazyloaderex(importlib.util.LazyLoader): 46 class _lazyloaderex(importlib.util.LazyLoader):
41 """This is a LazyLoader except it also follows the _deactivated global and 47 """This is a LazyLoader except it also follows the _deactivated global and
42 the ignore list. 48 the ignore list.
43 """ 49 """
49 self.loader.exec_module(module) 55 self.loader.exec_module(module)
50 else: 56 else:
51 super().exec_module(module) 57 super().exec_module(module)
52 58
53 59
54 # This is 3.6+ because with Python 3.5 it isn't possible to lazily load 60 _extensions_loader = _lazyloaderex.factory(
55 # extensions. See the discussion in https://bugs.python.org/issue26186 for more. 61 importlib.machinery.ExtensionFileLoader
56 if sys.version_info[0:2] >= (3, 6): 62 )
57 _extensions_loader = _lazyloaderex.factory(
58 importlib.machinery.ExtensionFileLoader
59 )
60 else:
61 _extensions_loader = importlib.machinery.ExtensionFileLoader
62
63 _bytecode_loader = _lazyloaderex.factory( 63 _bytecode_loader = _lazyloaderex.factory(
64 importlib.machinery.SourcelessFileLoader 64 importlib.machinery.SourcelessFileLoader
65 ) 65 )
66 _source_loader = _lazyloaderex.factory(importlib.machinery.SourceFileLoader) 66 _source_loader = _lazyloaderex.factory(importlib.machinery.SourceFileLoader)
67 67
95 except ValueError: 95 except ValueError:
96 pass 96 pass
97 97
98 98
99 def enable(): 99 def enable():
100 if not _supported:
101 return
102
100 sys.path_hooks.insert(0, _makefinder) 103 sys.path_hooks.insert(0, _makefinder)
101 104
102 105
103 @contextlib.contextmanager 106 @contextlib.contextmanager
104 def deactivated(): 107 def deactivated():