L i,UddlmZddlZddlZddlmZmZmZmZddl m Z m Z ddl m Z ddlmZddlmZmZmZerddlmZdd lmZdd lmZe eZd ed <Gd deZdaded<GddZddZ ddZ!y)) annotationsN) TYPE_CHECKINGAnyFinal NamedTuple)config file_util) get_logger)FolderBlackList)NoOpPathWatcherPathWatcherTypeget_default_path_watcher_class)Callable) ModuleType) PagesManagerr_LOGGERc"eZdZUded<ded<y) WatchedModulerwatcher str | None module_nameN)__name__ __module__ __qualname____annotations__m/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/watcher/local_sources_watcher.pyrr's LrrzPathWatcherType | None PathWatcherceZdZdZddZddZddZddZddZ d ddZ ddZ dd Z dd Z dd Z dd Zdd Zy)LocalSourcesWatcheraKWatch local Python sources and pages to trigger app reruns. Purpose ------- This watcher powers Streamlit's core developer workflow: save a Python file and the app reruns. It tracks Python modules, the main script directory, and configured watch folders to notify the runtime when a relevant file changes. c||_tjj|jj|_t jd|_tjj|j |_ g|_ d|_ t|_tt jd|_i|_t|_|j'y)Nzserver.folderWatchListFzserver.folderWatchBlacklist)_pages_managerospathrealpathmain_script_path_main_script_pathr get_option_watch_foldersdirname_script_folder_on_path_changed _is_closedset_cached_sys_modulesr _folder_black_list_watched_modules_watched_pagesupdate_watched_pages)self pages_managers r__init__zLocalSourcesWatcher.__init__;s+!#!1!1$2E2E2V2V!W$//0HI ggood.D.DE=?-0U #2   ; <# ;=(+ !!#rc|jj}t}|jj j D]]}|ds t jj|d}|j|||jvsK|j|d_|jD]}t jj|stjd|9tjd|t jj|}||jvs}|j|dd|D]S}||vst jj!|r(|j#||jj%|U|jj'||_y)N script_path)rz#Watch folder is not a directory: %szRegistering watch folder: %sT)r is_directory)r3copyr/r# get_pagesvaluesr$r%r&add_register_watcherr*isdirrwarningdebugisfile_deregister_watcherremoveunion)r5old_page_pathsnew_pages_paths page_info page_path watch_folderwatch_folder_path old_page_paths rr4z(LocalSourcesWatcher.update_watched_pagesNs,,113$'E,,668??A I]+((=)ABI    * 3 33&& $' !// L77==. E|T MM8, G " 0 0 >  (;(;;&&% $!%' , :MO3BGGNN=((7##**=9  :#1177Hrc:|jj|yN)r-append)r5cbs rregister_file_change_callbackz1LocalSourcesWatcher.register_file_change_callbackxs $$R(rctjd|tjj |}||j vr|j D]w}tjj |s#tjj||g|k(sHtjd||jD] }|| ytjd|y|j jD]G}|j|jtjvs-tj|j=I|jD] }|| y)NzPath changed: %sz%File changed in watched directory: %sz'Received event for non-watched path: %s)rrBr$r%r&r2r@ commonpathr-errorr=rsysmodules)r5filepath norm_filepath watched_pathrQwms ron_path_changedz#LocalSourcesWatcher.on_path_changed{s" ((3((2  5 5 5 $ 5 5  GGMM,/**L-+HI#$MM"I8T"33%8 %  MMCX N ''..0 0B~~)bnn .KKK/ 0'' B xL rc|jjD]}|jji|_t |_d|_y)NT)r2r=rcloser/r3r.)r5r[s rr^zLocalSourcesWatcher.closesI''..0 B JJ     "!erct tattury |rdnd}tt||j|d|}||j |<y#t $r"}tjd||Yd}~yd}~wwxYw)Nz**/*F) glob_patternallow_nonexistent)rrzFailed to watch file %s: %sexc_info) rrr rr\r2 ExceptionrrA)r5rXrr:r`r[exs rr?z%LocalSourcesWatcher._register_watchers  8:K / )  %16tL#((!-&+  (B/1D ! !( +  OO98bO Q   s9A B"A??Bc||jvry||jk(ry|j|}|jj|j|=yrO)r2r(rr^)r5rXr[s rrDz'LocalSourcesWatcher._deregister_watchersR 400 0  t-- -   " "8 ,   ! !( +rc||jvSrO)r2r5rXs r _file_is_newz LocalSourcesWatcher._file_is_newst4444rc|j|xr7tj||jxstj|SrO)rir file_is_in_folder_globr,file_in_pythonpathrhs r_file_should_be_watchedz+LocalSourcesWatcher._file_should_be_watchedsC  *  , ,Xt7J7J K 6++H5 rc z|jryttj|jk7rt tjj Dcic] \}}||jt|"}}}ttj|_|j|yycc}}wrO) r.r/rVrWr0dictitems_exclude_blacklisted_pathsget_module_paths_register_necessary_watchers)r5namemodule modules_pathss rupdate_watched_modulesz*LocalSourcesWatcher.update_watched_moduless ??  s{{ t77 7%)$5$;$;$= D&d556Fv6NOOM(+3;;'7D $  - -m < 8s%B7c|jD]M\}}|D]C}|j|s|jtjj ||EOyrO)rprmr?r$r%r&)r5 module_pathsrtpathsr%s rrsz0LocalSourcesWatcher._register_necessary_watcherss^'--/ IKD% I//5**277+;+;D+A4H I Ircd|Dchc] }|jj|r|"c}Scc}wrO)r1is_blacklisted)r5rzps rrqz.LocalSourcesWatcher._exclude_blacklisted_pathss) Ra(?(?(N(Nq(QRRRs --N)r6rreturnNone)r~r)rQzCallable[[str], None]r~r)rXstrr~r)F)rXrrrr:boolr~r)rXrr~r)ryzdict[str, set[str]]r~r)rzset[str]r~r)rrr__doc__r7r4rRr\r^r?rDrirmrwrsrqrrrr!r!1so$&(IT)$LLQ*4DH < ,5  =I Srr!c pdddg}t}|D]^}g} ||}|j |Dcgc]6}t|stjjt|8c}`|S#t$rY`t$r%tj d|j dYwxYwcc}w)Nc8t|dr |jgSgS)N__file__)hasattrrms rz"get_module_paths..s'!Z"81::,brcdt|dr#|j|jjgSgS)N__spec__)rroriginrs rrz"get_module_paths..s1 1j !ajj&<::$$% rct|drWt|jjdk(r5t|jdrt |jj SgS)N__path___NamespacePath_path)rtyperrlistrrs rrz"get_module_paths..sT 1j !   % %)9 9 AJJ ( qzz''(  rz Examining the path of %s raised:Trb) r/AttributeErrorrdrrArupdate_is_valid_pathr$r%r&r)rupaths_extractors all_paths extract_pathspotential_pathsr}s rrrrrs A  -H>I)  +F3O /> T!.QRBSRWW  c!f % T       OO2FOOd    Us"A8B3 *B3 8 B0*B0/B0ct|txr@tjj |xstjj |SrO) isinstancerr$r%rCr@)r%s rrr$s3 dC RbggnnT&:&QbggmmD>QRr)rurr~r)r%rr~r)" __future__rr$rVtypingrrrr streamlitrr streamlit.loggerr #streamlit.watcher.folder_black_listr streamlit.watcher.path_watcherr r rcollections.abcrtypesrstreamlit.runtime.pages_managerrrrrrrr!rrrrrrrsz# 88''? ( <H%%J'+ #*}S}S@0fSr