+
    ~j;                     `   ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	H
t
Ht ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHtHt ^ RIt^R	IHt ^R
IHtHtHtH t  ]'       d   ^ RIH!t! R7t"]PF                  ! R4      t$RR8RRRRRRR]! 4       R^ RRR^2RRR^R^RRRR/R R llt%RR8RRRRRRR]! 4       R^ RRR^2RRRRRR/R  R! llt&]! R"4      t'R# R$ lt(R9R% R& llt)R' R( lt* ! R) R*4      t+R+ R, lt,R- R. lt-R/ R0 lt.] P^                  R1 R2 l4       t0R3 R4 lt1R5 R6 lt2R# ):    N)Callable	Generator)import_module)get_context)SpawnProcess)Path)sleep)TYPE_CHECKINGAny)DefaultFilter)Change
FileChangeawatchwatch)Literalzwatchfiles.mainargskwargstarget_typeautocallbackwatch_filtergrace_perioddebouncei@  stepdebugsigint_timeoutsigkill_timeout	recursiveTignore_permission_deniedFc                    V ^8  d   QhR\         \        ,          R\        \        R\        3,          ,          R\        \        R3,          R\
        \        \        3,          R,          RRR	\        \        \        ,          .R3,          R,          R
\        \        \        .\        3,          R,          R\        R\        R\        R\        R,          R\        R\        R\        R\        R\        /# )   pathstarget.r   r   Nr   &Literal['function', 'command', 'auto']r   r   r   r   r   r   r   r   r   r   returnr   strr   r   tupledictsetr   r   boolfloatint)formats   "c/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/watchfiles/run.py__annotate__r0      s    } }3J}(38$$} S/} cNT!	}
 :} J($./$6} FC=$./$6} } } } $;} } } } #}  	!}    c                   VR8X  d   \        V 4      p\        P                  RW4       \        4        \	        WW4      p^ pV'       d"   \        P                  RV4       \        V4        \        VRVRVRVRV	RR	R
VRV/  F=  pT;'       d	    V! V4       VP                  WR7       \	        WWV4      pV^,          pK?  	  VP                  4        V#   TP                  4        i ; i)u  
Run a process and restart it upon file changes.

`run_process` can work in two ways:

* Using `multiprocessing.Process` † to run a python function
* Or, using `subprocess.Popen` to run a command

!!! note

    **†** technically `multiprocessing.get_context('spawn').Process` to avoid forking and improve
    code reload/import.

Internally, `run_process` uses [`watch`][watchfiles.watch] with `raise_interrupt=False` so the function
exits cleanly upon `Ctrl+C`.

Args:
    *paths: matches the same argument of [`watch`][watchfiles.watch]
    target: function or command to run
    args: arguments to pass to `target`, only used if `target` is a function
    kwargs: keyword arguments to pass to `target`, only used if `target` is a function
    target_type: type of target. Can be `'function'`, `'command'`, or `'auto'` in which case
        [`detect_target_type`][watchfiles.run.detect_target_type] is used to determine the type.
    callback: function to call on each reload, the function should accept a set of changes as the sole argument
    watch_filter: matches the same argument of [`watch`][watchfiles.watch]
    grace_period: number of seconds after the process is started before watching for changes
    debounce: matches the same argument of [`watch`][watchfiles.watch]
    step: matches the same argument of [`watch`][watchfiles.watch]
    debug: matches the same argument of [`watch`][watchfiles.watch]
    sigint_timeout: the number of seconds to wait after sending sigint before sending sigkill
    sigkill_timeout: the number of seconds to wait after sending sigkill before raising an exception
    recursive: matches the same argument of [`watch`][watchfiles.watch]

Returns:
    number of times the function was reloaded.

```py title="Example of run_process running a function"
from watchfiles import run_process

def callback(changes):
    print('changes detected:', changes)

def foobar(a, b):
    print('foobar called with:', a, b)

