o
    Zh*                     @   s   d Z ddlZddlmZ ddlZddlZddlmZ ddl	Z	ddl
mZ ddlmZmZ ejd dkZe	jd dkZdd	 Zd
d Zdd Zdd Zdd ZedkrWe  dS dS )z4
File used to start kernels for the IPython Console
    N)DottedObjectName)is_module_installed)MPL_BACKENDS_FROM_SPYDERINLINE_FIGURE_FORMATS26c                  C   sz   t t} t | }t |d}dtjv r tjd dtjv st| ddl	}z	tj| W dS  t
y<   Y dS w )z*Import our customizations into the kernel.Z	customize r   N)ospdirname__file__joinsyspathremovesite
addsitedirspydercustomize
ValueError)hereparentZcustomize_dirr    r   S/var/www/html/lang_env/lib/python3.10/site-packages/spyder_kernels/console/start.pyimport_spydercustomize    s   




r   c                 C   s   | durd | }|S d}|S )zSympy configurationNzK
from sympy.interactive import init_session
init_session()
%matplotlib {0}
z;
from sympy.interactive import init_session
init_session()
)format)mpl_backendlinesr   r   r   sympy_config8   s   r   c                  C   sr  ddl m}  ddlm}m} zt|  d}|ddg|}W n   | }Y | }tj	ddk}|r7d	|j
_d
|j_tj	ddk}tsI||j_d}|g|j_tsY|jjd tjdd dkri|jjd tj	d}	|	dur|j jdd |	dD 7  _|jjd |jjd ddddddd|j_d}
tdr8tj	d}tj	d }|dkr!|dur!t| }
|
d!kr tj	d"}t}|dur|| |j_tj	d#}|durt||jjd$< ttj	d%}ttj	d&}|dur|dur||f|jjd'< tj	d(}|dkrd)nd}|jjd*|i nd!}
tj	d+dk}d,}|jj| |
| tj	d-dk}|rOtd.rO|jjd/ tj	d0}tj	d1}|dkro|durot!|ro||j_"tj	d2}|durt#||j$_%d3|j$_&tj	d4dk}||j_'tj	d5dk}|rtd6rt(|
}|jj| tsd	|j_)|*| |S )7z3Create a config object with IPython kernel options.r   )get_ipython_dir)Configload_pyconfig_filesZprofile_defaultzipython_config.pyzipython_kernel_config.pyZSPY_TESTINGTrueFZPlainZ
SPY_JEDI_Oz$import sys; sys.argv = ['']; del syszfimport builtins; builtins.runfile = builtins.spyder_runfile; del builtins.spyder_runfile; del builtins   )      zLimport sys; import pdb; sys.breakpointhook = pdb.set_trace; del sys; del pdbZSPY_RUN_LINES_ONc                 S   s   g | ]}|  qS r   )strip).0xr   r   r   
<listcomp>   s    z!kernel_config.<locals>.<listcomp>;z-get_ipython().kernel._load_autoreload_magic()z&get_ipython().kernel._load_wurlitzer())g      @g      @H   
   g      ?white)figure.figsize
figure.dpiz	font.sizezfigure.subplot.bottomzfigure.facecolorzfigure.edgecolorZ
matplotlibZSPY_PYLAB_OZSPY_BACKEND_OinlineZSPY_FORMAT_OZSPY_RESOLUTION_Or-   ZSPY_WIDTH_OZSPY_HEIGHT_Or,   ZSPY_BBOX_INCHES_OZtightbbox_inchesZSPY_AUTOLOAD_PYLAB_Oz1get_ipython().kernel._set_mpl_backend('{0}', {1})ZSPY_RUN_CYTHONCythonz%reload_ext CythonZSPY_USE_FILE_OZSPY_RUN_FILE_OZSPY_AUTOCALL_Or   ZSPY_GREEDY_OZSPY_SYMPY_OZsympy)+ZIPython.core.applicationr   Ztraitlets.config.loaderr   r   r	   r   osenvirongetZHistoryAccessorenabledZInteractiveShellZxmodePY2ZIPCompleterZuse_jediIPKernelAppZ
exec_linesappendr   version_infosplitZInlineBackendrcr   r   r   Zfigure_formatfloatZprint_figure_kwargsupdater   existsZfile_to_runintZMQInteractiveShellZautocallZbanner1Zgreedyr   Zcapture_fd_output_merge)r   r   r   Zprofile_pathcfgZspy_cfgZtestingZjedi_oZ
clear_argvZrun_lines_or   Zpylab_oZ	backend_oZformat_oformatsZresolution_oZwidth_oZheight_oZbbox_inches_or/   Zautoload_pylab_ocommandZ
run_cythonZ
use_file_oZ
run_file_oZ
autocall_oZgreedy_oZsympy_or   r   r   r   kernel_configI   s   
	





rD   c                 C   sl   t  }|  \}}zddlm} W n
   ddlm} Y |  t||dd |j |  |	  dS )z
    Spyder's variable explorer magic

    Used to generate plots, histograms and images of the variables displayed
    on it.
    r   Nr!   )
get_ipythonr9   Zguiqwt.pyplotpyplotZmatplotlib.pyplotZfiguregetattrkernelZ_get_current_namespaceshow)lineipfuncnamenamerF   r   r   r   varexp   s    rN   c                  C   s   zt jtt W n	 ty   Y nw zt d W n	 t	y&   Y nw d} d}t
  dt jv r>t jd dt jv s3ddlm} ddlm} G dd d|}| }||_zt |_W n   Y |  |jt dd l}|j|jj_|  d S )	Nr   r   __main__r   )r6   )SpyderKernelc                   @   s    e Zd Zer
edZdd ZdS )zmain.<locals>.SpyderKernelAppz-spyder_kernels.console.outstream.TTYOutStreamc                 S   s   dS )a  
            This method was added in IPykernel 5.3.1 and it replaces
            the debugger used by the kernel with a new class
            introduced in IPython 7.15 during kernel's initialization.
            Therefore, it doesn't allow us to use our debugger.
            Nr   )selfr   r   r   init_pdb/  s   z&main.<locals>.SpyderKernelApp.init_pdbN)__name__
__module____qualname__IPYKERNEL_6r   Zoutstream_classrR   r   r   r   r   SpyderKernelApp)  s    rW   )r   r   r   r	   r
   r   r   localspopKeyErrorr   Zipykernel.kernelappr6   Zspyder_kernels.console.kernelrP   instanceZkernel_classrD   configZ
initializeshellZregister_magic_functionrN   pdbZPdbZInteractiveTBZdebugger_clsstart)__doc__rS   r6   rP   rW   rH   r^   r   r   r   main  s<   

ra   rO   )r`   r1   Zos.pathr   r	   r   r   Z	traitletsr   Z	ipykernelZspyder_kernels.utils.miscr   Zspyder_kernels.utils.mplr   r   versionr5   __version__rV   r   r   rD   rN   ra   rS   r   r   r   r   <module>   s(    3A
