o
    3g                     @  s"  d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ zdd	lmZ W n4 ey` Z z(zdd
lmZ ed W n eyU Z zeZW Y dZ[ndZ[ww W Y dZ[ndZ[ww dZeG dd deZddlmZ eeZddlmZ ddlmZ edddZdddZdS )z+
Bindings for the 'core' HPI configuration
    )annotationsN)Sequence)	dataclass)Path   )warnings)core)commonzB'common' config section is deprecated. Please rename it to 'core'. c                   @  sh   e Zd ZU dZeZded< 	 dZded< 	 dZded< 	 dZ	ded< 	 dddZ
dddZdddZdS )Configz
    Config for the HPI itself.
    To override, add to your config file something like

    class config:
        cache_dir = '/your/custom/cache/path'
    zPath | str | None	cache_dirNtmp_dirzSequence[str] | Noneenabled_modulesdisabled_modulesreturnPath | Nonec                 C  s8   | j }|d u r	d S |tkrddlm} | S t| S )Nr   )_appdirs_cache_dir)r   _HPI_CACHE_DIR_DEFAULTcachewr   r   
expanduser)selfcdirr    r   -/home/garg/my-data/HPI/my/core/core_config.pyget_cache_dirG   s   zConfig.get_cache_dirr   c                 C  sJ   | j }|d u rdd l}t| d }nt|}| }|jddd |S )Nr   HPIT)parentsexist_ok)r   tempfiler   
gettempdirr   mkdir)r   tdirr   tpathr   r   r   get_tmp_dirR   s   zConfig.get_tmp_dirmodulestrbool | Nonec                   sj   d fdd}|| j pg }|| jpg }|d u r!|d u rd S dS |d u r'dS td	| d
| d dS )NspecsSequence[str]r   
str | Nonec                   s"   | D ]}t | r|  S qd S )N)rematch)r'   specr$   r   r   matchesc   s
   z)Config._is_module_active.<locals>.matchesFTz[module]: conflicting regexes 'z' and 'z5' are set in the config. Please only use one of them.)r'   r(   r   r)   )r   r   r   medium)r   r$   r.   onoffr   r-   r   _is_module_active`   s   zConfig._is_module_active)r   r   )r   r   )r$   r%   r   r&   )__name__
__module____qualname____doc__r   r   __annotations__r   r   r   r   r#   r2   r   r   r   r   r      s   
 	

r   )make_config)Iterator)contextmanagerr   Iterator[Config]c                  c  sT    ddl m}  | t}d |_d |_d |_|V  W d    d S 1 s#w   Y  d S )Nr   )_override_config)cfgr<   configr   r   r   )r<   ccr   r   r   _reset_config   s   
"r@   Nonec               	   C  s  dd l } t}| #}|dd u sJ |dd u sJ |dd u s%J W d    n1 s/w   Y  | +}dg|_dg|_|ddu sIJ |dd u sRJ |ddu s[J W d    n1 sew   Y  | K}dg|_dg|_|dd u sJ |dd u sJ | jtdd	}|ddu sJ W d    n1 sw   Y  t|d
ksJ W d    d S 1 sw   Y  d S )Nr   zmy.whateverzmy.corezmy.body.exercisez	my.body.*TFzconflicting regexes)r+   r   )pytestr@   r2   r   r   warnsUserWarninglen)rB   resetr?   record_warningsr   r   r   test_active_modules   s0   "rH   )r   r;   )r   rA   ) r6   
__future__r   r*   collections.abcr   dataclassesr   pathlibr   r
   r   	my.configr   user_config	Exceptioner	   highe2objectr   r   r=   r8   r>   r9   
contextlibr:   ctxr@   rH   r   r   r   r   <module>   s:    \