if __name__ == '__main__':
    run_process('./path/to/dir', target=foobar, args=(1, 2), callback=callback)
```

As well as using a `callback` function, changes can be accessed from within the target function,
using the `WATCHFILES_CHANGES` environment variable.

```py title="Example of run_process accessing changes"
from watchfiles import run_process

def foobar(a, b, c):
    # changes will be an empty list "[]" the first time the function is called
    changes = os.getenv('WATCHFILES_CHANGES')
    changes = json.loads(changes)
    print('foobar called due to changes:', changes)

if __name__ == '__main__':
    run_process('./path/to/dir', target=foobar, args=(1, 2, 3))
```

Again with the target as `command`, `WATCHFILES_CHANGES` can be used
to access changes.

```bash title="example.sh"
echo "changers: ${WATCHFILES_CHANGES}"
```

```py title="Example of run_process running a command"
from watchfiles import run_process

if __name__ == '__main__':
    run_process('.', target='./example.sh')
```
r   running "%s" as %s3sleeping for %s seconds before watching for changesr   r   r   r   raise_interruptFr   r   )r   r   )detect_target_typeloggerr   catch_sigtermstart_processr	   r   stop)r#   r   r   r   r   r   r   r   r   r   r   r   r   r   r"   processreloadschangess   $$$$$$$$$$$$$$*   r/   run_processr>      s   @ f(0
LL%v;OF>GGJLYl	
%	
 	
 		

 	
 "	
  	
 &>	
G **'*LLLX#FwOGqLG	
 	N 	s   +"C 5C C'c                   V ^8  d   QhR\         \        ,          R\        \        R\        3,          ,          R\        \        R3,          R\
        \        \        3,          R,          RRR	\        \        \        ,          .\        3,          R,          R
\        \        \        .\        3,          R,          R\        R\        R\        R\        R,          R\        R\        R\        /# )r!   r"   r#   .r   r   Nr   r$   r   r   r   r   r   r   r   r   r%   r&   )r.   s   "r/   r0   r0      s     M M3JM(38$$M S/M cNT!	M
 :M J(#-.5M FC=$./$6M M M M $;M M #M 	Mr1   c                :  "   ^ RI pVR8X  d   \        V 4      p\        P                  RW4       \	        4        \
        P                  P                  \        WW4      G Rj  xL
 p^ pV'       d5   \        P                  RV4       \
        P                  ! V4      G Rj  xL
  \        VRVRVRVRV	R	V
R
V/   Rj  xL
  pVe*   V! V4      pVP                  V4      '       d   VG Rj  xL
  \
        P                  P                  VP                  4      G Rj  xL
  \
        P                  P                  \        WWV4      G Rj  xL
 pV^,          pK   L L L Lt LE LD\
        P                  P                  TP                  4      G Rj  xL 
  T# 5i)a  
Async equivalent of [`run_process`][watchfiles.run_process], all arguments match those of `run_process` except
`callback` which can be a coroutine.

Starting and stopping the process and watching for changes is done in a separate thread.

As with `run_process`, internally `arun_process` uses [`awatch`][watchfiles.awatch], however `KeyboardInterrupt`
cannot be caught and suppressed in `awatch` so these errors need to be caught separately, see below.

```py title="Example of arun_process usage"
import asyncio
from watchfiles import arun_process

async def callback(changes):
    await asyncio.sleep(0.1)
    print('changes detected:', changes)

def foobar(a, b):
    print('foobar called with:', a, b)

async def main():
    await arun_process('.', target=foobar, args=(1, 2), callback=callback)

