;i/dZddlmZddlZddlZddlZddlZddlZddlZddl m Z  ddl m Z n #e$re Z YnwxYwddZdd Z dd Zd Zd Zd ZdS)a Magic Reload Library Luke Campagnola 2010 Python reload function that actually works (the way you expect it to) - No re-importing necessary - Modules can be reloaded in any order - Replaces functions and methods with their updated code - Changes instances to use updated classes - Automatically decides which modules to update by comparing file modification times Does NOT: - re-initialize exting instances, even if __init__ changes - update references to any module-level objects ie, this does not reload correctly: from module import someObject print someObject ..but you can use this instead: (this works even for the builtin reload) import module print module.someObject )print_functionN)printExc)reloadFc 6g}g}i}ttjD]-\}}t j|sd||< |dkrd||<,t |ddd||<Ctj |j ddvrd d t|j zf||<|3|j dt||krd d |j d |f||<tj |j d dz}||vrtj |s d d|zf||<t |d|dz}tj |sd||<Xtj|jtj|jkrd||<|| t#||d||<#t$$ra} t'd|z||jd dt+jt/| | zf||<Yd} ~ 'd} ~ wwxYwt|d kr%t%dd|z|S)a@Automatically reload all modules whose __file__ begins with *prefix*. Skips reload if the file has not been updated (if .pyc is newer than .py) If *prefix* is None, then all loaded modules are checked. Returns a dictionary {moduleName: (reloaded, reason)} describing actions taken for each module. )Fz not a module__main__)Fzignored __main____file__N)Fzmodule has no __file__r).pyz.pycFz%s not a .py/pyc filezfile z not in prefix rr z.py does not exist: %s __cached__c)Fzcode has no pyc file to compare)Fz"code has not changed since compile)debug)TNz*Error while reloading module %s, skipping zreload failed: %sz!Some modules failed to reload: %sz, )listsysmodulesitemsinspectismodulegetattrospathsplitextr strlenisfilestatst_mtimeappendr Exceptionr__name__ tracebackformat_exception_onlytypejoin) prefixr failedchangedretmodNamemodpypycexcs DC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\pyqtgraph/reload.py reloadAllr.(sFG CS[..00112j2j $$ 2CL  j 6CL  3 D ) ) 1O>OOPPP JsG33 I=AIIc |rtdt|z|j}t ||j}t |dr|||D]~}||}||d}||us|(tj |rP|r5td|j |t|t|fzt|||||_ tj|r=t|||} |r)d} | dkrd| z} td|j d || |rgt!|t"rR|} ||t)| D]} |dF|r6t!|t,r!|||D] } | |vr|| = dS) aaReplacement for the builtin reload function: - Reloads the module as usual - Updates all old functions and class methods to use the new code - Updates all instances of each modified class to use the new class - Can update lists and dicts, but this is disabled by default - Requires that class and function names have not changed z Reloading %s __reload__Nz% Updating class %s.%s (0x%x -> 0x%x)r (and %d previous versions)z Updating function .)printr__dict__copy orig_reloadhasattrr0getrisclassrid updateClass__previous_reload_version__ isfunctionupdateFunction isinstancerrextendrangepopdictupdate)moduler listsdictsoldDictnewDictkoldnewdepthextralijs r-rrns: , ns6{{*+++o""$$GoGv|$$#'"""ajkk!T"" #::  ?3    h=RSUWX[U\U\^`ad^e^e@ffggg S% ( ( (.1C + +   $ $ "3U33E S1999EAEv55QRRR  z#t,,  A JJsOOO1XX      z#t,,  JJsOOO  C<<A;c<|j|_|j|_t|dr |j|_|j|_|g}||vrdS||t|drt |j|||dz|}n|}|dkr||_|S)N __kwdefaultsr=r)rNvisitedr)__code__ __defaults__r8__kwdefaults____doc__rr?r=)rLrMr rNrVmaxDepths r-r?r?s )zI Skipping method update for %s; new class does not have this attribute__func____previous_reload_method__r1rr2z Updating method r=z Adding missing attribute %s)gc get_referrersr@ __class__r4safeStrrr: issubclass __bases__index TypeErrorreprrdirrr>ismethodAttributeErrorr?r8r_setattrr<r=)rLrMr refsrefindnewBasesattroanaofuncnfuncrNrOs r-r<r<s C D""! #s## J (<(< # E4ws||CDDD%% J*S#*>*> J3#-CWCWm))#..=#.#c:S]3q566=RR$,CMM @3FGGG1D4G4GGHHH1DNNBCCC  J9GCLLHIII    EQXY\Q]Q]Q]Q]_fgj_k_k_k_kmtuxmymymymyz { { {  CFF S$    b ! ! FW%5b%9%9 F S$''!   nehllmmm  B B//EB B//EE!!&ueU;;u&BCC:79E4FEqyy = EEeeDEEEC33 0 0 0 sD!! 3 @7$>??? CwsD11 2 2 2s122AC3S%@@@@@AAs8B0E CEA!D55$EA F'4HH&%H&c t|}n_#t$rR t|}n>#t$r1dtt |t |fz}YnwxYwYnwxYw|S)Nz)rrrhrcr"r;)objss r-rcrcsK HH KKK KS AA K K K*gd3ii.@.@"S''-JJAAA KK Hs/ A.-A.8A(%A.'A((A.-A.ct|tstj|rt |ddStj|r|jt |jddSt |jdd}|dS|j}t |d|}t|dr|j }tj |||Stj ||SdS)z\Return the previous version of *obj*, or None if this object has not been reloaded. r=Nr_r^im_class) r@r"rr>rrj__self__r^r8rztypes MethodType)rw oldmethodselfoldfuncclss r-getPreviousVersionr(s#t7 23 7 77s94@@@  #  7 < 3<)EtLL L .JDQQI trs-,&%%%%%   ///////KKKCCCCL2222rFNANANAf   77777s /99