a
    =b@                     @   s6   d dl Z d dlZ d dlZd dlZdddZdd ZdS )    Nc                    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	}|d
vrt  B D ]}|| q||t fS )a,  Attach lazily loaded submodules, functions, or other attributes.

    Typically, modules import submodules and attributes as follows::

      import mysubmodule
      import anothersubmodule

      from .foo import someattr

    The idea is to replace a package's `__getattr__`, `__dir__`, and
    `__all__`, such that all imports work exactly the way they did
    before, except that they are only imported when 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
    ----------
    package_name : str
        Typically use ``__name__``.
    submodules : set
        List of submodules to attach.
    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   3lib/python3.9/site-packages/skimage/_shared/lazy.py
<dictcomp>6   s   zattach.<locals>.<dictcomp>c                    s^   | v rt  d|  S |  v rFt  d |   }t|| S td d|  d S )N.zNo z attribute )	importlibimport_modulegetattrAttributeError)nameZsubmod)attr_to_modulespackage_name
submodulesr   r   __getattr__<   s    
zattach.<locals>.__getattr__c                      s    S )Nr   r   )__all__r   r   __dir__G   s    zattach.<locals>.__dir__ZEAGER_IMPORT )r   0Zfalse)setitemslistkeysosenvironget)r   r   Zsubmod_attrsr   r   Zeager_importr   r   )r   r   r   r   r   attach   s     '
r   c                 C   sv   zt j|  W S  ty   Y n0 tj| }|du rDtd|  dtj|}|t j| < tj|j	}|
| |S )a  Return a lazily imported proxy for a module.

    We often see the following pattern::

      def myfunc():
          import scipy as sp
          sp.argmin(...)
          ....

    This is to prevent a module, 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 module or submodule 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.

    NzNo module name '')sysmodulesKeyErrorr
   util	find_specModuleNotFoundErrormodule_from_spec
LazyLoaderloaderexec_module)fullnamespecmoduler(   r   r   r   loadR   s    *

r-   )NN)r
   importlib.utilr   r    r   r-   r   r   r   r   <module>   s
   
K