if __name__ == '__main__':
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print('stopped via KeyboardInterrupt')
```
Nr   r3   r4   r   r   r   r   r   r   )inspectr6   r7   r   r8   anyio	to_threadrun_syncr9   r	   r   isawaitabler:   )r#   r   r   r   r   r   r   r   r   r   r   r   r"   rA   r;   r<   r=   rs   $$$$$$$$$$$$*     r/   arun_processrG      sx    Z f(0
LL%v;OOO,,]FQU^^GGJLYkk,'''	!  	
   ":  g !A""1%%oo&&w||44400UYcjkk1/ _
 	( 4k" //
"
"7<<
000Ns   AF!E"F0/FE F9E&=E>E&$F&F+E ,0FE"-F
E$FFE& F"F$F&-FFFspawnc                F    V ^8  d   QhR\         R\        \         ,          /# )r!   cmdr%   )r'   list)r.   s   "r/   r0   r0      s     ) )3 )49 )r1   c                     ^ RI pVP                  4       P                  P                  4       R8g  p\        P
                  ! WR7      # )r   Nwindows)posix)platformunamesystemlowershlexsplit)rJ   rO   rN   s   &  r/   	split_cmdrU      s4    NN##))+y8E;;s((r1   c                    V ^8  d   QhR\         \        R\        3,          ,          RRR\        \        R3,          R\        \         \        3,          R,          R\
        \        ,          R,          R	R
/# )r!   r#   .r   Literal['function', 'command']r   r   Nr=   r%   CombinedProcess)r'   r   r   r(   r)   r*   r   )r.   s   "r/   r0   r0      sp     !$ !$(38$$!$1!$ S/!$ cNT!	!$
 _t#!$ !$r1   c                 d   Vf   RpM:\         P                  ! V UUu. uF  w  rgVP                  4       V.NK  	  upp4      pV\        P                  R&   VR8X  dc   T;'       g    / p\        V \        4      '       d   V \        4       W#3p\        p/ pMT p\        P                  WVR7      p	V	P                  4        McV'       g	   V'       d   \        P                  R4       \        V \        4      '       g   Q R4       h\        V 4      p
\        P                   ! V
4      p	\#        V	4      # u uppi )Nz[]WATCHFILES_CHANGESfunction)r#   r   r   z-ignoring args and kwargs for "command" targetz+target must be a string to run as a command)jsondumpsraw_strosenviron
isinstancer'   get_tty_pathrun_functionspawn_contextProcessstartr7   warningrU   
subprocessPopenrX   )r#   r   r   r   r=   changes_env_varcptarget_r;   
popen_argss   &&&&&      r/   r9   r9      s     **7%K741qyy{A&67%KL'6BJJ#$ j 2fc""<>47D"GFG''w&'Q6NNJK&#&&U(UU&v&
"":.7##/ &Ls   D,
c                X    V ^8  d   QhR\         \        R\        3,          ,          RR/# )r!   r#   .r%   rW   )r'   r   r   )r.   s   "r/   r0   r0     s)      sXc3h%77 <\ r1   c                    \        V \        4      '       g   R# V P                  R4      '       d   R# \        P                  ! RV 4      '       d   R# R# )a&  
Used by [`run_process`][watchfiles.run_process], [`arun_process`][watchfiles.arun_process]
and indirectly the CLI to determine the target type with `target_type` is `auto`.

Detects the target type - either `function` or `command`. This method is only called with `target_type='auto'`.

The following logic is employed:

* If `target` is not a string, it is assumed to be a function
* If `target` ends with `.py` or `.sh`, it is assumed to be a command
* Otherwise, the target is assumed to be a function if it matches the regex `[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+`

If this logic does not work for you, specify the target type explicitly using the `target_type` function argument
or `--target-type` command line argument.

Args:
    target: The target value

Returns:
    either `'function'` or `'command'`
r[   commandz[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+)z.pyz.sh)ra   r'   endswithre	fullmatch)r#   s   &r/   r6   r6     s>    , fc""		(	(	8&	A	Ar1   c                      a  ] tR tRt o V 3R lR ltRV 3R lR lltV 3R lR lt]V 3R lR	 l4       tV 3R
 lR lt	]V 3R lR l4       t
RtV tR# )rX   i>  c                   < V ^8  d   QhRR/# )r!   rl   z&SpawnProcess | subprocess.Popen[bytes] )r.   __classdict__s   "r/   r0   CombinedProcess.__annotate__?  s     ? ?B ?r1   c                <    Wn         V P                  f   Q R4       hR # )Nzprocess not yet spawned_ppid)selfrl   s   &&r/   __init__CombinedProcess.__init__?  s    xx#>%>>#r1   c                *   < V ^8  d   QhRS[ RS[ RR/# )r!   r   r   r%   Nr-   )r.   rx   s   "r/   r0   ry   C  s'     Q Q3 QS Q Qr1   c                   \         P                  P                  R R4       V P                  4       '       d   \        P                  R4       \         P                  ! V P                  \        P                  4        V P                  V4       V P                  fX   \        P                  R4       \         P                  ! V P                  \        P                  4       V P                  V4       R# \        P                  R4       R# \        P                  RV P                  4       R#   \        P                   d    \        P                  RT4        Li ; i)rZ   Nzstopping process...z!SIGINT timed out after %r secondsz+process has not terminated, sending SIGKILLzprocess stoppedz#process already dead, exit code: %d)r_   r`   popis_aliver7   r   killr}   signalSIGINTjoinrh   TimeoutExpiredrg   exitcodeSIGKILL)r~   r   r   s   &&&r/   r:   CombinedProcess.stopC  s    


