K itddlZddlZddlZddlZddlZddlZddgZddZGddejZ dZ y) Nattach _lazy_importc |i} tn t|jDcic]\}}|D]}||c}}} t jz fd}fd}tj j ddr)t jzD] }|| ||tfScc}}}w)aAttach lazily loaded submodules, and functions or other attributes. Typically, modules import submodules and attributes as follows:: import mysubmodule import anothersubmodule from .foo import someattr The idea of this function is to replace the `__init__.py` module's `__getattr__`, `__dir__`, and `__all__` attributes such that all imports work exactly the way they normally would, except that the actual import is delayed until the resulting module object is first used. The typical way to call this function, replacing the above imports, is:: __getattr__, __lazy_dir__, __all__ = lazy.attach( __name__, ["mysubmodule", "anothersubmodule"], {"foo": "someattr"} ) This functionality requires Python 3.7 or higher. Parameters ---------- module_name : str Typically use __name__. submodules : set List of submodules to lazily import. submod_attrs : dict Dictionary of submodule -> list of attributes / functions. These attributes are imported as they are used. Returns ------- __getattr__, __dir__, __all__ c|vrtjd|S|vr)tjd|}t||Stdd|)N.zNo z attribute ) importlib import_modulegetattrAttributeError)namesubmodattr_to_modules module_name submoduless [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/networkx/lazy_imports.py __getattr__zattach..__getattr__?su : **k]!D6+BC C _ $,, }Aod>S=T-UVF64( ( 3{m;tf!EF FcSN)__all__sr__dir__zattach..__dir__Hsr EAGER_IMPORT)setitemslistkeysosenvironget) rr submod_attrsmodattrsattrrrrrs `` @@rrr sL U _ %1$6$6$8 c5U=Ac  O: 4 4 667GG zz~~nb),,./*< D    g ..-sC c(eZdZfdZfdZxZS)DelayedImportErrorModulec2||_t||i|yr)%_DelayedImportErrorModule__frame_datasuper__init__)self frame_dataargskwargs __class__s rr+z!DelayedImportErrorModule.__init__Ss& $)&)rc|dvrt||y|j}td|dd|dd|dd|d d d j |d xsd j ) N)r0__file__ __frame_datazNo module named 'speczG' This error is lazily reported, having originally occurred in File filenamez, line linenoz, in functionz ----> r code_context)r*rr)ModuleNotFoundErrorjoinstrip)r,xfdr0s rrz$DelayedImportErrorModule.__getattr__Ws 9 9 G  """B%#BvJ<0Z.)HeBzNCSTN!3!9r:@@BCE r)__name__ __module__ __qualname__r+r __classcell__)r0s@rr'r'Rs*  rr'c  tj|S#YnxYwtjj |}|[ t j d}||j|j|j|jd}t|d~S#~wxYwtjj|}|tj|<tjj|j}|j||S)aReturn a lazily imported proxy for a module or library. Warning ------- Importing using this function can currently cause trouble when the user tries to import from a subpackage of a module before the package is fully imported. In particular, this idiom may not work: np = lazy_import("numpy") from numpy.lib import recfunctions This is due to a difference in the way Python's LazyLoader handles subpackage imports compared to the normal import process. Hopefully we will get Python's LazyLoader to fix this, or find a workaround. In the meantime, this is a potential problem. The workaround is to import numpy before importing from the subpackage. Notes ----- We often see the following pattern:: def myfunc(): import scipy as sp sp.argmin(...) .... This is to prevent a library, in this case `scipy`, from being imported at function definition time, since that can be slow. This function provides a proxy module that, upon access, imports the actual module. So the idiom equivalent to the above example is:: sp = lazy.load("scipy") def myfunc(): sp.argmin(...) .... The initial import time is fast because the actual import is delayed until the first attribute is requested. The overall import time may decrease as well for users that don't make use of large portions of the library. Parameters ---------- fullname : str The full name of the package or subpackage to import. For example:: sp = lazy.load("scipy") # import scipy as sp spla = lazy.load("scipy.linalg") # import scipy.linalg as spla Returns ------- pm : importlib.util._LazyModule Proxy module. Can be used like any regularly imported module. Actual loading of the module occurs upon first attribute request. )r4r5r6r7r8r')sysmodulesrutil find_specinspectstackr5r6r7r8r'module_from_spec LazyLoaderloader exec_module)fullnamer4parentr-modulerLs rrrdsx {{8$$   >> # #H -D | ]]_Q'F "OO --"OO & 3 3 J,J8RS ^^ , ,T 2F"CKK ^^ & &t{{ 3F v MsABB)NN) rimportlib.utilrHrrDtypesrr ModuleTyper'rrrrrTs@ ^ $D/Nu//$Xr