B
    åCer  ã               @   s¬   d dl Z d dlZd dlmZ d dlmZ d dlmZmZmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZ er~d dlZeje Ze  d¡ZG d	d
„ d
eƒZG dd„ deƒZdS )é    N)ÚPath)Úsocket)ÚTYPE_CHECKINGÚCallableÚDictÚListÚOptional)ÚDefaultWatcher)ÚConfig)Ú
BaseReloadzuvicorn.errorc                   sD   e Zd Zeedœ‡ fdd„Zdedœdd„Zdedœdd	„Z‡  Z	S )
ÚCustomWatcher)Ú	root_pathÚconfigc                s´   dg}‡ fdd„|D ƒ| _ | j  ˆ j¡ tt| j ƒƒ| _ ddddg}‡ fdd„|D ƒ| _| j ˆ j¡ tt| jƒƒ| _i | _i | _tˆ j	ƒ| _
tˆ jƒ| _|| _tƒ  t|ƒ¡ d S )	Nz*.pyc                s   g | ]}|ˆ j kr|‘qS © )Úreload_excludes)Ú.0Údefault)r   r   úv/var/www/downstreamdata.science/rtclock/rtclock-venv/lib/python3.7/site-packages/uvicorn/supervisors/watchgodreload.pyú
<listcomp>   s   z*CustomWatcher.__init__.<locals>.<listcomp>z.*z.py[cod]z.sw.*z~*c                s   g | ]}|ˆ j kr|‘qS r   )Úreload_includes)r   r   )r   r   r   r   !   s   )ÚincludesÚextendr   ÚlistÚsetÚexcludesr   Úwatched_dirsÚwatched_filesÚreload_dirsÚdirs_includesZreload_dirs_excludesÚdirs_excludesÚresolved_rootÚsuperÚ__init__Ústr)Úselfr   r   Zdefault_includesZdefault_excludes)Ú	__class__)r   r   r"      s     



zCustomWatcher.__init__ÚDirEntry)ÚentryÚreturnc             C   s²   | j  |j¡}|d k	r|S t|ƒ}|jt ¡ krNt ¡ | jkrNd| j |j< dS xR| jD ]H}| |¡rVx(| j	D ]}| |¡rld| j |j< dS qlW d| j |j< dS qVW d| j |j< dS )NFT)
r   ÚgetÚpathr   ÚparentÚcwdr   r   Úmatchr   )r$   r'   Úcached_resultÚ
entry_pathÚinclude_patternÚexclude_patternr   r   r   Úshould_watch_file/   s"    

zCustomWatcher.should_watch_filec             C   sp  | j  |j¡}|d k	r|S t|ƒ}|| jkr<d| j |j< dS x„| jD ]z}| |¡rDd}|| jkrdd}x| jD ]}||jkrld}qlW |r¢t	 
d| | j¡t| jƒ¡ d| j |j< | j |¡ dS qDW || jkrÜd| j |j< dS x(| jD ]}||jkräd| j |j< dS qäW xX| jD ]N}| |¡rt	 dt| | j¡ƒt| jƒ¡ | j |¡ d| j |j< dS qW d| j |j< dS )NFTzPWatchGodReload detected a new excluded dir '%s' in '%s'; Adding to exclude list.zLWatchGodReload detected a new reload dir '%s' in '%s'; Adding to watch list.)r   r)   r*   r   r   r   r-   r   ÚparentsÚloggerÚdebugÚrelative_tor    r#   Úaddr   Úinfo)r$   r'   r.   r/   r1   Z
is_watchedÚ	directoryr0   r   r   r   Úshould_watch_dirE   sR    







zCustomWatcher.should_watch_dir)
Ú__name__Ú
__module__Ú__qualname__r   r
   r"   Úboolr2   r:   Ú__classcell__r   r   )r%   r   r      s   r   c                   sT   e Zd Zeeeee  gdf ee ddœ‡ fdd„Zeee	  dœdd„Z
‡  ZS )ÚWatchGodReloadN)r   ÚtargetÚsocketsr(   c                s˜   t  dt¡ tƒ  |||¡ d| _g | _g }x&|jD ]}t 	¡ |j
kr4| |¡ q4W t 	¡ |krn| t 	¡ ¡ x$|D ]}| j t| ¡ | jƒ¡ qtW d S )NzU"watchgod" is deprecated, you should switch to watchfiles (`pip install watchfiles`).ZWatchGod)ÚwarningsÚwarnÚDeprecationWarningr!   r"   Zreloader_nameÚwatchersr   r   r,   r3   Úappendr   Úresolver   )r$   r   rA   rB   r   r9   Úw)r%   r   r   r"      s    
zWatchGodReload.__init__)r(   c             C   s@   |   ¡  x2| jD ](}| ¡ }|tƒ krtdd„ |D ƒƒS qW d S )Nc             S   s   h | ]}t |d  ƒ’qS )é   )r   )r   Úcr   r   r   ú	<setcomp>œ   s    z0WatchGodReload.should_restart.<locals>.<setcomp>)ÚpauserF   Úcheckr   r   )r$   ÚwatcherZchanger   r   r   Úshould_restart–   s    
zWatchGodReload.should_restart)r;   r<   r=   r
   r   r   r   r   r"   r   rP   r?   r   r   )r%   r   r@   ~   s
   r@   )ÚloggingrC   Úpathlibr   r   Útypingr   r   r   r   r   Zwatchgodr	   Zuvicorn.configr
   Zuvicorn.supervisors.basereloadr   Úosr&   r#   Ú	getLoggerr4   r   r@   r   r   r   r   Ú<module>   s   

j