a
    њh                  	   @   s  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 d dlmZ d dl	m
Z
mZmZmZmZmZmZ ddlmZ ddlmZmZmZ ddlmZmZmZ dd	lmZ ed
ZeedddZ eddddZ!ee
dddZ"eee eedeeeege#f f ef dddZ$dS )    N)Path)dedent)AnyCallableListOptionalTupleUnioncast   )Change)
BaseFilterDefaultFilterPythonFilter)detect_target_typeimport_stringrun_process)VERSIONzwatchfiles.cli)path_strreturnc                 C   s&   t | }| st|n| S d S )N)r   existsFileNotFoundErrorresolve)r   path r   I/wd/webapps/venvs/v2025_4um/lib/python3.9/site-packages/watchfiles/cli.pyresolve_path   s    
r   )args_r   c                  G   s  | pt jdd }tjdttjp"ddtjd}|j	ddd	 |j	d
dddd |j	ddt
dd |j	ddt
dg ddd |j	ddt
ddd |j	ddt
dd |j	ddd d! |j	d"dd#d! |j	d$dt
d%g d&d'd |j	d(dtd)d*d |j	d+dtd,d-d |j	d.dtdd/d |j	d0dd1d! |j	d2d3d4d5t d6 ||}|jr^tj}ntt|j }t }|| |tjd7d8d9 td}|| || |jdkrt|j}n|j}|d:krtd;|j t |j |j!r$|jgt"#|j! t _n|j!r$t$d< zd=d> |j%D }W nF t&y~ }	 z,t'd?|	 d@t j(dA t )d W Y d}	~	n
d}	~	0 0 t*|j+|j,\}
}t-dBtdC.dDdE |D |j|| t/||j||
|tjk|j0|j1|j2 |j3|j4dF	 dS )Ga  
    Watch one or more directories and execute either a shell command or a python function on file changes.

    Example of watching the current directory and calling a python function:

        watchfiles foobar.main

    Example of watching python files in two local directories and calling a shell command:

        watchfiles --filter python 'pytest --lf' src tests

    See https://watchfiles.helpmanual.io/cli/ for more information.
    r   NZ
watchfiles 
)progdescriptionformatter_classtargetz&Command or dotted function path to run)helppaths*.z8Filesystem paths to watch, defaults to current directory)nargsdefaultr$   z--ignore-paths?zrSpecify directories to ignore, to ignore multiple paths use a comma as separator, e.g. "env" or "env,node_modules")r(   typer$   z--target-typeauto)commandfunctionr,   zWhether the target should be intercepted as a shell command or a python function, defaults to "auto" which infers the target type from the target string)r(   r+   r)   choicesr$   z--filterr)   zWhich files to watch, defaults to "default" which uses the "DefaultFilter", "python" uses the "PythonFilter", "all" uses no filter, any other value is interpreted as a python function/class path which is imported)r(   r+   r)   r$   z--argszbArguments to set on sys.argv before calling target function, used only if the target is a functionz	--verbose
store_truez1Set log level to "debug", wins over `--verbosity`)actionr$   z--non-recursivez7Do not watch for changes in sub-directories recursivelyz--verbosityinfo)warningr2   debugzLog level, defaults to "info"z--sigint-timeout   z?How long to wait for the sigint timeout before sending sigkill.z--grace-periodr   zKNumber of seconds after the process is started before watching for changes.z--sigkill-timeoutzLHow long to wait for the sigkill timeout before issuing a timeout exception.z--ignore-permission-deniedzEIgnore permission denied errors while watching files and directories.z	--versionz-Vversionz
%(prog)s v)r1   r6   z[%(asctime)s] %(message)sz%H:%M:%S)fmtdatefmtr.   z/target_type=function, attempting import of "%s"z1--args is only used when the target is a functionc                 S   s   g | ]}t |qS r   )r   .0pr   r   r   
<listcomp>       zcli.<locals>.<listcomp>zpath "z" does not existfileu:   watchfiles v%s 👀  path=%s target="%s" (%s) filter=%s...z, c                 s   s   | ]}d | d V  qdS )"Nr   r9   r   r   r   	<genexpr>   r=   zcli.<locals>.<genexpr>)	r#   target_typewatch_filterr4   sigint_timeoutsigkill_timeout	recursiveignore_permission_deniedgrace_period)5sysargvargparseArgumentParserr   cli__doc__stripRawTextHelpFormatteradd_argumentstrintfloatr   
parse_argsverboseloggingDEBUGgetattr	verbosityupperStreamHandlersetLevelsetFormatter	Formatter	getLogger
addHandlerrB   r   r#   loggerr4   import_exitargsshlexsplitr3   r%   r   printstderrexitbuild_filterfilterignore_pathsr2   joinr   rD   rE   Znon_recursiverG   rH   )r   rd   parserZarg_namespaceZ	log_levelhdlrZ	wg_loggerrB   r%   erC   Zwatch_filter_strr   r   r   rM      s    	







 	rM   )function_pathr   c              
   C   sp   t  }|tjvrtj| z
t| W S  tyj } z*td| tjd t	d W Y d }~n
d }~0 0 d S )NzImportError: r>   r   )
osgetcwdrI   r   appendr   ImportErrorrg   rh   ri   )rq   cwdrp   r   r   r   rc      s    

rc   )filter_nameignore_paths_strr   c                 C   s   g }|rdd | dD }| dkr2t|ddfS | dkrHt|ddfS | d	krb|r^td
 dS t| }t|trt|tr||d|j	fS |rtd t|trt|t
r| |j	fS ttttgtf |}|t|fS d S )Nc                 S   s   g | ]}t | qS r   )r   r   r9   r   r   r   r<      r=   z build_filter.<locals>.<listcomp>,r)   )rl   r   pythonr   allz>"--ignore-paths" argument ignored as "all" filter was selected)Nz(no filter)zN"--ignore-paths" argument ignored as filter is not a subclass of DefaultFilter)rf   r   r   rb   r3   rc   
isinstancer+   
issubclass__name__r   r
   r   r   rR   boolrepr)rw   rx   rl   Zwatch_filter_clsrC   r   r   r   rj      s(    

rj   )%rK   rW   rr   re   rI   pathlibr   textwrapr   typingr   r   r   r   r   r	   r
   r   r   filtersr   r   r   runr   r   r   r6   r   r`   rb   rR   r   rM   rc   r   rj   r   r   r   r   <module>   s&   $
   