wL i$dZddlZddlmZddlZddlZddlmZddl m Z ddlZejZ edZ dZdZiad Zd Zd Zdd Ziad Zej.Zgej2ddddddfdZy)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_ d|t_y#|t_wxYww)N) builtin_mod __import__) new_import saved_imports \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/IPython/lib/deepreload.pyreplace_import_hookr (s1))L'K. !-  s?/ ? <?c|}|rt|tsy|jdd}|9t|ds t dt |dk(r|dkDr t dy|}nSd|vry|d}d |vr|x|d<}n=|j d }|dcxkr|kr t d|dkrd|d<y|d|x|d<}t |}t|d d D]} |jd d|}|d|} tj|} | |fS#t$r} t d | d} ~ wwxYw#t$r2} |d krtd|zd} ntd|z| Yd} ~ | |fSd} ~ wwxYw)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-1sJ  7D1kk-.Gw)<= = w<1 qy !KLL W $*%  ,3 3GM "TmmC(G"U" !KLL#{)- &,3HW,= =GM "T d)C 5!R / /++c1c*C/ :D GT" 4<) /'(-. / / G >  ! "F8:>?@EF G  4<Gs0D-D! D DD! E*%EEc*t|dk(r|d|fS|jd}|dk(r td|dkr|}d}n |d|}||dzd}|dk7r|dz }||z }t|||}|||k7rt|||}||}|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 4yA~D#~ ))C.C ax,-- Qwt*CEF| by s 7NC c7C 0F ~#-!&'7;  C ~2T9:: 4 c~|tvr'|tjvrtj|}|Std|dt|<tjj |d} |t j |}nt j||}t|||||S#|r|tj|<xYw)z,m = import_submodule(mod, subname, fullname) ReloadingrN) found_nowrrprintr importlibreload import_module add_submodule)r3r6fullnamemoldms r r1r1s9S[[!8 KK !& H# k8$ ({{x. $$T*++GS9 c1h0 H (, H% s &.B$$B<cN|y|tj|}t|||y)zmod.{subname} = submodN)rrsetattr)r3submodrCr6s r rBrBs, { ~X& C&! r:ct|dsy|D]a}t|ds td|dk(r#|r" |j}t|||d}|r@yt||rOt |||dz|zcy#t$rYpwxYw) 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&@A A 3; kk&c3Q7d# S$c D(8 9:"  s A55 BBct||\}}t||dkrdn|||\}}}|}|rt||||\}}}|r| td|s|St|||d|S)zReplacement for __import__()rNr/)r-r9rrM) r&r"localsrOr#r,r5headtails r deep_import_hookrXsWe,KFC vtSQOD$ D #D$c:dC   |,--  D(C+ Kr:c|tur|St|ts td|j}|t j vrtd|z t|S#|t|<YnxYw tj|}n#|t j |<xYw tj|S#tjwxYw)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  Ez a $:;; ::D 3;;FMNN$ &&$"#$"" D  ! K !s*A A)-BB3BB33C rzos.pathbuiltins__main__numpyznumpy._globalsc|D] }dt|<  tt5t|cdddiaS#1swYiayxYw#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@sZ& !  !1 2 ,#F+ , ,  , B s$A 8 AAAAA )NNNr)__doc__r_r contextlibrr?rrZrwarningsrroriginal_importr r-r9r=r1rBrMrXr[r^r@original_reloadbuiltin_module_namesr:r rms6%  ((..GR$P   :  :*,@""   ! !                r: