Mercurial > public > mercurial-scm > hg-stable
diff hgdemandimport/demandimportpy3.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | adb636392b3f |
children | 2d31ef3fb494 |
line wrap: on
line diff
--- a/hgdemandimport/demandimportpy3.py Sat Oct 05 10:29:34 2019 -0400 +++ b/hgdemandimport/demandimportpy3.py Sun Oct 06 09:45:02 2019 -0400 @@ -36,10 +36,12 @@ _deactivated = False + class _lazyloaderex(importlib.util.LazyLoader): """This is a LazyLoader except it also follows the _deactivated global and the ignore list. """ + def exec_module(self, module): """Make the module load lazily.""" with tracing.log('demandimport %s', module): @@ -48,14 +50,18 @@ else: super().exec_module(module) + # This is 3.6+ because with Python 3.5 it isn't possible to lazily load # extensions. See the discussion in https://bugs.python.org/issue26186 for more. _extensions_loader = _lazyloaderex.factory( - importlib.machinery.ExtensionFileLoader) + importlib.machinery.ExtensionFileLoader +) _bytecode_loader = _lazyloaderex.factory( - importlib.machinery.SourcelessFileLoader) + importlib.machinery.SourcelessFileLoader +) _source_loader = _lazyloaderex.factory(importlib.machinery.SourceFileLoader) + def _makefinder(path): return importlib.machinery.FileFinder( path, @@ -65,15 +71,19 @@ (_bytecode_loader, importlib.machinery.BYTECODE_SUFFIXES), ) + ignores = set() + def init(ignoreset): global ignores ignores = ignoreset + def isenabled(): return _makefinder in sys.path_hooks and not _deactivated + def disable(): try: while True: @@ -81,9 +91,11 @@ except ValueError: pass + def enable(): sys.path_hooks.insert(0, _makefinder) + @contextlib.contextmanager def deactivated(): # This implementation is a bit different from Python 2's. Python 3