B
    \7                 @   sX  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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Z.e/eZ0e01e i Z2dd Z3e3dddd e3dddd e3d d!d"d# e3d$d%d&d' e3d(d)d*d+ e Z4de4j5_6d,e4j_7d-e4j$_8d.e4j5_9d.e4j5_:d.e4j5_;d/e4j5_<d0e4j5_=e4d1fe2d2< d3d4d5iid6fe2d4< d3d7d5iid8fe2d9< e01e2 e/eZ>e>1e  G d:d; d;eZ?G d<d3 d3eeZ@d@d=d>ZAe@jBZCeDd?krTeC  dS )Azl
The :class:`~IPython.core.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)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   ZauthorZauthor_emailsuperr   __init__)selfappZcontact_nameZcontact_emailZbug_tracker)	__class__ 5lib/python3.7/site-packages/IPython/terminal/ipapp.pyr   B   s
    
zIPAppCrashHandler.__init__c                s   | j }tt| |g}|j}yJ||d  x| jjjd D ]}|| q<W |d || jjjd  W n   Y nX 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_sepZreportZrpt_addline)r"   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   s    r6   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_exitzSet 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_interactzIf 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 k	r| j  S t| j d S )N)subappstartprintipython_dir)r    r#   r#   r$   r>      s    

zLocateIPythonApp.startN)r.   r/   r0   descriptiondictsubcommandsr>   r#   r#   r#   r$   r;      s   r;   c                   sR  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ddddZedddejfddZded< ee 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$d4 fd(d)	Z%e&d5 fd*d+	Z'd,d- Z(d.d/ Z)d0d1 Z*d2d3 Z+  Z,S )6r7   Zipythonz\Class to use to instantiate the TerminalInteractiveShell object. Useful for custom Frontends)klassZdefault_valuehelpT)configclassesc          
   C   s   t | j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    r#   r#   r$   _classes_default   s    z#TerminalIPythonApp._classes_default)z*qtconsole.qtconsoleapp.JupyterQtConsoleAppzKDEPRECATED, Will be removed in IPython 6.0 : Launch the Jupyter Qt Console.)z notebook.notebookapp.NotebookAppzUDEPRECATED, Will be removed in IPython 6.0 : Launch the Jupyter HTML Notebook Server.)z)jupyter_console.app.ZMQTerminalIPythonAppzWDEPRECATED, Will be removed in IPython 6.0 : Launch the Jupyter terminal-based Console.)z#nbconvert.nbconvertapp.NbConvertAppzUDEPRECATED, Will be removed in IPython 6.0 : Convert notebooks to/from other formats.)znbformat.sign.TrustNotebookAppzoDEPRECATED, Will be removed in IPython 6.0 : Sign notebooks to trust their potentially unsafe contents at load.)z*jupyter_client.kernelspecapp.KernelSpecAppzRDEPRECATED, Will be removed in IPython 6.0 : Manage Jupyter kernel specifications.)Z	qtconsoleZnotebookZconsoleZ	nbconvertZtrustZ
kernelspec)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.)r<   ZkernelZlocatehistory)z+notebook.nbextensions.InstallNBExtensionAppzUDEPRECATED, Will be removed in IPython 6.0 : Install Jupyter notebook extension fileszinstall-nbextensionFz>Start IPython quickly by skipping the loading of config files.)rE   r8   c             C   s   |d rdd | _ d S )Nnewc              _   s   d S )Nr#   )akwr#   r#   r$   r6     s    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.zIf 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.r9   c             C   s   |d rd| _ d S )NrJ   T)interact)r    rN   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 )NrJ   TF)something_to_runr9   rP   )r    rN   rJ   r#   r#   r$   _file_to_run_changed  s
    
z'TerminalIPythonApp._file_to_run_changedNc                sZ   |dkrt jdd n|}d|krJ|dd }|d}td d||< tt| |S )z<override to allow old '-pylab' flag with deprecation warningNr   z-pylabz^`-pylab` flag has been deprecated.
    Use `--matplotlib <backend>` and import pylab manually.z--pylab)sysargvindexwarningswarnr   r7   parse_command_line)r    rV   idx)r"   r#   r$   rZ   !  s    

z%TerminalIPythonApp.parse_command_linec                sj   t t| | | jdk	rdS | jr6| js6| jd | _|   |   | 	  | 
  |   |   dS )z8Do actions after construct, but before starting the app.Nr   )r   r7   
initializer=   Z
extra_argsrS   rR   Z	init_path
init_shellinit_bannerZinit_gui_pylabZinit_extensionsZ	init_code)r    rV   )r"   r#   r$   r\   1  s    
zTerminalIPythonApp.initializec             C   s.   | j j| | j| j| jd| _| jj|  dS )z(initialize the InteractiveShell instance)parentprofile_dirr@   r*   N)interactive_shell_classinstancer`   r@   r*   r)   Zconfigurablesr(   )r    r#   r#   r$   r]   E  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_bannerrP   r)   Zshow_bannerZ	log_levelloggingINFOr?   )r    r#   r#   r$   r^   P  s    
 zTerminalIPythonApp.init_bannerc             C   s   |dkrt d d| _dS )z,Replace --pylab='inline' with --pylab='auto'Zinlinez>'inline' not available as pylab backend, using 'auto' instead.autoN)rX   rY   Zpylab)r    nameoldrJ   r#   r#   r$   _pylab_changedW  s    
z!TerminalIPythonApp._pylab_changedc             C   sT   | j d k	r| j  S | jr2| jd | j  n| jd | jjsPt	d d S )NzStarting IPython's mainloop...zIPython not interactive...r   )
r=   r>   rP   logdebugr)   ZmainloopZlast_execution_succeededrU   exit)r    r#   r#   r$   r>   ^  s    

zTerminalIPythonApp.start)N)N)-r.   r/   r0   rg   r   Zcl_usagerA   r   Zcrash_handler_class	_examplesZexamplesflagsaliasesr   rG   r   objectr   tagra   r   rH   rB   Zdeprecated_subcommandsr;   rC   r4   r   Zauto_creater8   r   rO   rc   r9   rQ   rT   rS   rZ   r   r\   r]   r^   ri   r>   r2   r#   r#   )r"   r$   r7      sb   
	c             C   s<   | dk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pathr+   r7   Zconfig_file_pathsr(   rM   rF   )r@   r`   r!   r#   r#   r$   load_default_configj  s    rt   __main__)N)Er1   rd   rr   rU   rX   Ztraitlets.config.loaderr   Ztraitlets.config.applicationr   r   ZIPython.corer   r   ZIPython.core.completerr   ZIPython.core.crashhandlerr   ZIPython.core.formattersr	   ZIPython.core.historyr
   ZIPython.core.applicationr   r   r   r   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   rm   r   rB   rn   r4   r3   ZaddflagZclassic_configZInteractiveShellZ
cache_sizeZpprintZprompts_classZseparate_inZseparate_outZseparate_out2ZcolorsZxmodero   r;   r7   rt   Zlaunch_instanceZlaunch_new_instancer.   r#   r#   r#   r$   <module>   s   !

	





 8

