1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
U
Þ=®d™9ã@sÆUddlmZddlZddlZddlZddlZddlZddlZddlZ    ddl
m Z ddl m Z ddlmZeejejhƒZeejejh™Zeedƒr e ej¡eeƒZ[dd    d
d d d dhZddœdd„Zddddœdd„Zddddœdd„Zddddœdd„Zdddœdd „Zd!dœd"d#„Z Gd$d%„d%ƒZ!Gd&d'„d'e!ƒZ"Gd(d)„d)e!ƒZ#e"e#d*œZ$d+e%d,<z e&d-ƒWn"e'k
rŒe$d.e$d/<YnXe$d0e$d/<ddœd1d2„Z(d:d3d4d4d5d6dd7œd8d9„Z)dS);é)Ú annotationsN)Úchain)ÚPurePathé)Ú_logÚ real_prefixÚ __pycache__z.gitz.hgz.toxz.noxz .pytest_cachez .mypy_cachezt.Iterator[str]©Úreturnccsfttj ¡ƒD]R}t|ddƒ}|dks| t¡r2qtj     |¡sZ|}tj 
|¡}||kr2qq2|VqdS)z;Find the filesystem paths associated with imported modules.Ú__file__N) ÚlistÚsysÚmodulesÚvaluesÚgetattrÚ
startswithÚ_ignore_alwaysÚosÚpathÚisfileÚdirname)ÚmoduleÚnameÚold©rúId:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\werkzeug/_reloader.pyÚ_iter_module_paths(s   rzset[str]ÚNone)ÚpathsÚexclude_patternsr
cCs |D]}| t ||¡¡qdS©N)Údifference_updateÚfnmatchÚfilter)rrÚpatternrrrÚ_remove_by_pattern<sr%zt.Iterable[str])Ú extra_filesrr
c
    Csútƒ}tttjƒ|ƒD]È}tj |¡}tj |¡r>| |¡qtj     |¡di}t 
|¡D]„\}}}|  t ¡s|tj  |¡tkr†| ¡qXd}|D]&}    |     d¡rŽd}| tj ||    ¡¡qŽ|sÔ|tj     |¡sÔ| ¡qX|||<qXq| tƒ¡t||ƒ|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.
    TF)z.pyz.pyc)Úsetrr r rrÚabspathrÚaddrÚwalkrÚ_stat_ignore_scanÚbasenameÚ_ignore_common_dirsÚclearÚendswithÚjoinÚupdaterr%)
r&rrrZ parent_has_pyÚrootÚdirsÚfilesZhas_pyrrrrÚ_find_stat_pathsAs4   
ÿþ
 
r5cCsztƒ}tttjƒ|ƒD]2}tj |¡}tj |¡r>tj |¡}|     |¡qt
ƒD]}|     tj |¡¡qPt ||ƒt |ƒS)z­Find 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&rr3rrrrÚ_find_watchdog_pathsws    
 
r7)rr
cspi}tdd„|DƒtddD]&}|}|D]}| |i¡}q(| ¡qtƒ‰ddddœ‡‡fd    d
„ ‰ˆ|d ƒˆS) Ncss|]}t|ƒjVqdSr )rÚparts©Ú.0ÚxrrrÚ    <genexpr>’sz%_find_common_roots.<locals>.<genexpr>T)ÚkeyÚreversezt.Mapping[str, dict]ztuple[str, ...]r)Únoderr
cs<| ¡D]\}}ˆ|||fƒq|s8ˆ tjj|Ž¡dSr )Úitemsr)rrr0)r?rÚprefixÚchild©Ú_walkÚrvrrrDœsz!_find_common_roots.<locals>._walkr)ÚsortedÚlenÚ
setdefaultr.r')rr2Úchunksr?ÚchunkrrCrr6s
 
r6z    list[str]cCsŠtjdkr tjftjdd…•Stjg}tjd}tjdd…}tjd}t|ddƒdks”tjdkr|j    dkrtj
  |¡stj
  |›d    ¡rtj
  |¡}tjdkr
tj
  |¡sÒtj
  |›d    ¡rÒ|d    7}tj
  tj¡dd    kr
tj
  |¡dd    kr
