a
    ø£Be*0  ã                   @   sT  d Z ddlZddlZddlZddlZddlmZ ddlmZm	Z	 ddl
mZ ddl
mZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZmZmZ ddlmZ ddlmZmZ ddlm Z m!Z!m"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z*m+Z+m,Z,m-Z-m.Z. dZ/G dd„ deƒZ0e1eƒZ2e2 3e!¡ i Z4dd„ Z5e5ddddƒ e5dddd ƒ e5d!d"d#d$ƒ e5d%d&d'd(ƒ e5d)d*d+d,ƒ eƒ Z6de6j7_8d-e6j_9d.e6j&_:d/e6j7_;d/e6j7_<d/e6j7_=d0e6j7_>d1e6j7_?e6d2fe4d3< d4d5d6iid7fe4d5< d4d8d6iid9fe4d:< e2 3e4¡ e1eƒZ@e@ 3e"¡ G d;d<„ d<eƒZAG d=d4„ d4ee ƒZBd@d>d?„ZCeBjDZEdS )Azp
The :class:`~traitlets.config.application.Application` object for the command
line :command:`ipython` program.
é    N)ÚConfig)Úboolean_flagÚcatch_config_error)Úrelease)Úusage)ÚIPCompleter)ÚCrashHandler)ÚPlainTextFormatter)ÚHistoryManager)Ú
ProfileDirÚBaseIPythonApplicationÚ
base_flagsÚbase_aliases)ÚMagicsManager)ÚScriptMagicsÚLoggingMagics)ÚInteractiveShellAppÚshell_flagsÚshell_aliases)ÚStoreMagicsé   )ÚTerminalInteractiveShell)Úget_ipython_dir)ÚBoolÚListÚdefaultÚobserveÚTypea  
ipython --matplotlib       # enable matplotlib integration
ipython --matplotlib=qt    # enable matplotlib integration with qt4 backend

ipython --log-level=DEBUG  # set logging to DEBUG
ipython --profile=foo      # start with profile foo

ipython profile create foo # create profile foo w/ default config files
ipython help profile       # show the help for the profile subcmd

ipython locate             # print the path to the IPython directory
ipython locate profile foo # print the path to the directory for profile `foo`
c                       s,   e Zd ZdZ‡ fdd„Z‡ fdd„Z‡  ZS )ÚIPAppCrashHandlerzDsys.excepthook for IPython itself, leaves a detailed report on disk.c                    s*   t j}t j}d}tt| ƒ ||||¡ d S )Nz)https://github.com/ipython/ipython/issues)r   ÚauthorÚauthor_emailÚsuperr   Ú__init__)ÚselfÚappZcontact_nameÚcontact_emailZbug_tracker©Ú	__class__© úY/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/IPython/terminal/ipapp.pyr"   B   s    
ÿzIPAppCrashHandler.__init__c                    s|   | j }tt| ƒ |¡g}|j}zF||d ƒ | jjjd D ]}||ƒ q:|dƒ || jjjd ƒ W n   Y n0 d 	|¡S )z*Return a string containing a crash report.zHistory of session input:Z_ihz7
*** Last line of input (may not be in above history):
Ú
Ú )
Zsection_sepr!   r   Úmake_reportÚappendr$   ÚshellÚuser_nsZ_last_input_lineÚjoin)r#   Ú	tracebackZsec_sepÚreportZrpt_addÚliner&   r(   r)   r,   J   s    
zIPAppCrashHandler.make_report)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r"   r,   Ú__classcell__r(   r(   r&   r)   r   ?   s   r   c                  G   s   t  t| Ž ¡S ©N)Úfrontend_flagsÚupdater   )Úargsr(   r(   r)   Ú<lambda>c   ó    r=   zautoedit-syntaxz(TerminalInteractiveShell.autoedit_syntaxz1Turn on auto editing of files with syntax errors.z2Turn off auto editing of files with syntax errors.zsimple-promptz&TerminalInteractiveShell.simple_promptz-Force simple minimal prompt using `raw_input`z1Use a rich interactive prompt with prompt_toolkitZbannerz!TerminalIPythonApp.display_bannerz'Display a banner upon starting IPython.z-Don't display a banner upon starting IPython.zconfirm-exitz%TerminalInteractiveShell.confirm_exitzÂSet to confirm when you try to exit IPython with an EOF (Control-D
    in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
    you can force a direct exit without any confirmation.z#Don't prompt the user when exiting.z
