}BFj$dZddlZddlmZddlZddlZddlmZddl m Z ddlZej Z edZ dZdZiad Zd Zd Zdd ZiadZejZgejddddddRfdZdS)a Provides a reload() function that acts recursively. Python's normal :func:`python:reload` function only reloads the module that it's passed. The :func:`reload` function in this module also reloads everything imported from that module, which is useful when you're changing files deep inside a package. To use this as your default reload function, type this:: import builtins from IPython.lib import deepreload builtins.reload = deepreload.reload A reference to the original :func:`python:reload` is stored in this module as :data:`original_reload`, so you can restore it later. This code is almost entirely based on knee.py, which is a Python re-implementation of hierarchical module import. N)contextmanager) ModuleType)warnc#~Ktj}|t_ dV|t_dS#|t_wxYw)N) builtin_mod __import__) new_import saved_imports DC:\PYTHON\_runtimes\venv\Lib\site-packages\IPython/lib/deepreload.pyreplace_import_hookr (sF)L'K. !-  ----s.<c\|}|rt|tsdS|dd}|Lt|dst dt |dkr|dkrt ddS|}njd|vrdS|d}d |vr|x|d<}nP|d }|dcxkr|krnnt d|dkrd|d<dS|d|x|d<}t |}t|d d D]<} |d d|}#t$r} t d | d} ~ wwxYw|d|} tj |} nE#t$r8} |d krtd|zd} ntd|z| Yd} ~ nd} ~ wwxYw| |fS)a parent, name = get_parent(globals, level) Return the package that an import is being performed in. If globals comes from the module foo.bar.bat (not itself a package), this returns the sys.modules entry for foo.bar. If globals is from a package's __init__.py, the package's entry in sys.modules is returned. If globals doesn't come from a package or a module in a package, or a corresponding entry is not found in sys.modules, None is returned. )N __package__Nrindexz__package__ set to non-stringrz(Attempted relative import in non-package__name____path__.z2attempted relative import beyond top-level packagez?Parent module '%.200s' not found while handling absolute importzAParent module '%.200s' not loaded, cannot perform relative import) isinstancedictgethasattr ValueErrorlenrfindrangersysmodules BaseExceptionr SystemError) globalslevel orig_levelpkgnamenamemodnamelastdotdotxeparents r get_parentr-1spJ  7D11xkk-..Gw)) ><== = w<<1  qyy !KLLL8 W $ $8*%  ,3 3GM "TTmmC((G""""U""""" !KLLL{{)- &x,3HWH,= =GM "T d))C 5!R // /++c1c**CC / / /'((-. / / :D GT" GGG >>  ! " " "FF8:>?@@EF G FFFF G 4<s0 D%% E/D??EE%% F'/.F""F'cxt|dkr|d|fS|d}|dkrtd|dkr|}d}n|d|}||dzd}|dkr|dz }||z }t|||}|||krt|||}||}|t d|z|||fS)zf mod, name, buf = load_next(mod, altmod, name, buf) altmod is either None or same as mod rNrEmpty module namerrzNo module named %.200s)rfindrimport_submodule ImportError)modaltmodr&bufr)subnamenextresults r load_nextr9zs 4yyA~~D#~ ))C..C axx,--- Qwwtt*CEFF| byy s 7NC c7C 0 0F ~#--!&'7;;  C ~2T9::: 4 c||tvr!|tjvrtj|}ntd|dt|<tj|d} |t j|}nt j||}n#|r|tj|<xYwt|||||S)z,m = import_submodule(mod, subname, fullname) ReloadingrN) found_nowrrprintr importlibreload import_module add_submodule)r3r6fullnamemoldms r r1r1s9S[!8!8 K ! k8$$$ ({x.. $T**+GS99  -(, H% c1h000 Hs &,BB'cX|dS|tj|}t|||dS)zmod.{subname} = submodN)rrsetattr)r3submodrCr6s r rBrBs4 { ~X& C&!!! Fr:c2t|dsdS|D]}t|dstd|dkr3|r* |j}t|||d}|sdSJ#t$rYVwxYwt||st |||dz|zdS) z,Handle 'from module import a, b, c' imports.rNrz"Item in ``from list'' not a string*rrr)r TypeError__all__ensure_fromlistAttributeErrorr1)r3fromlistr5 recursiveitemallrets r rMrMs 3 # #::tX&& B@AA A 3;;  k&c3Q7711 "     d## : S$c D(8 9 9 9::sA A,+A,rct||\}}t||dkrdn|||\}}}|}|rt||||\}}}||td|s|St|||d|S)zReplacement for __import__()rNr/)r-r9rrM) r&r"localsrOr#r,r5headtails r deep_import_hookrXsWe,,KFC vtSQQOD$ D ;#D$c::dC ;  |,---  D(C+++ Kr:c|tur|St|tstd|j}|t jvrtd|z t|S#|t|<YnxYw tj |}n#|t j|<xYw t n#t wxYw|S)zReplacement for reload().z reload() argument must be modulez*reload(): module %.200s not in sys.modules) typesrrrKrrrr2modules_reloadingr?r@clear)rDr&newms r deep_reload_hookr^s  Ezz a $ $<:;;; :D 3;FMNNN$ &&$"#$""" D  !!!!!!!! Ks* A%% A37B B< BB<<Crzos.pathbuiltins__main__numpyznumpy._globalsc|D] }dt|< tt5t|cdddiaS#1swxYwY iadS#iawxYw)aMRecursively reload all modules used in the given module. Optionally takes a list of modules to exclude from reloading. The default exclude list contains modules listed in sys.builtin_module_names with additional sys, os.path, builtins and __main__, to prevent, e.g., resetting display, exception, and io hooks. rN)r=r rXr^)moduleexcludeis r r@r@s& !  !1 2 2 , ,#F++ , , , , , , ,  , , , , , , , , , B s-AA AAA A AA)NNNr)__doc__r_r contextlibrr?rrZrwarningsrroriginal_importr r-r9r=r1rBrMrXr[r^r@original_reloadbuiltin_module_namesr:r rms6%%%%%%  (...GGGR$$$P     :    :::*,@"   !                 r: