U
    Uºcã  ã                   @   s0   d Z ddlZddlZddlZdd„ Zdd„ ZdS )zETensorBoard is a webapp for understanding TensorFlow runs and graphs.é    Nc                    s   ‡ fdd„}|S )a!  Decorator to define a function that lazily loads the module 'name'.

    This can be used to defer importing troublesome dependencies - e.g. ones that
    are large and infrequently used, or that cause a dependency cycle -
    until they are actually used.

    Args:
      name: the fully-qualified name of the module; typically the last segment
        of 'name' matches the name of the decorated function

    Returns:
      Decorator function that produces a lazy-loading module 'name' backed by the
      underlying decorated function.
    c                    s>   t ‡ ‡‡fdd„ƒ‰dˆ_dˆ_G ‡fdd„dtjƒ}|ˆƒS )Nc                    sD   ˆj rtdˆ ƒ‚dˆ_ z
ˆ ƒ }W 5 dˆ_ X | j |j¡ dˆ_|S )Nz,Circular import when resolving LazyModule %rTF)ÚloadingÚImportErrorÚ__dict__ÚupdateÚloaded)ÚselfÚmodule)Úload_fnÚ	load_onceÚname© ú4/tmp/pip-unpacked-wheel-g8kmtpbc/tensorboard/lazy.pyr
   *   s    ÿ
z-lazy_load.<locals>.wrapper.<locals>.load_onceFc                       s0   e Zd Z‡ fdd„Z‡ fdd„Z‡ fdd„ZdS )z.lazy_load.<locals>.wrapper.<locals>.LazyModulec                    s   t ˆ | ƒ|ƒS ©N)Úgetattr)r   Ú	attr_name©r
   r   r   Ú__getattr__@   s    z:lazy_load.<locals>.wrapper.<locals>.LazyModule.__getattr__c                    s   t ˆ | ƒƒS r   )Údir©r   r   r   r   Ú__dir__C   s    z6lazy_load.<locals>.wrapper.<locals>.LazyModule.__dir__c                    s   ˆ j rdˆ | ƒ S d| j S )Nz<%r via LazyModule (loaded)>z+<module %r via LazyModule (not yet loaded)>)r   Ú__name__r   r   r   r   Ú__repr__F   s    ÿÿz7lazy_load.<locals>.wrapper.<locals>.LazyModule.__repr__N)r   Ú
__module__Ú__qualname__r   r   r   r   r   r   r   Ú
LazyModule?   s   r   )Ú_memoizer   r   ÚtypesÚ
ModuleType)r	   r   ©r   )r	   r
   r   Úwrapper'   s    zlazy_load.<locals>.wrapperr   )r   r   r   r   r   Ú	lazy_load   s    )r    c                    s2   t ƒ ‰i ‰ t ¡ ‰t ˆ¡‡ ‡‡‡fdd„ƒ}|S )zKMemoizing decorator for f, which must have exactly 1 hashable
    argument.c              	      sD   ˆ   | ˆ¡ˆkr<ˆ" ˆ   | ˆ¡ˆkr2ˆ| ƒˆ | < W 5 Q R X ˆ |  S r   )Úget)Úarg©ÚcacheÚfÚlockZnothingr   r   r   \   s
    z_memoize.<locals>.wrapper)ÚobjectÚ	threadingÚRLockÚ	functoolsÚwraps)r%   r   r   r#   r   r   S   s    r   )Ú__doc__r*   r(   r   r    r   r   r   r   r   Ú<module>   s
   <