a
    ij!                     @  s   d Z ddlmZ 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l	m
Z
mZ ejG dd dZddddd	d
ZejddddZdddddddZdS )zLazy import utils.    )annotationsN)AnyIteratorc                   @  sR   e Zd ZU dZded< ejedZded< e	j
ddd	d
ZdddddZdS )
LazyModulez'Module loaded lazily during first call.strmodule_name)default_factoryzdict[str, LazyModule]_submodulesztypes.ModuleTypereturnc                 C  s   t | jS N)	importlibimport_moduler   )self r   Z/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/etils/epy/lazy_imports_utils.py_module+   s    zLazyModule._moduler   )namer   c                 C  s$   || j v r| j | S t| j|S d S r   )r	   getattrr   )r   r   r   r   r   __getattr__/   s    

zLazyModule.__getattr__N)__name__
__module____qualname____doc____annotations__dataclassesfielddictr	   	functoolscached_propertyr   r   r   r   r   r   r   $   s   
r   r   )moduler   r   c                 C  s$   t | j d| d}|| j|< |S )N.r   )r   r   r	   )r    r   Zchild_moduler   r   r   _register_submodule9   s
    
r#   zIterator[None]r
   c                  c  s*   t j} ztt _dV  W | t _n| t _0 dS )a  Context Manager which lazy loads packages.

  Their import is not executed immediately, but is postponed to the first
  call of one of their attributes.

  Limitation:

  - You can only lazy load modules (`from x import y` will not work if `y` is a
    constant or a function or a class).

  Usage:

  ```python
  with epy.lazy_imports():
    import tensorflow as tf
  ```

  Yields:
    None
  N)builtins
__import___lazy_import)Zoriginal_importr   r   r   lazy_importsA   s
    r'   r   ztuple[str, ...]int)r   fromlistlevelc           
      C  sl   ~~|rt d|  d| d^}}t|d}|}|D ]} t|| }q8|rd|D ]}	t||	 qP|S |S dS )zMock of `builtins.__import__`.z*Relative import statements not supported (z).r!   r"   N)
ValueErrorsplitr   r#   )
r   globals_Zlocals_r)   r*   Z	root_namepartsrootchildflr   r   r   r&   a   s    
r&   )NNr   r   )r   
__future__r   r$   
contextlibr   r   r   typestypingr   r   	dataclassr   r#   contextmanagerr'   r&   r   r   r   r   <module>   s$   
!    