| d¡| |¡nftj
 |¡rdt t|j    ¡}tj
  tj
 |¡¡d}|dkrh|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.
    )éé
rNrÚ__main__Ú __package__ÚntÚz.exeÚ.z-m)r Ú version_infoÚ
executableZ    orig_argvÚargvrrrrrNrÚexistsr(ÚsplitextÚpopÚappendrÚtÚcastÚstrr,ÚextendÚlstrip)rEZ    py_scriptÚargsrMZ    py_modulerrrrÚ_get_args_for_reloading§sD
 
 
ÿþ
ýü  ÿþ
 
 
r_c@s†eZdZdZddddddœdd    „Zdd
œd d „Zd d„Zdd
œdd„Zdd
œdd„Zdd
œdd„Z    dddœdd„Z
dddœdd„Z dS)Ú ReloaderLooprPNrút.Iterable[str] | Noneú int | floatr)r&rÚintervalr
cCs,dd„|p dDƒ|_t|pdƒ|_||_dS)NcSsh|]}tj |¡’qSr)rrr(r9rrrÚ    <setcomp>ësz(ReloaderLoop.__init__.<locals>.<setcomp>r)r&r'rrc)Úselfr&rrcrrrÚ__init__åszReloaderLoop.__init__r    cCs | ¡|S)zgDo any setup, then run one step of the watch to populate the
        initial filesystem state.
        )Úrun_step©rerrrÚ    __enter__ïszReloaderLoop.__enter__cCsdS)z4Clean up any resources associated with the reloader.Nr©reÚexc_typeÚexc_valÚexc_tbrrrÚ__exit__öszReloaderLoop.__exit__cCs| ¡t |j¡qdS)zfContinually run the watch step, sleeping for the configured
        interval after each step.
        N)rgÚtimeÚsleeprcrhrrrÚrunúszReloaderLoop.runcCsdS)z}Run one step for watching the filesystem. Called once to set
        up initial state, then repeatedly to update it.
        NrrhrrrrgszReloaderLoop.run_stepÚintcCsLtdd|j›ƒtƒ}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 ÚtrueÚWERKZEUG_RUN_MAINF)ÚenvÚ    close_fdsrKN)rrr_rÚenvironÚcopyÚ
subprocessÚcall)rer^Z new_environZ    exit_coderrrÚrestart_with_reloaders
z"ReloaderLoop.restart_with_reloaderr[©Úfilenamer
cCs| |¡t d¡dS©NrK)Ú
log_reloadr Úexit©rer~rrrÚtrigger_reloads
zReloaderLoop.trigger_reloadcCs"tj |¡}tdd|›dƒdS)Nrsz * Detected change in z , reloading)rrr(rr‚rrrr€s zReloaderLoop.log_reload)NNr) Ú__name__Ú
__module__Ú __qualname__rrfrirnrqrgr|rƒr€rrrrr`âsü
r`cs4eZdZdZddœ‡fdd„ Zddœdd„Z‡ZS)    ÚStatReloaderLoopÚstatr`r    csi|_tƒ ¡Sr )ÚmtimesÚsuperrirh©Ú    __class__rrri"szStatReloaderLoop.__enter__rc    Cstt|j|jƒD]`}zt |¡j}Wntk
r:YqYnX|j |¡}|dkr\||j|<q||kr|     |¡qdSr )
r5r&rrrˆÚst_mtimeÚOSErrorr‰Úgetrƒ)rerÚmtimeZold_timerrrrg&s
 
