Format: application/x-python-code
⬇ Download File (15.3 KB)
   1  o
   2  
   3  ��hFK�@s�dZddlZddlmZddlZddlZddlZddlm	Z	ddl
   4  mZddlm
   5  Z
   6  ddlmZmZddlmZdd	lmZdd
   7  lmZmZmZmZmZmZmZmZddlmZe e!ej"�e!ej#��Z$iZ%dd
   8  �Z&e&dddd�e&dddd�e&dddd�e&dddd�e&ddd d!�e&d"d#d$d%�e
   9  �Z'd&e'j(_)d&e'j(_*d&e'j(_+e'd'fe%d(<d)d*d+iid,fe%d*<d)d-d+iid.fe%d-<e,d/d0d1d2d3d4d5d6d7d8d9�
  10  Z-d:e-d;<Gd<d=�d=e�Z.Gd>d)�d)e�Z/dS)?z�
  11  A mixin for :class:`~IPython.core.application.Application` classes that
  12  launch InteractiveShell instances, load extensions, etc.
  13  �N)�chain)�boolean_flag)�Configurable)�Config)�SYSTEM_CONFIG_DIRS�ENV_CONFIG_DIRS)�
  14  preserve_keys)�filefind)�Unicode�Instance�List�Bool�CaselessStrEnum�observe�DottedObjectName�	Undefined)�
  15  pt_inputhookscGst�t|��S�N)�shell_flags�updater)�args�r�Kc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/shellapp.py�<lambda>*srZ
  16  autoindentzInteractiveShell.autoindentzTurn on autoindenting.zTurn off autoindenting.Z	automagiczInteractiveShell.automagiczoTurn on the auto calling of magic commands. Type %%magic at the
  17          IPython  prompt  for  more information.z,Turn off the auto calling of magic commands.�pdbzInteractiveShell.pdbz;Enable auto calling the pdb debugger after every exception.z<Disable auto calling the pdb debugger after every exception.�pprintzPlainTextFormatter.pprintz'Enable auto pretty printing of results.z(Disable auto pretty printing of results.z
  18  color-infozInteractiveShell.color_infoa0IPython can display information about objects via a set of functions,
  19      and optionally can use colors for this, syntax highlighting
  20      source code and various other elements. This is on by default, but can cause
  21      problems with some pagers. If you see such problems, you can disable the
  22      colours.z-Disable using colors for info related things.z
  23  ignore-cwdzInteractiveShellApp.ignore_cwdz3Exclude the current working directory from sys.pathz1Include the current working directory in sys.path�z&Eliminate all spacing between prompts.Znosep�InteractiveShellApp�pylab�autoz�Pre-load matplotlib and numpy for interactive use with
  24      the default matplotlib backend. The exact options available
  25      depend on what Matplotlib provides at runtime.�
  26  matplotlibz�Configure matplotlib for interactive use with
  27      the default matplotlib backend. The exact options available
  28      depend on what Matplotlib provides at runtime.zInteractiveShell.autocallzInteractiveShell.colorszInteractiveShell.logfilezInteractiveShell.logappendzInteractiveShellApp.code_to_runz!InteractiveShellApp.module_to_runz$InteractiveShellApp.extra_extensionszInteractiveShellApp.guizInteractiveShellApp.pylabzInteractiveShellApp.matplotlib)
  29  Zautocall�colorsZlogfileZ	logappend�c�m�ext�guirr zInteractiveShell.cache_sizez
  30  cache-sizec	sHeZdZdZefdeejdejdejddf�fdd�
  31  Zd	d
  32  �Z	�Z
  33  S)� MatplotlibBackendCaselessStrEnumaTAn enum of Matplotlib backend strings where the case should be ignored.
  34  
  35      Prior to Matplotlib 3.9.0 the list of valid backends is hardcoded in
  36      pylabtools.backends. After that, Matplotlib manages backends.
  37  
  38      The list of valid backends is determined when it is first needed to avoid
  39      wasting unnecessary initialisation time.
  40      �self�
  41  default_value�kwargs�returnNcst�jdd|i|��dS)Nr(r)�super�__init__)r'r(r)��	__class__rrr,~sz)MatplotlibBackendCaselessStrEnum.__init__cCs8|dkrt�||�durddlm}|�|_t�||�S)N�valuesr)�'_list_matplotlib_backends_and_gui_loops)�object�__getattribute__ZIPython.core.pylabtoolsr0r/)r'�namer0rrrr2�sz1MatplotlibBackendCaselessStrEnum.__getattribute__)�__name__�
  42  __module__�__qualname__�__doc__rr�t�Anyr,r2�
  43  __classcell__rrr-rr&ts�����r&c@s�eZdZdZee�dd�jdd�Zee�dd�jdd�Z	e
  44  ddd�jdd�Zee�d	g�jdd�Ze
  45  dd
  46  d�jdd�Z
  47  ee�dd�jdd�Ze
  48  ddd�jdd�Zed
  49  dd�jdd�Zee�dd�jdd�Zed
  50  dd�jdd�Zed
  51  dd�jdd�Zeedd�e�d�jdd�Zeddd�jdd�Zeddd�jdd�Ze
  52  ddd�jdd�Ze
  53  ddd�jdd�Zeddd�Ze
  54  d�Zee ddd�Z!e"d�dd��Z#dd �Z$d!d"�Z%d#d$�Z&d%d&�Z'd'd(�Z(d)d*�Z)d5d+d,�Z*d-d.�Z+d/d0�Z,d1d2�Z-d3d4�Z.dS)6ra�A Mixin for applications that start InteractiveShell instances.
  55  
  56      Provides configurables for loading extensions and executing files
  57      as part of configuring a Shell environment.
  58  
  59      The following methods should be called by the :meth:`initialize` method
  60      of the subclass:
  61  
  62        - :meth:`init_path`
  63        - :meth:`init_shell` (to be implemented by the subclass)
  64        - :meth:`init_gui_pylab`
  65        - :meth:`init_extensions`
  66        - :meth:`init_code`
  67      z<A list of dotted module names of IPython extensions to load.)�helpT)�configz�
  68          Dotted module name(s) of one or more IPython extensions to load.
  69  
  70          For specifying extra extensions to load on the command-line.
  71  
  72          .. versionadded:: 7.10
  73          Fz:Reraise exceptions encountered loading IPython extensions?Z
  74  storemagiczoShould variables loaded at startup (by startup files, exec_lines, etc.)
  75          be hidden from tools like %who?z(List of files to run at IPython startup.z]Run the file referenced by the PYTHONSTARTUP environment
  76          variable at IPython startup.rzA file to be runz(lines of code to run at IPython startup.z!Execute the given command string.zRun the module as a script.z2Enable GUI event loop integration with any of {0}.)�
  77  allow_noner;z�Configure matplotlib for interactive use with
  78          the default matplotlib backend. The exact options available
  79          depend on what Matplotlib provides at runtime.z�Pre-load matplotlib and numpy for interactive use,
  80          selecting a particular matplotlib backend and loop integration.
  81          The exact options available depend on what Matplotlib provides at runtime.
  82          z�If true, IPython will populate the user namespace with numpy, pylab, etc.
  83          and an ``import *`` is done from numpy and pylab, when using pylab mode.
  84  
  85          When False, pylab mode should not import any names into the user namespace.
  86          z�If True, IPython will not add the current working directory to sys.path.
  87          When False, the current working directory is added to sys.path, allowing imports
  88          of modules defined in the current directory.z1IPython.core.interactiveshell.InteractiveShellABC)r=N)rr=�user_nscCs(|jdur|d|j_|j��dSdS)N�new)�shellr>Zinit_user_ns)r'Zchangerrr�_user_ns_changed�s
  89  �z$InteractiveShellApp._user_ns_changedcCsZdtjvs|jr
  90  dSttj�D]\}}tj�|�\}}|dvr!nqd}tj�|d�dS)a�Add current working directory, '', to sys.path
  91  
  92          Unlike Python's default, we insert before the first `site-packages`
  93          or `dist-packages` directory,
  94          so that it is after the standard library.
  95  
  96          .. versionchanged:: 7.2
  97              Try to insert after the standard library, instead of first.
  98          .. versionchanged:: 8.0
  99              Allow optionally not including the current directory in sys.path
 100          rN>z
 101  dist-packagesz
 102  site-packagesr)�sys�path�
 103  ignore_cwd�	enumerate�os�split�insert)r'�idxrC�parentZ	last_partrrr�	init_path�s�zInteractiveShellApp.init_pathcCstd��)NzOverride in subclasses)�NotImplementedError�r'rrr�
 104  init_shellszInteractiveShellApp.init_shellcsd}�j��jr��fdd�}�j}n�jr�j}�j}n	�jr&�j}�j}|s*dSz||�}Wn)tyE�j�d��j�	�YdSt
 105  yY�j�d��j�	�YdSwt|t�r}|dd�\}}�j�
 106  d||�|d	kr{td
 107  |�dSdS|}�j�
 108  d|�dS)z=Enable GUI event loop integration, taking pylab into account.Fcs�j|�jd�S)N)Z
 109  import_all)Zenable_pylab�pylab_import_all)�key�r'r@rrrsz4InteractiveShellApp.init_gui_pylab.<locals>.<lambda>NzDEventloop or matplotlib integration failed. Is matplotlib installed?z-GUI event loop or pylab initialization failed�z@Enabling GUI event loop integration, eventloop=%s, matplotlib=%srzUsing matplotlib backend: %sz1Enabling GUI event loop integration, eventloop=%s)r@rr Zenable_matplotlibr%Z
 110  enable_gui�ImportError�log�warning�
 111  showtraceback�	Exception�
 112  isinstance�tuple�info�print)r'�enablerP�rr%�backendrrQr�init_gui_pylabsH
 113  
 114  �
 115  ���z"InteractiveShellApp.init_gui_pylabcCs�zA|j�d�|j|j|j}|D],}z|j�d|�|jj�|�Wq|j	r,�dj
 116  ||jjd�}|jj
 117  |dd�YqWdS|j	rI�|jj
 118  ddd�YdS)	z�Load all IPython extensions in IPythonApp.extensions.
 119  
 120          This uses the :meth:`ExtensionManager.load_extensions` to load all
 121          the extensions listed in ``self.extensions``.
 122          zLoading IPython extensions...zLoading IPython extension: %szGError in loading extension: {ext}
 123  Check your config files in {location})r$�locationT)�exc_infoz$Unknown error in loading extensions:N)rT�debug�default_extensions�
 124  extensions�extra_extensionsrZr@Zextension_managerZload_extension�"reraise_ipython_extension_failures�format�profile_dirr`rU)r'rdr$�msgrrr�init_extensions8s,���
 125  z#InteractiveShellApp.init_extensionscCsj|��|��|��|jr|jj�|jj�|��|�	�t
 126  j��t
 127  j
 128  ��tt
 129  j���|j_dS)z1run the pre-flight code, specified via exec_linesN)�_run_startup_files�_run_exec_lines�_run_exec_files�hide_initial_nsr@Zuser_ns_hiddenrr>�_run_cmd_line_code�_run_modulerB�stdout�flush�stderr�set�modules�keysZ_sys_modules_keysrMrrr�	init_codeUs
 130  
 131  zInteractiveShellApp.init_codecCs�|jsdSz3|j�d�|jD]&}z|j�d|�|jj|dd�Wq|j�d|�|j��YqWdS|j�d�|j��YdS)zCRun lines of code in IPythonApp.exec_lines in the user's namespace.Nz*Running code from IPythonApp.exec_lines...z"Running code in user namespace: %sF�Z
 132  store_history�-Error in executing line in user namespace: %sz0Unknown error in handling IPythonApp.exec_lines:)�
 133  exec_linesrTrbrZr@�run_cellrUrV)r'�linerrrrlis&
 134  ���	z#InteractiveShellApp._run_exec_linescCsz
 135  t|d|jg�}Wnty|j�d|�YdSwtj}|g|jdd�t_z\tj	�
 136  |�r||j�d|�t|j
 137  jd��-||j
 138  jd<|�d�sR|�d�r[|j
 139  j||d�n|j
 140  j||j
 141  j|d	d
 142  �Wd�n1sqwYW|t_dSW|t_dSW|t_dS|t_w)N�.zFile not found: %r�z"Running file in user namespace: %s�__file__z.ipyz.ipynb��
 143  shell_futuresT)r�Zraise_exceptions)r	Zipython_dir�IOErrorrTrUrB�argv�
 144  extra_argsrFrC�isfilerZrr@r>�endswithZsafe_execfile_ipyZ
 145  safe_execfile)r'�fnamer�Z
 146  full_filename�	save_argvrrr�
 147  _exec_file|s>������
 148  �
 149  �zInteractiveShellApp._exec_filecCs,|jjgdd�ttt�D�}g}|jrHtj�dd�rH|j	sH|j
 150  sH|jsHtjd}|j�
 151  d|�z|�|�Wn|j�d|�|j��Y|ddd�D]}|t�tj�|d	��7}|t�tj�|d
 152  ��7}qO|sndS|j�
 153  d|�zt|�D]}|�|�qzWdS|j�d�|j��YdS)
 154  z(Run files from profile startup directorycSsg|]	}tj�|d��qS)Zstartup)rFrC�join)�.0�prrr�
 155  <listcomp>�s�z:InteractiveShellApp._run_startup_files.<locals>.<listcomp>Z
 156  PYTHONSTARTUPFz Running PYTHONSTARTUP file %s...z0Unknown error in handling PYTHONSTARTUP file %s:N�����z*.pyz*.ipyz Running startup files from %s...z(Unknown error in handling startup files:)rh�startup_dirrrr�exec_PYTHONSTARTUPrF�environ�get�file_to_run�code_to_run�
 157  module_to_runrTrbr�rUr@rV�globrCr��sorted)r'Zstartup_dirsZ
 158  startup_filesZpython_startupr�r�rrrrk�s>����
 159  �z&InteractiveShellApp._run_startup_filescCsV|jsdS|j�d�z|jD]}|�|�qWdS|j�d�|j��YdS)z$Run files from IPythonApp.exec_filesNz)Running files in IPythonApp.exec_files...z0Unknown error in handling IPythonApp.exec_files:)�
 160  exec_filesrTrbr�rUr@rV)r'r�rrrrm�s
 161  �z#InteractiveShellApp._run_exec_filescCs
 162  |jr8|j}z|j�d|�|jj|dd�Wd
 163  S|j�d|�|j��|js5|�d�Yd
 164  SYd
 165  S|j	r�|j	}t
 166  j�|�rKt
 167  j�
 168  |d�}t
 169  j�|�s`|j�d|�|js`|�d�z
 170  |j|d	d
 171  �Wd
 172  S|jjdd�|js�|�d�Yd
 173  SYd
 174  Sd
 175  S)z.Run code or file specified at the command-linez+Running code given at command line (c=): %sFrxryr~z__main__.pyzFile '%s' doesn't existrRTr��)�	tb_offsetN)r�rTrZr@r{rUrV�interact�exitr�rFrC�isdirr��existsr�)r'r|r�rrrro�s>��
 176  �
 177  ��z&InteractiveShellApp._run_cmd_line_codecCsJ|jr#tj}tjg|jt_z|j�|j|jj�W|t_dS|t_wdS)z)Run module specified at the command-line.N)r�rBr��
 178  executabler�r@Zsafe_run_moduler>)r'r�rrrrp�s
 179  ��zInteractiveShellApp._run_module)F)/r4r5r6r7rr
 180  �tagrdrrer
 181  rfrcrnr�r�r�rzr�r�r�gui_keysrgr%r&r rrOrDrr@r��dictr>rrArKrNr_rjrwrlr�rkrmrorprrrrr�s����	������������������������
 182  '
 183  
 184  )0r7r��	itertoolsrrFrB�typingr8Ztraitlets.config.applicationrZtraitlets.config.configurablerZtraitlets.config.loaderrZIPython.core.applicationrrZIPython.utils.contextsrZIPython.utils.pathr	Z	traitletsr
 185  rrr
 186  rrrrZIPython.terminalrrYr��backends�aliasesr�rZaddflagZnosep_configZInteractiveShellZseparate_inZseparate_outZ
 187  separate_out2r�Z
 188  shell_aliasesr&rrrrr�<module>s�(
 189  ������
 190  �
 191  ��