o
    3gr                     @  s   d Z ddlmZ ddlZddlmZmZ ddlmZ ddl	m
Z
mZmZ ddlmZ e
Zed	ed
ee f dZdZeddddddZdS )z
Decorator to gracefully handle importing a data source, or warning
and yielding nothing (or a default) when its not available
    )annotationsN)IterableIteratorwraps)AnyCallableTypeVar   )mediumFactoryF.)bound )defaultmodule_namehelp_urlr   Iterable[T]r   
str | Noner   return)Callable[..., Callable[..., Iterator[T]]]c                   s   d fdd}|S )	a  
    doesn't really play well with types, but is used to catch
    ModuleNotFoundError's for when modules aren't installed in
    all.py files, so the types don't particularly matter

    this is meant to be used to wrap some function which imports
    and then yields an iterator of objects

    If the user doesn't have that module installed, it returns
    nothing and warns instead
    factory_funcr   r   Callable[..., Iterator[T]]c                   s    t  d fdd}|S )Nr   Iterator[T]c               
   ?  s   z| i |}|E d H  W d S  t tfy } ziddlm} ddlm} d}d ur6|jdu r6d}|swd u rFtdj	 d ntd dj	 d	 t
jd
 dddd t|t tfrw||d}|swt|trw| E d H  W Y d }~d S d }~ww )Nr
   )core_config)warn_my_config_import_errorFTzModule z4 could not be imported, or isn't configured properlyz (z5) could not be imported, or isn't configured properlyzAIf you don't want to use this module, to hide this message, add 'zb' to your core config disabled_modules in your config, like:

class core:
    disabled_modules = [z]
)
stacklevel)r   r   )ImportErrorAttributeError r   errorr   config_is_module_activer   __qualname__warningswarn
isinstance)argskwargsreserrCCr   suppressed_in_confmatched_config_err)r   r   r   r   r   (/home/garg/my-data/HPI/my/core/source.pywrapper0   s4   z1import_source.<locals>.decorator.<locals>.wrapper)r   r   r   )r   r.   r   r   r   )r   r-   	decorator/   s   z import_source.<locals>.decoratorN)r   r   r   r   r   )r   r   r   r0   r   r/   r-   import_source   s   #r1   )r   r   r   r   r   r   r   r   )__doc__
__future__r   r#   collections.abcr   r   	functoolsr   typingr   r   r	   r   Tr   _DEFAULT_ITRr1   r   r   r   r-   <module>   s    