+T2==??LL./GGDHHfmm,		.) }}$LM&..1		/*./NN@$--P ,,  BNS	s   <D+ ++EEc                    < V ^8  d   QhRS[ /# r!   r%   )r+   )r.   rx   s   "r/   r0   ry   [  s     * *$ *r1   c                    \        V P                  \        4      '       d   V P                  P                  4       # V P                  P	                  4       R J # N)ra   r|   r   r   pollr~   s   &r/   r   CombinedProcess.is_alive[  s;    dgg|,,77##%%77<<>T))r1   c                    < V ^8  d   QhRS[ /# r   r   )r.   rx   s   "r/   r0   ry   b  s      S r1   c                .    V P                   P                  # r   r{   r   s   &r/   r}   CombinedProcess.pida  s     ww{{r1   c                $   < V ^8  d   QhRS[ RR/# )r!   timeoutr%   Nr   )r.   rx   s   "r/   r0   ry   f  s     " "C "D "r1   c                    \        V P                  \        4      '       d   V P                  P                  V4       R # V P                  P	                  V4       R # r   )ra   r|   r   r   wait)r~   r   s   &&r/   r   CombinedProcess.joinf  s3    dgg|,,GGLL!GGLL!r1   c                .   < V ^8  d   QhRS[ R,          /# r!   r%   Nr   )r.   rx   s   "r/   r0   ry   m  s     & &#* &r1   c                    \        V P                  \        4      '       d   V P                  P                  # V P                  P                  # r   )ra   r|   r   r   
returncoder   s   &r/   r   CombinedProcess.exitcodel  s3    dgg|,,77###77%%%r1   )r|   N)      )__name__
__module____qualname____firstlineno__r   r:   r   propertyr}   r   r   __static_attributes____classdictcell__)rx   s   @r/   rX   rX   >  sW     ? ?Q Q0* *  " " & &r1   rX   c          
          V ^8  d   QhR\         R\         R,          R\        \        R3,          R\        \         \        3,          RR/# )r!   r[   tty_pathNr   .r   r%   )r'   r(   r   r)   )r.   s   "r/   r0   r0   t  sI      3 #* E#s(O UYZ]_bZbUc hl r1   c                     \        V4      ;_uu_ 4        \        V 4      pV! V/ VB  R R R 4       R #   + '       g   i     R # ; ir   )set_ttyimport_string)r[   r   r   r   funcs   &&&& r/   rc   rc   t  s3    			X&df 
			s	   2A	c                0    V ^8  d   QhR\         R\        /# )r!   dotted_pathr%   )r'   r   )r.   s   "r/   r0   r0   z  s     g gs gs gr1   c                
    V P                  R4      P                  R^4      w  r\	        T4      p \        YB4      #   \         d   p\        RT  R24      ThRp?ii ; i  \         d   p\        RT RT R24      ThRp?ii ; i)	z
Stolen approximately from django. Import a dotted module path and return the attribute/class designated by the
last name in the path. Raise ImportError if the import fails.
 ."z!" doesn't look like a module pathNzModule "z" does not define a "z" attribute)striprsplit
ValueErrorImportErrorr   getattrAttributeError)r   module_path
class_nameemodules   &    r/   r   r   z  s    
V"-"3"3C"8"?"?Q"G ;'Fgv**  VAk]*LMNTUUV  gH[M1FzlR]^_effgs,   #< 
A AAAB*A==Bc                2    V ^8  d   QhR\         R,          /# r   )r'   )r.   s   "r/   r0   r0     s      cDj r1   c                      \         P                  ! \        P                  P	                  4       4      #   \
         d     R# \         d     R# i ; i)zf
Return the path to the current TTY, if any.

Virtually impossible to test in pytest, hence no cover.
z/dev/ttyN)r_   ttynamesysstdinfilenoOSErrorr   rw   r1   r/   rb   rb     s@    zz#))**,--  s   14 AAAAc                L    V ^8  d   QhR\         R,          R\        R,          /# )r!   r   Nr%   )NNN)r'   r   )r.   s   "r/   r0   r0     s$      cDj Y/?%@ r1   c              #      "   V '       d/    \        V 4      ;_uu_ 4       pV\        n        R x  R R R 4       R # R x  R #   + '       g   i     R # ; i  \         d	    R x   R # i ; i5ir   )openr   r   r   )r   ttys   & r/   r   r     sJ     	h3	   	    		sG   	A)A ?A A)A	
A A)A A&"A)%A&&A)c                4    V ^8  d   QhR\         R\        RR/# )r!   signum_framer%   N)r-   r   )r.   s   "r/   r0   r0     s!      S # $ r1   c                 b    \         P                  R \        P                  ! V 4      4       \        h)z-received signal %s, raising KeyboardInterrupt)r7   rg   r   SignalsKeyboardInterrupt)r   r   s   &&r/   raise_keyboard_interruptr     s!    
NNBFNNSYDZ[
r1   c                    V ^8  d   QhRR/# r   rw   )r.   s   "r/   r0   r0     s     < <t <r1   c                     \         P                  R\        P                  ! 4       4       \        P                  ! \        P
                  \        4       R# )a  
Catch SIGTERM and raise KeyboardInterrupt instead. This means watchfiles will stop quickly
on `docker compose stop` and other cases where SIGTERM is sent.

Without this the watchfiles process will be killed while a running process will continue uninterrupted.
z8registering handler for SIGTERM on watchfiles process %dN)r7   r   r_   getpidr   SIGTERMr   rw   r1   r/   r8   r8     s,     LLKRYY[Y
MM&..":;r1   )r>   rG   r6   r   rw   r   )3
contextlibr\   loggingr_   rs   rS   r   rh   r   collections.abcr   r   	importlibr   multiprocessingr   multiprocessing.contextr   pathlibr   timer	   typingr
   r   rB   filtersr   mainr   r   r   r   r   __all__	getLoggerr7   r>   rG   rd   rU   r9   r6   rX   rc   r   rb   contextmanagerr   r   r8   rw   r1   r/   <module>r      s      	 	    
 / # ' 0   %  " 3 3
N			,	-} } %)	}
 =C} :>} :G} } } } } } } } &+}@M M %)	M
 =CM 9=M :GM M M M M M &+Md G$)!$H@3& 3&lg"   
<r1   