
    h                     v    S SK r S SKr S SKrS SKrS SKrS SKrSS/rSS jr " S S\R                  5      r	S r
g)	    Nattach_lazy_importc                   ^ ^^^	 Uc  0 nTc  [        5       mO[        T5      mUR                  5        VVVs0 s H  u  p4U  H  oUU_M     M     snnnm	[        TT	R                  5       -  5      mU	U U4S jnU4S jn[        R
                  R                  SS5      (       a+  [        T	R                  5       5      T-   H  nU" U5        M     Xg[        T5      4$ s  snnnf )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__

c                    > U T;   a  [         R                  " T SU  35      $ U T;   a)  [         R                  " T STU     35      n[        X5      $ [        ST SU  35      e)N.zNo z attribute )	importlibimport_modulegetattrAttributeError)namesubmodattr_to_modulesmodule_name
submoduless     G/var/www/html/env/lib/python3.13/site-packages/networkx/lazy_imports.py__getattr__attach.<locals>.__getattr__?   ss    :**k]!D6+BCC_$,,}Aod>S=T-UVF6(( 3{m;tf!EFF    c                     > T $ N )__all__s   r   __dir__attach.<locals>.__dir__H   s    r   EAGER_IMPORT )setitemslistkeysosenvironget)
r   r   submod_attrsmodattrsattrr   r   r   r   s
   ``      @@r   r   r      s    L U
_
 %1$6$6$8$8jcUTc	U$8O : 4 4 667GG 
zz~~nb)),,./*<D = g..-s   Cc                   4   ^  \ rS rSrU 4S jrU 4S jrSrU =r$ )DelayedImportErrorModuleR   c                 2   > Xl         [        TU ]  " U0 UD6  g r   )%_DelayedImportErrorModule__frame_datasuper__init__)self
frame_dataargskwargs	__class__s       r   r.   !DelayedImportErrorModule.__init__S   s    &$)&)r   c                    > US;   a  [         TU ]  U5        g U R                  n[        SUS    SUS    SUS    SUS	    S
SR	                  US   =(       d    S5      R                  5        3
5      e)N)r3   __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fdr3   s      r   r   $DelayedImportErrorModule.__getattr__W   s    99G"""B%#BvJ< 0Z.)HeBzNCS TN!3!9r:@@BCE r   )r7   )__name__
__module____qualname____firstlineno__r.   r   __static_attributes____classcell__)r3   s   @r   r)   r)   R   s    *
 
r   r)   c                     [         R                  U    $ !    O= f[        R                  R	                  U 5      nUc\   [
        R                  " 5       S   nU UR                  UR                  UR                  UR                  S.n[        US5      A$ ! Af = f[        R                  R                  U5      nU[         R                  U '   [        R                  R                  UR                  5      nUR                  U5        U$ )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.

   )r8   r9   r:   r;   r<   r)   )sysmodulesr   util	find_specinspectstackr9   r:   r;   r<   r)   module_from_spec
LazyLoaderloaderexec_module)fullnamer8   parentr0   modulerS   s         r   r   r   d   s    x{{8$$ >>##H-D|	]]_Q'F "OO --"OO & 3 3J ,J8RS^^,,T2F"CKK^^&&t{{3F
vMs    AB B)NN)r   importlib.utilrO   r!   rK   typesr   r   
ModuleTyper)   r   r   r   r   <module>r[      s@       	 
 ^
$D/Nu// $Xr   