zStatReloaderLoop.run_step)r„r…r†rrirgÚ __classcell__rrr‹rr‡sr‡csleZdZddddœ‡fdd„ Zdddœdd    „Zd
d œ‡fd d „ Zdd„Zdd œdd„Zdd œdd„Z‡Z    S)ÚWatchdogReloaderLoopzt.Anyr)r^Úkwargsr
csÎddlm}ddlm}ddlm‰ddlm‰tƒj||Ž|j‰G‡‡‡fdd„d|ƒ}|j     
¡}|  d¡r||dd    …}d
|›d |_ |ƒ|_ d d „|jDƒ}|d|•dd „tDƒ|j•d|_d|_dS)Nr)ÚObserver)ÚPatternMatchingEventHandler)ÚEVENT_TYPE_OPENED)ÚFileModifiedEventcs eZdZddœ‡‡fdd„ ZdS)z3WatchdogReloaderLoop.__init__.<locals>.EventHandlerr—)Úeventcs|jˆkrdSˆ|jƒdSr )Z
event_typeZsrc_path)rer˜)r–rƒrrÚ on_any_eventBs
z@WatchdogReloaderLoop.__init__.<locals>.EventHandler.on_any_eventN)r„r…r†r™r©r–r—rƒrrÚ EventHandlerAsr›Úobserveriøÿÿÿz
watchdog (ú)cSsg|]}tj |¡s|‘qSr)rrÚisdir)r:ÚprrrÚ
<listcomp>Ts z1WatchdogReloaderLoop.__init__.<locals>.<listcomp>ú*.pyú*.pycú*.zipcSsg|]}d|›d‘qS)z*/z/*r)r:Údrrrr Xs)ÚpatternsÚignore_patternsF)r¡r¢r£)Zwatchdog.observersr”Zwatchdog.eventsr•r–r—rŠrfrƒr„Úlowerr/rrœr&r-rÚ event_handlerÚ should_reload)rer^r“r”r•r›Z reloader_nameZextra_patternsr‹ršrrf8s(    
 
  þþzWatchdogReloaderLoop.__init__r[r}cCsd|_| |¡dS)NT)r©r€r‚rrrrƒ^sz#WatchdogReloaderLoop.trigger_reloadr`r    csi|_|j ¡tƒ ¡Sr )ÚwatchesrœÚstartrŠrirhr‹rrries
zWatchdogReloaderLoop.__enter__cCs|j ¡|j ¡dSr )rœÚstopr0rjrrrrnjs
zWatchdogReloaderLoop.__exit__cCs*|js| ¡t |j¡qt d¡dSr)r©rgrorprcr rrhrrrrqnszWatchdogReloaderLoop.runc    Cs t|jƒ}t|j|jƒD]V}||jkrdz|jj|j|dd|j|<Wntk
rbd|j|<YnX|     |¡q|D]&}|j 
|d¡}|dk    rt|j  |¡qtdS)NT)Ú    recursive) r'rªr7r&rrœÚscheduler¨rŽÚdiscardrWZ
unschedule)reZ    to_deleterZwatchrrrrgus 
 
ÿ zWatchdogReloaderLoop.run_step)
r„r…r†rfrƒrirnrqrgr‘rrr‹rr’7s &r’)rˆÚwatchdogzdict[str, type[ReloaderLoop]]Úreloader_loopszwatchdog.observersrˆÚautor°cCs~tjdkstj ¡sdSz 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.NrrK)    r ÚstdinÚisattyÚtermiosÚ ImportErrorÚ    tcgetattrÚECHOÚ    tcsetattrZTCSANOW)rµÚ
attributesrrrÚensure_echo_onšs  r»zt.Callable[[], None]rarbr[)Ú    main_funcr&rrcÚ reloader_typer
c    Cs¤ddl}| |jdd„¡t||||d}z^tj d¡dkrztƒtj|dd    }d
|_    || 
¡|  ¡W5QRXnt   | ¡¡Wntk
ržYnXdS) z<Run the given function in an independent Python interpreter.rNcWs
t d¡S)Nr)r r)r^rrrÚ<lambda>·óz#run_with_reloader.<locals>.<lambda>)r&rrcrurtr)Útargetr^T)ÚsignalÚSIGTERMr±rrxrr»Ú    threadingÚThreadÚdaemonr«rqr rr|ÚKeyboardInterrupt)r¼r&rrcr½rÁZreloaderrYrrrÚrun_with_reloader­s$ÿrÇ)NNrr²)*Ú
__future__rr"rrzr rÃroÚtypingrYÚ    itertoolsrÚpathlibrÚ    _internalrÚtupleÚ base_prefixÚbase_exec_prefixrrAÚ exec_prefixÚhasattrr)rr+r-rr%r5r7r6r_r`r‡r’r±Ú__annotations__Ú
__import__r¶r»rÇrrrrÚ<module>s`    
 ù 6;=Wþ  û