Format: application/x-python-code
⬇ Download File (4.7 KB)
   1  o
   2  
   3  ��h��@sndZddlZddlZddlZddlmZmZddlmZddl	m
   4  Z
   5  ddlmZddd�Z
   6  Gd	d
   7  �d
   8  e�ZdS)z(A class for managing IPython extensions.�N)�
   9  import_module�reload)�Configurable)�ensure_dir_exists)�InstanceF)Z
  10  storemagicZ
  11  autoreloadcsveZdZdZeddd�Zd�fdd�	Zdefd	d
  12  �Zdefdd�Z	defd
  13  d�Z
  14  defdd�Zdd�Zdd�Z
  15  �ZS)�ExtensionManagera�A class to manage IPython extensions.
  16  
  17      An IPython extension is an importable Python module that has
  18      a function with the signature::
  19  
  20          def load_ipython_extension(ipython):
  21              # Do things with ipython
  22  
  23      This function is called after your extension is imported and the
  24      currently active :class:`InteractiveShell` instance is passed as
  25      the only argument.  You can do anything you want with IPython at
  26      that point, including defining new magic and aliases, adding new
  27      components, etc.
  28  
  29      You can also optionally define an :func:`unload_ipython_extension(ipython)`
  30      function, which will be called if the user unloads or reloads the extension.
  31      The extension manager will only call :func:`load_ipython_extension` again
  32      if the extension is reloaded.
  33  
  34      You can put your extension modules anywhere you want, as long as
  35      they can be imported by Python's standard import mechanism.
  36      z1IPython.core.interactiveshell.InteractiveShellABCT)�
  37  allow_noneNcs&tt|�jdd|i|��t�|_dS)N�shell�)�superr�__init__�set�loaded)�selfr	�kwargs��	__class__r
  38  �Mc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/extensions.pyr2szExtensionManager.__init__�
  39  module_strcCs@z|�|�WSty|tvrdt|<|�d|�YS�w)aLoad an IPython extension by its module name.
  40  
  41          Returns the string "already loaded" if the extension is already loaded,
  42          "no load function" if the module doesn't have a load_ipython_extension
  43          function, or None if it succeeded.
  44          T�IPython.extensions.)�_load_extension�ModuleNotFoundError�
  45  BUILTINS_EXTS)rrr
  46  r
  47  r�load_extension6s�zExtensionManager.load_extensioncCs�||jvrdS|jdusJ�|jj�,|tjvrt|�}tj|}|�|�r-|j�|�n		Wd�dSWd�dS1sAwYdS)Nzalready loadedzno load function)rr	Zbuiltin_trap�sys�modulesr�_call_load_ipython_extension�add�rr�modr
  48  r
  49  rrEs
  50  
  51  
  52  
  53  
  54  �"�z ExtensionManager._load_extensioncCs\t�|d�durd|}||jvrdS|tjvr,tj|}|�|�r*|j�|�dSdSdS)a{Unload an IPython extension by its module name.
  55  
  56          This function looks up the extension's name in ``sys.modules`` and
  57          simply calls ``mod.unload_ipython_extension(self)``.
  58  
  59          Returns the string "no unload function" if the extension doesn't define
  60          a function to unload itself, "not loaded" if the extension isn't loaded,
  61          otherwise None.
  62          FTrz
  63  not loadedzno unload functionN)r�getrrr�_call_unload_ipython_extension�discardrr
  64  r
  65  r�unload_extensionTs
  66  
  67  
  68  
  69  
  70  �z!ExtensionManager.unload_extensioncCstt�|d�durd|}||jvr3|tjvr3|�|�tj|}t|�|�|�r1|j�|�dSdS|�	|�dS)a4Reload an IPython extension by calling reload.
  71  
  72          If the module has not been loaded before,
  73          :meth:`InteractiveShell.load_extension` is called. Otherwise
  74          :func:`reload` is called and then the :func:`load_ipython_extension`
  75          function of the module, if it exists is called.
  76          FTrN)
  77  rr rrrr#rrrrrr
  78  r
  79  r�reload_extensionjs	
  80  
  81  
  82  �z!ExtensionManager.reload_extensioncC�t|d�r
  83  |�|j�dSdS)N�load_ipython_extensionT)�hasattrr&r	�rrr
  84  r
  85  rr�
  86  �z-ExtensionManager._call_load_ipython_extensioncCr%)N�unload_ipython_extensionT)r'r*r	r(r
  87  r
  88  rr!�r)z/ExtensionManager._call_unload_ipython_extension)N)�__name__�
  89  __module__�__qualname__�__doc__rr	r�strrrr#r$rr!�
  90  __classcell__r
  91  r
  92  rrrsr)r.�osZos.pathr�	importlibrrZtraitlets.config.configurablerZIPython.utils.pathrZ	traitletsrrrr
  93  r
  94  r
  95  r�<module>s
  96