hgdemandimport/demandimportpy3.py
changeset 42474 adb636392b3f
parent 37843 670eb4fa1b86
child 43076 2372284d9457
equal deleted inserted replaced
42473:307f67d4aee3 42474:adb636392b3f
    30 import importlib.abc
    30 import importlib.abc
    31 import importlib.machinery
    31 import importlib.machinery
    32 import importlib.util
    32 import importlib.util
    33 import sys
    33 import sys
    34 
    34 
       
    35 from . import tracing
       
    36 
    35 _deactivated = False
    37 _deactivated = False
    36 
    38 
    37 class _lazyloaderex(importlib.util.LazyLoader):
    39 class _lazyloaderex(importlib.util.LazyLoader):
    38     """This is a LazyLoader except it also follows the _deactivated global and
    40     """This is a LazyLoader except it also follows the _deactivated global and
    39     the ignore list.
    41     the ignore list.
    40     """
    42     """
    41     def exec_module(self, module):
    43     def exec_module(self, module):
    42         """Make the module load lazily."""
    44         """Make the module load lazily."""
    43         if _deactivated or module.__name__ in ignores:
    45         with tracing.log('demandimport %s', module):
    44             self.loader.exec_module(module)
    46             if _deactivated or module.__name__ in ignores:
    45         else:
    47                 self.loader.exec_module(module)
    46             super().exec_module(module)
    48             else:
       
    49                 super().exec_module(module)
    47 
    50 
    48 # This is 3.6+ because with Python 3.5 it isn't possible to lazily load
    51 # This is 3.6+ because with Python 3.5 it isn't possible to lazily load
    49 # extensions. See the discussion in https://bugs.python.org/issue26186 for more.
    52 # extensions. See the discussion in https://bugs.python.org/issue26186 for more.
    50 _extensions_loader = _lazyloaderex.factory(
    53 _extensions_loader = _lazyloaderex.factory(
    51     importlib.machinery.ExtensionFileLoader)
    54     importlib.machinery.ExtensionFileLoader)