term-titlez#TerminalInteractiveShell.term_titlez'Enable auto setting the terminal title.z(Disable auto setting the terminal title.Fz'IPython.terminal.prompts.ClassicPromptsr+   ZNoColorZPlainz:Gives IPython a similar feel to the classic Python prompt.ZclassicÚTerminalIPythonAppÚquickTz*Enable quick startup with no config files.Úforce_interactz¬If running code from the command line, become interactive afterwards.
    It is often useful to follow this with `--` to treat remaining flags as
    script arguments.
    Úic                   @   s"   e Zd ZdZedd�Zdd„ ZdS )ÚLocateIPythonAppz!print the path to the IPython dir)z%IPython.core.profileapp.ProfileLocatez.print the path to an IPython profile directory)Úprofilec                 C   s"   | j d ur| j  ¡ S t| jƒ d S r9   )ÚsubappÚstartÚprintÚipython_dir©r#   r(   r(   r)   rF   ¬   s    

zLocateIPythonApp.startN)r4   r5   r6   ÚdescriptionÚdictÚsubcommandsrF   r(   r(   r(   r)   rC   ¥   s
   ÿrC   c                       s  e Zd ZdZejZeZe	Z
eZeZeƒ Zeeedd�jdd�Zedƒdd„ ƒZed	d
dejfdd�ZedƒZeddd�jdd�Zedƒdd„ ƒZeddd�jdd�Zeddd�jdd�Zedƒdd„ ƒZ edddƒdd„ ƒZ!edƒZ"e#d)‡ fdd „	ƒZ$d!d"„ Z%d#d$„ Z&d%d&„ Z'd'd(„ Z(‡  Z)S )*r?   Úipythonz\Class to use to instantiate the TerminalInteractiveShell object. Useful for custom Frontends)ÚklassÚdefault_valueÚhelpT)ÚconfigÚclassesc                 C   s   t | jtttttttt	t
gS )zCThis has to be in a method, for TerminalIPythonApp to be available.)r   r'   r   r
   r   r   r	   r   r   r   r   rI   r(   r(   r)   Ú_classes_defaultÃ   s    õz#TerminalIPythonApp._classes_default)z"IPython.core.profileapp.ProfileAppz#Create and manage IPython profiles.)zipykernel.kernelapp.IPKernelAppz,Start a kernel without an attached frontend.z'IPython.terminal.ipapp.LocateIPythonApp)z"IPython.core.historyapp.HistoryAppz$Manage the IPython history database.)rD   ZkernelZlocateÚhistoryFz>Start IPython quickly by skipping the loading of config files.)rP   r@   c                 C   s   |d rdd„ | _ d S )NÚnewc                  _   s   d S r9   r(   )ÚaÚkwr(   r(   r)   r=   í   r>   z3TerminalIPythonApp._quick_changed.<locals>.<lambda>)Úload_config_file©r#   Úchanger(   r(   r)   Ú_quick_changedê   s    z!TerminalIPythonApp._quick_changedz2Whether to display a banner upon starting IPython.zšIf a command or file is given via the command-line,
        e.g. 'ipython foo.py', start an interactive shell after executing the
        file or command.rA   c                 C   s   |d rd| _ d S )NrU   T)ÚinteractrY   r(   r(   r)   Ú_force_interact_changedú   s    z*TerminalIPythonApp._force_interact_changedÚfile_to_runZcode_to_runZmodule_to_runc                 C   s&   |d }|rd| _ |r"| js"d| _d S )NrU   TF)Úsomething_to_runrA   r\   )r#   rZ   rU   r(   r(   r)   Ú_file_to_run_changedÿ   s
    
