o ]Lb@sdZddlmZddlZddlZddlZddlmZda ej dddkZ Gd d d ej j ZGd d d eZead dZddZddZddZejddZdS)aLazy loading for Python 3.6 and above. This uses the new importlib finder/loader functionality available in Python 3.5 and up. The code reuses most of the mechanics implemented inside importlib.util, but with a few additions: * Allow excluding certain modules from lazy imports. * Expose an interface that's substantially the same as demandimport for Python 2. This also has some limitations compared to the Python 2 implementation: * Much of the logic is per-package, not per-module, so any packages loaded before demandimport is enabled will not be lazily imported in the future. In practice, we only expect builtins to be loaded before demandimport is enabled. )absolute_importN)tracingF)cs eZdZdZfddZZS) _lazyloaderexzaThis is a LazyLoader except it also follows the _deactivated global and the ignore list. csjtd|%ts|jtvr|j|nt|WddSWddS1s.wYdS)zMake the module load lazily.zdemandimport %sN)rlog _deactivated__name__ignoresloader exec_modulesuper)selfmodule __class__@/usr/lib/python3/dist-packages/hgdemandimport/demandimportpy3.pyr1s"z_lazyloaderex.exec_module)r __module__ __qualname____doc__r __classcell__rrrrr,src@sReZdZdZdZddZddZddZeZd d Z d d Z d dZ dddZ dS) LazyFindera2A wrapper around a ``MetaPathFinder`` that makes loaders lazy. ``sys.meta_path`` finders have their ``find_spec()`` called to locate a module. This returns a ``ModuleSpec`` if found or ``None``. The ``ModuleSpec`` has a ``loader`` attribute, which is called to actually load a module. Our class wraps an existing finder and overloads its ``find_spec()`` to replace the ``loader`` with our lazy loader proxy. We have to use __getattribute__ to proxy the instance because some meta path finders don't support monkeypatching. )_findercCst|d|dSNr)object __setattr__)rfinderrrr__init__KszLazyFinder.__init__cCsdt|dS)Nzr)r__getattribute__rrrr__repr__NzLazyFinder.__repr__cCtt|dSr)boolrr!r"rrr __nonzero__Sr$zLazyFinder.__nonzero__cCs&|dvr t||Stt|d|S)N)r find_specr)rr!getattrrnamerrrr!Xs zLazyFinder.__getattribute__cCr%r)delattrrr!r*rrr __delattr__^r$zLazyFinder.__delattr__cCstt|d||Sr)setattrrr!)rr+valuerrrraszLazyFinder.__setattr__NcCst|d}z|j}Wnty(|||}|durd}ntj||}Ynw||||}|durE|jdurEt |jddrEt |j|_|S)Nrr) rr!r(AttributeError find_module importlibutilspec_from_loaderr r)r)rfullnamepathtargetrr(r specrrrr(ds"        zLazyFinder.find_specN) r rrr __slots__r r#r'__bool__r!r-rr(rrrrr:srcCs|adSr9)r ) ignoresetrrrinitsr=cCst o tddtjDS)Ncss|]}t|tVqdSr9) isinstancer).0rrrr s  zisenabled..)r anysys meta_pathrrrr isenabledsrDcCs<g}tjD]}|t|tr|jn|q|tjdd<dSr9)rBrCappendr>rr new_findersrrrrdisables  rHcCsFtsdSg}tjD]}|t|tst|n|q |tjdd<dSr9) _supportedrBrCrEr>rrFrrrenables rJccs4t}|rdaz dVW|rdadSdS|rdaw)NTF)rDr ) demandenabledrrr deactivatedsrL)r __future__r contextlibimportlib.utilr2rBrr version_inforIr3 LazyLoaderrrrsetr r=rDrHrJcontextmanagerrLrrrrs"  B