Format: application/x-python-code
⬇ Download File (6.2 KB)
   1  o
   2  
   3  ��h�$�@s�dZddlZddlmZddlZddlZddlmZddl	m
   4  Z
   5  ddlZejZedd��Z
   6  dd	�Zd
   7  d�Ziadd
   8  �Zdd�Zdd�Zddd�Ziadd�ZejZgej�d�d�d�d�d�d�Rfdd�ZdS) a�
   9  Provides a reload() function that acts recursively.
  10  
  11  Python's normal :func:`python:reload` function only reloads the module that it's
  12  passed. The :func:`reload` function in this module also reloads everything
  13  imported from that module, which is useful when you're changing files deep
  14  inside a package.
  15  
  16  To use this as your default reload function, type this::
  17  
  18      import builtins
  19      from IPython.lib import deepreload
  20      builtins.reload = deepreload.reload
  21  
  22  A reference to the original :func:`python:reload` is stored in this module as
  23  :data:`original_reload`, so you can restore it later.
  24  
  25  This code is almost entirely based on knee.py, which is a Python
  26  re-implementation of hierarchical module import.
  27  �N)�contextmanager)�
  28  ModuleType)�warnccs*�tj}|t_z	dVW|t_dS|t_w)N)�builtin_mod�
  29  __import__)Z
  30  new_importZsaved_import�r�Lc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/lib/deepreload.py�replace_import_hook(s�r	cCs�|}|r	t|t�sdS|�dd�}|dur1t|d�std��t|�dkr.|dkr,td��dS|}n<d|vr7dS|d}d	|vrF||d<}n'|�d
  31  �}|dkrX|krYtd��|dkrcd|d<dS|d|�|d<}t|�}t|dd�D]}z	|�d
  32  d|�}Wqwty�}	ztd
  33  �|	�d}	~	ww|d|�}z
  34  t	j
  35  |}
  36  W|
  37  |fSty�}	z|dkr�td|�d}
  38  nt
  39  d|�|	�WYd}	~	|
  40  |fSd}	~	ww)a�
  41      parent, name = get_parent(globals, level)
  42  
  43      Return the package that an import is being performed in.  If globals comes
  44      from the module foo.bar.bat (not itself a package), this returns the
  45      sys.modules entry for foo.bar.  If globals is from a package's __init__.py,
  46      the package's entry in sys.modules is returned.
  47  
  48      If globals doesn't come from a package or a module in a package, or a
  49      corresponding entry is not found in sys.modules, None is returned.
  50      )N��__package__N�rindexz__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)�
  51  isinstance�dict�get�hasattr�
  52  ValueError�len�rfind�ranger�sys�modules�
  53  BaseExceptionr�SystemError)�globals�levelZ
  54  orig_levelZpkgname�name�modnameZlastdot�dot�x�e�parentrrr�
  55  get_parent1sl
  56  
  57  ��������
  58  �	��r&cCs�t|�dkr|d|fS|�d�}|dkrtd��|dkr!|}d}n|d|�}||dd�}|dkr7|d7}||7}t|||�}|durU||krUt|||�}|durU|}|dur_td|��|||fS)zf
  59      mod, name, buf = load_next(mod, altmod, name, buf)
  60  
  61      altmod is either None or same as mod
  62      rNr�Empty module namerr
  63  zNo module named %.200s)r�findr�import_submodule�ImportError)�modZaltmodr �bufr"�subname�next�resultrrr�	load_nextzs*
  64  
  65  
  66  r0cCs�|tvr|tjvrtj|}|Std|�dt|<tj�|d�}z|dur+t�|�}nt�||�}Wn|r=|tj|<�t||||�|S)z,m = import_submodule(mod, subname, fullname)Z	ReloadingrN)	�	found_nowrr�printr�	importlib�reload�
  67  import_module�
  68  add_submodule)r+r-�fullname�mZoldmrrrr)�s"
  69  
  70  ��
  71  r)cCs.|durdS|durtj|}t|||�dS)zmod.{subname} = submodN)rr�setattr)r+Zsubmodr7r-rrrr6�s
  72  r6c	Cs�t|d�sdS|D]=}t|d�std��|dkr7|rq	z|j}Wn	ty)Yq	wt|||d�}|s6dSq	t||�sFt|||d|�q	dS)	z,Handle 'from module import a, b, c' imports.rNrz"Item in ``from list'' not a string�*rrr)r�	TypeError�__all__�AttributeError�ensure_fromlistr))r+�fromlistr,�	recursive�item�all�retrrrr>�s*
  73  
  74  
  75  ��
  76  ��r>rc	Csxt||�\}}t||dkrdn|||�\}}}|}|r't||||�\}}}|s|dur/td��|s3|St|||d�|S)zReplacement for __import__()rNr')r&r0rr>)	r r�localsr?rr%r,�head�tailrrr�deep_import_hook�s �rGcCs�|tur|St|t�std��|j}|tjvrtd|��zt|WS|t|<Yzzt	�
  77  |�}Wn	|tj|<�Wt��|St��w)zReplacement for reload().z reload() argument must be modulez*reload(): module %.200s not in sys.modules)�typesrrr;r
  78  rrr*�modules_reloadingr3r4�clear)r8r Znewmrrr�deep_reload_hook�s(
  79  
  80  
  81  
  82  
  83  �
  84  �rKrzos.path�builtins�__main__�numpyznumpy._globalscCsZ|D]}dt|<qz tt��t|�Wd�WiaS1s wYWiadSiaw)aMRecursively reload all modules used in the given module.  Optionally
  85      takes a list of modules to exclude from reloading.  The default exclude
  86      list contains modules listed in sys.builtin_module_names with additional
  87      sys, os.path, builtins and __main__, to prevent, e.g., resetting
  88      display, exception, and io hooks.
  89      rN)r1r	rGrK)�module�exclude�irrrr4s
  90  
  91  ��r4)NNNr)�__doc__rLr�
  92  contextlibrr3rrHr�warningsrrZoriginal_importr	r&r0r1r)r6r>rGrIrKr4Zoriginal_reload�builtin_module_namesrrrr�<module>sJ
  93  I(
  94   ��������