z'TerminalIPythonApp._file_to_run_changedNc                    sj   t t| ƒ |¡ | jdurdS | jr6| js6| jd | _|  ¡  |  ¡  |  	¡  |  
¡  |  ¡  |  ¡  dS )z8Do actions after construct, but before starting the app.Nr   )r!   r?   Ú
initializerE   Ú
extra_argsr_   r^   Z	init_pathÚ
init_shellÚinit_bannerZinit_gui_pylabZinit_extensionsZ	init_code)r#   Úargvr&   r(   r)   ra   
  s    
zTerminalIPythonApp.initializec                 C   s.   | j j| | j| j| jd�| _| jj | ¡ dS )z(initialize the InteractiveShell instance)ÚparentÚprofile_dirrH   r/   N)Úinteractive_shell_classÚinstancerg   rH   r/   r.   Zconfigurablesr-   rI   r(   r(   r)   rc     s
    þzTerminalIPythonApp.init_shellc                 C   s,   | j r| jr| j ¡  | jtjkr(tƒ  dS )zoptionally display the bannerN)Údisplay_bannerr\   r.   Zshow_bannerÚ	log_levelÚloggingÚINFOrG   rI   r(   r(   r)   rd   )  s    
zTerminalIPythonApp.init_bannerc                 C   s   |dkrt  d¡ d| _dS )z,Replace --pylab='inline' with --pylab='auto'Úinlinez>'inline' not available as pylab backend, using 'auto' instead.ÚautoN)ÚwarningsÚwarnZpylab)r#   ÚnameÚoldrU   r(   r(   r)   Ú_pylab_changed0  s    
z!TerminalIPythonApp._pylab_changedc                 C   s^   | j d ur| j  ¡ S | jr2| j d¡ | j ¡  n(| j d¡ | j ¡  | jjsZt	 
d¡ d S )NzStarting IPython's mainloop...zIPython not interactive...r   )rE   rF   r\   ÚlogÚdebugr.   ZmainloopZrestore_term_titleZlast_execution_succeededÚsysÚexitrI   r(   r(   r)   rF   7  s    


zTerminalIPythonApp.start)N)*r4   r5   r6   rr   r   Zcl_usagerJ   r   Zcrash_handler_classÚ	_examplesZexamplesÚflagsÚaliasesr   rR   r   Úobjectr   Útagrh   r   rS   rK   rC   rL   r   Zauto_creater@   r   r[   rj   rA   r]   r`   r_   r   ra   rc   rd   rt   rF   r8   r(   r(   r&   r)   r?   ³   sj   ýü
ÿöÿþ
ÿþÿü


c                 C   s<   | du rt ƒ } tj | d¡}tƒ }|j |¡ | ¡  |jS )zhLoad the default config file from the default ipython_dir.

    This is useful for embedded shells.
    NZprofile_default)	r   ÚosÚpathr0   r?   Zconfig_file_pathsr-   rX   rQ   )rH   rg   r$   r(   r(   r)   Úload_default_configD  s    r€   )N)Fr7   rl   r~   rw   rp   Ztraitlets.config.loaderr   Ztraitlets.config.applicationr   r   ZIPython.corer   r   ZIPython.core.completerr   ZIPython.core.crashhandlerr   ÚIPython.core.formattersr	   ZIPython.core.historyr
   ZIPython.core.applicationr   r   r   r   ZIPython.core.magicr   ZIPython.core.magicsr   r   ZIPython.core.shellappr   r   r   ZIPython.extensions.storemagicr   Zinteractiveshellr   ZIPython.pathsr   Z	traitletsr   r   r   r   r   ry   r   rK   rz   r;   r:   ZaddflagZclassic_configZInteractiveShellZ
cache_sizeÚpprintZprompts_classZseparate_inZseparate_outZseparate_out2ÚcolorsZxmoder{   rC   r?   r€   Zlaunch_instanceZlaunch_new_instancer(   r(   r(   r)   Ú<module>   s�   	!
þþþüþþ
þ
þ

 
