B
    kb7                 @   sd  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Z2e23e! 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:< e23e4 e1eZ@e@3e" G d;d< d<eZAG d=d4 d4ee ZBdAd>d?ZCeBjDZEeFd@kr`eE  dS )Bzp
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   ZauthorZauthor_emailsuperr   __init__)selfappZcontact_nameZcontact_emailZbug_tracker)	__class__ 5lib/python3.7/site-packages/IPython/terminal/ipapp.pyr    C   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(   K   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>d       r7   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/   r0   r1   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 )6r9   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	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$   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.)rG   r:   c             C   s   |d rdd | _ d S )Nnewc              _   s   d S )Nr$   )akwr$   r$   r%   r7     r8   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.r;   c             C   s   |d rd| _ d S )NrL   T)interact)r!   rP   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 )NrL   TF)something_to_runr;   rR   )r!   rP   rL   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   r9   parse_command_line)r!   rX   idx)r#   r$   r%   r\   #  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   r9   
initializer?   Z
extra_argsrU   rT   Z	init_path
init_shellinit_bannerZinit_gui_pylabZinit_extensionsZ	init_code)r!   rX   )r#   r$   r%   r^   3  s    
zTerminalIPythonApp.initializec             C   s.   | j j| | j| j| jd| _| jj|  dS )z(initialize the InteractiveShell instance)parentprofile_dirrB   r+   N)interactive_shell_classinstancerb   rB   r+   r*   Zconfigurablesr)   )r!   r$   r$   r%   r_   G  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_bannerrR   r*   Zshow_bannerZ	log_levelloggingINFOrA   )r!   r$   r$   r%   r`   R  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)rZ   r[   Zpylab)r!   nameoldrL   r$   r$   r%   _pylab_changedY  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@   rR   logdebugr*   ZmainloopZlast_execution_succeededrW   exit)r!   r$   r$   r%   r@   `  s    

zTerminalIPythonApp.start)N)N)-r/   r0   r1   ri   r   Zcl_usagerC   r   Zcrash_handler_class	_examplesZexamplesflagsaliasesr   rI   r   objectr   tagrc   r   rJ   rD   Zdeprecated_subcommandsr=   rE   r5   r   Zauto_creater:   r   rQ   re   r;   rS   rV   rU   r\   r   r^   r_   r`   rk   r@   r3   r$   r$   )r#   r%   r9      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,   r9   Zconfig_file_pathsr)   rO   rH   )rB   rb   r"   r$   r$   r%   load_default_configl  s    rv   __main__)N)Gr2   rf   rt   rW   rZ   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.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   ro   r   rD   rp   r5   r4   ZaddflagZclassic_configZInteractiveShellZ
cache_sizeZpprintZprompts_classZseparate_inZseparate_outZseparate_out2ZcolorsZxmoderq   r=   r9   rv   Zlaunch_instanceZlaunch_new_instancer/   r$   r$   r$   r%   <module>   s   !

	





 9

