o
    h                     @   s`   d dl Z d dlZ d dlZd dlZd dlZd dlZddgZdddZG dd dejZ	dd Z
dS )	    Nattach_lazy_importc                    s   |du ri }du rt  nt dd | D t B  fdd} fdd}tjdd	rGt  B D ]}|| q@||t fS )
a  Attach 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__

    Nc                 S   s    i | ]\}}|D ]}||qqS  r   ).0modattrsattrr   r   i/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/networkx/lazy_imports.py
<dictcomp>9   s
    zattach.<locals>.<dictcomp>c                    sZ   | v rt  d|  S |  v r#t  d |   }t|| S td d|  )N.zNo z attribute )	importlibimport_modulegetattrAttributeError)namesubmod)attr_to_modulesmodule_name
submodulesr   r	   __getattr__?   s   
zattach.<locals>.__getattr__c                      s    S Nr   r   )__all__r   r	   __dir__H   s   zattach.<locals>.__dir__EAGER_IMPORT )setitemslistkeysosenvironget)r   r   submod_attrsr   r   r   r   )r   r   r   r   r	   r      s   &	
c                       s(   e Zd Z fddZ fddZ  ZS )DelayedImportErrorModulec                    s   || _ t j|i | d S r   )%_DelayedImportErrorModule__frame_datasuper__init__)self
frame_dataargskwargs	__class__r   r	   r&   S   s   z!DelayedImportErrorModule.__init__c                    sf   |dv rt  | d S | j}td|d  d|d  d|d  d|d	  d
d|d p,d  
)N)r,   __file____frame_datazNo module named 'speczG'

This error is lazily reported, having originally occurred in
  File filenamez, line linenoz, in functionz

----> r   code_context)r%   r   r$   ModuleNotFoundErrorjoinstrip)r'   xfdr+   r   r	   r   W   s   z$DelayedImportErrorModule.__getattr__)__name__
__module____qualname__r&   r   __classcell__r   r   r+   r	   r#   R   s    r#   c                 C   s   zt j|  W S    Y tj| }|du r1zt d }| |j|j|j	|j
d}t|dW ~S ~w tj|}|t j| < tj|j}|| |S )a  Return 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.

    N   )r/   r0   r1   r2   r3   r#   )sysmodulesr   util	find_specinspectstackr0   r1   r2   r3   r#   module_from_spec
LazyLoaderloaderexec_module)fullnamer/   parentr(   modulerF   r   r   r	   r   d   s*   <


)NN)r   importlib.utilrB   r   r>   typesr   r   
ModuleTyper#   r   r   r   r   r	   <module>   s    
G