U a~6@s UddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ejejejejhZeedreejeeZ[ejeddd Zejeejedd d d Zejeejeejed ddZejeejeejed ddZejeejedddZej edddZ!GdddZ"Gddde"Z#Gddde"Z$e#e$dZ%ej&eej'e"fe(d<z e)dWn"e*k re%d e%d!<YnXe%d"e%d!<ddd#d$Z+d(ej,gdfej-ejeej-ejeej.e/e0fedd%d&d'Z1dS))N)chain)PurePath)_log real_prefixreturnccs\ttjD]H}t|dd}|dkr(qtj|sP|}tj|}||kr(qq(|VqdS)z;Find the filesystem paths associated with imported modules.__file__N) listsysmodulesvaluesgetattrospathisfiledirname)modulenameoldrSC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-1tps7o9u\werkzeug\_reloader.py_iter_module_pathss   r)pathsexclude_patternsrcCs |D]}|t||qdSN)difference_updatefnmatchfilter)rrpatternrrr_remove_by_pattern.sr ) extra_filesrrc Cst}tttj|D]}tj|}tj|r<||t |D]V\}}}| t sjtj |dkrt| qF|D]"}|drx|tj||qxqFq|tt|||S)axFind paths for the stat reloader to watch. Returns imported module files, Python files under non-system paths. Extra files and Python files under extra directories can also be scanned. System paths have to be excluded for efficiency. Non-system paths, such as a project root or ``sys.path.insert``, should be the paths of interest to the user anyway. >.hg.git __pycache__)z.pyz.pyc)setrr r rrabspathraddwalk startswith_ignore_prefixesbasenameclearendswithjoinupdaterr )r!rrrrootdirsfilesrrrr_find_stat_paths3s       r3cCszt}tttj|D]2}tj|}tj|r>tj|}| |qt D]}| tj|qPt ||t |S)zFind paths for the stat reloader to watch. Looks at the same sources as the stat reloader, but watches everything under directories instead of individual files. ) r%rr r rrr&rrr'rr _find_common_roots)r!rr1rrrr_find_watchdog_paths]s      r5)rrcsi}tdd|DtddD]&}|}|D]}||i}q(|qttjttftj tdfddfdd |d S) Ncss|]}t|jVqdSr)rparts.0xrrr xsz%_find_common_roots..T)keyreverse.)noderrcs<|D]\}}|||fq|s8tjj|dSr)itemsr'rrr.)r=rprefixchild_walkrvrrrBsz!_find_common_roots.._walkr) sortedlen setdefaultr,r%tMappingstrdictTuple)rr0chunksr=chunkrrArr4us , r4cCsrtjg}tjd}tjdd}tjd}t|dddksltjdkr|jdkrtj |stj |drtj |}tjdkrtj |stj |dr|d7}tj tjddkrtj |ddkr| d| |n|tjdd krtj}nftj|rLtt|j}tj tj|d}|dkrP|d |7}n|}|d |d f|||S) zpDetermine how the script was executed, and return the args needed to execute it again in a new process. rrN__main__ __package__ntz.exez-m.)r executableargvr rrrrOrexistsr&splitextpopappendrrGcastrIr+extendlstrip)rCZ py_scriptargsrNZ py_modulerrrr_get_args_for_reloadingsD         r]c@seZdZdZdejejeejejeeje e fddddZ dddd Z d d Z ddd d ZddddZe dddZeddddZeddddZdS) ReloaderLooprQNr)r!rintervalrcCs,dd|p dD|_t|pd|_||_dS)NcSsh|]}tj|qSr)rrr&r7rrr sz(ReloaderLoop.__init__..r)r!r%rr_)selfr!rr_rrr__init__szReloaderLoop.__init__rcCs ||S)zgDo any setup, then run one step of the watch to populate the initial filesystem state. )run_steprarrr __enter__szReloaderLoop.__enter__cCsdS)z4Clean up any resources associated with the reloader.Nrraexc_typeexc_valexc_tbrrr__exit__szReloaderLoop.__exit__cCs|t|jqdS)zfContinually run the watch step, sleeping for the configured interval after each step. N)rctimesleepr_rdrrrrunszReloaderLoop.runcCsdS)z}Run one step for watching the filesystem. Called once to set up initial state, then repeatedly to update it. NrrdrrrrcszReloaderLoop.run_stepcCsLtdd|jt}tj}d|d<tj||dd}|dkr|SqdS) z|Spawn a new Python interpreter with the same arguments as the current one, but running the reloader thread. infoz * Restarting with trueWERKZEUG_RUN_MAINF)env close_fdsN)rrr]renvironcopy subprocesscall)rar\Z new_environZ exit_coderrrrestart_with_reloaders z"ReloaderLoop.restart_with_reloaderfilenamercCs||tddSNrs) log_reloadr exitrarzrrrtrigger_reloads zReloaderLoop.trigger_reloadcCs"tj|}tdd|ddS)Nrnz * Detected change in z , reloading)rrr&rr~rrrr|s zReloaderLoop.log_reload)NNr)__name__ __module__ __qualname__rrGOptionalIterablerIUnionintfloatrbrerjrmrcrxrr|rrrrr^s"  r^cs4eZdZdZedfdd ZddddZZS)StatReloaderLoopstatrcsi|_tSr)mtimessuperrerd __class__rrre szStatReloaderLoop.__enter__Nc Csxtt|j|jD]`}zt|j}Wntk r>YqYnX|j |}|dkr`||j|<q||kr| |qdSr) rr3r!rrrst_mtimeOSErrorrgetr)rarmtimeZold_timerrrrc s   zStatReloaderLoop.run_step)rrrrr^rerc __classcell__rrrrrsrcspeZdZejejddfdd ZeddddZedfd d Z d d Z ddd dZ ddddZ Z S)WatchdogReloaderLoopN)r\kwargsrcsddlm}ddlm}tj|||jGfddd|}|j}| dr`|dd}d|d |_ ||_ d d |j D}|d|d|j d|_d|_dS)Nr)Observer)PatternMatchingEventHandlercseZdZfddZdS)z3WatchdogReloaderLoop.__init__..EventHandlercs|jdSr)Zsrc_path)raeventrrr on_any_event'sz@WatchdogReloaderLoop.__init__..EventHandler.on_any_eventN)rrrrrrrr EventHandler&srobserveriz watchdog ()cSsg|]}tj|s|qSr)rrisdir)r8prrr 6s z1WatchdogReloaderLoop.__init__..*.py*.pyc*.zip*/__pycache__/**/.git/**/.hg/*)patternsignore_patternsF)rrr)rrr)Zwatchdog.observersrZwatchdog.eventsrrrbrrlowerr-rrr!r event_handler should_reload)rar\rrrrZ reloader_nameZextra_patternsrrrrbs*      zWatchdogReloaderLoop.__init__rycCsd|_||dS)NT)rr|r~rrrrBsz#WatchdogReloaderLoop.trigger_reloadrcsi|_|jtSr)watchesrstartrrerdrrrreIs zWatchdogReloaderLoop.__enter__cCs|j|jdSr)rstopr.rfrrrrjNs zWatchdogReloaderLoop.__exit__cCs*|js|t|jqtddSr{)rrcrkrlr_r r}rdrrrrmRszWatchdogReloaderLoop.runc Cst|j}t|j|jD]V}||jkrdz|jj|j|dd|j|<Wntk rbd|j|<YnX| |q|D]&}|j |d}|dk rt|j |qtdS)NT) recursive) r%rr5r!rrschedulerrdiscardrWZ unschedule)raZ to_deleterZwatchrrrrcYs    zWatchdogReloaderLoop.run_step)rrrrGAnyrbrIrr^rerjrmrcrrrrrrs #r)rwatchdogreloader_loopszwatchdog.observersrautorcCs~tjdkstjsdSz ddl}Wntk r:YdSX|tj}|d|j@sz|d|jO<|tj|j|dS)zuEnsure that echo mode is enabled. Some tools such as PDB disable it which causes usability issues after a reload.Nrrs) r stdinisattytermios ImportError tcgetattrECHO tcsetattrZTCSANOW)r attributesrrrensure_echo_on~s  r) main_funcr!rr_ reloader_typerc Csddl}||jddt||||d}z^tjddkrzttj|dd }d |_ || | W5QRXnt |Wntk rYnXdS) zz#run_with_reloader..)r!rr_rpror)targetr\T)signalSIGTERMrrrtrr threadingThreaddaemonrrmr r}rxKeyboardInterrupt)rr!rr_rrZreloaderrGrrrrun_with_reloaders$r)NNrr)2rrrvr rrktypingrG itertoolsrpathlibr _internalrr? base_prefix exec_prefixbase_exec_prefixhasattrr'rtupler*IteratorrIrSetr rr3r5r4Listr]r^rrrDictType__annotations__ __import__rrCallablerrrrrrrrrsf      + <=T