o
    Þ­j  ã                   @   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dedefdd„Z deddfdd„Z!dede
fdd„Z"dedee deedeeeege#f f ef f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|ƒ‚| ¡ S )N)r   ÚexistsÚFileNotFoundErrorÚresolve)r   Úpath© r   úK/var/www/html/CropPilot/venv/lib/python3.10/site-packages/watchfiles/cli.pyÚresolve_path   s   r   Úargs_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rãt|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 n# t&�y= }	 zt'd?|	› d@�t j(dA� t  )d¡ W Y d}	~	nd}	~	ww 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   NÚ
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-   z˜Whether 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*   zÔWhich 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)Úwarningr3   Ú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)r2   r7   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>›   s    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   r:   r   r   r   Ú	<genexpr>¥   s   € zcli.<locals>.<genexpr>)	r$   Útarget_typeÚwatch_filterr5   Ú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$   Úloggerr5   Úimport_exitÚargsÚshlexÚsplitr4   r&   r   ÚprintÚstderrÚexitÚbuild_filterÚfilterÚignore_pathsr3   Újoinr   rD   rE   Únon_recursiverG   rH   )r   rd   ÚparserÚarg_namespaceÚ	log_levelÚhdlrÚ	wg_loggerrB   r&   ÚerC   Úwatch_filter_strr   r   r   rM      sú   ýÿû	ùúüÿúûûûý







€
€þú	örM   Úfunction_pathc              
   C   sn   t  ¡ }|tjvrtj |¡ zt| ƒW S  ty6 } ztd|› �tjd� t 	d¡ W Y d }~d S d }~ww )NzImportError: r>   r   )
ÚosÚgetcwdrI   r   Úappendr   ÚImportErrorrg   rh   ri   )rv   Úcwdrt   r   r   r   rc   ¹   s   

€þrc   Úfilter_nameÚignore_paths_strc                 C   sÞ   g }|rdd„ |  d¡D ƒ}| dkrt|d�dfS | dkr$t|d�dfS | d	kr1|r/t d
¡ dS t| ƒ}t|tƒrGt|tƒrG||d�|j	fS |rNt d¡ t|tƒr^t|t
ƒr^|ƒ |j	fS ttttgtf |ƒ}|t|ƒfS )Nc                 S   s   g | ]}t |ƒ ¡ ‘qS r   )r   r   r:   r   r   r   r=   Ê   s    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   r4   rc   Ú
isinstancer,   Ú
issubclassÚ__name__r   r
   r   r   rR   ÚboolÚrepr)r|   r}   rl   Úwatch_filter_clsrC   r   r   r   rj   Å   s(   

rj   )%rK   rW   rw   re   rI   Úpathlibr   Útextwrapr   Útypingr   r   r   r   r   r	   r
   r   r   Úfiltersr   r   r   Úrunr   r   r   r7   r   r`   rb   rR   r   rM   rc   r„   rj   r   r   r   r   Ú<module>   s0    $
  ÿÿ þ