a
    ø£BeÛ  ã                   @   sÈ   U d Z ddl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mZmZmZ ddlmZ ddlmZ dd	lmZ d
dddœZeed< ddddiidfiZeed< G dd„ deƒZejZdS )znbclient cli.é    N)Údedent)Ú
JupyterApp)ÚBoolÚIntegerÚListÚUnicodeÚdefault)Úcatch_config_error)Ú__version__é   )ÚNotebookClientzNbClientApp.timeoutzNbClientApp.startup_timeoutzNbClientApp.kernel_name)ÚtimeoutÚstartup_timeoutÚkernel_nameÚnbclient_aliaseszallow-errorsÚNbClientAppÚallow_errorsTzLErrors are ignored and execution is continued until the end of the notebook.Únbclient_flagsc                       s  e Zd ZU dZeeƒZdZeZ	e
ZdZeg dd�jdd�Zedded	ƒd
�jdd�Zeed< ededƒd�jdd�Zeed< ededƒd�jdd�Zeed< ededƒd�jdd�Zeed< ededƒd�jdd�Zeed< edƒdd„ ƒZed!‡ fdd„	ƒZdd„ Z dd „ Z!‡  Z"S )"r   zE
    An application used to execute notebook files (``*.ipynb``)
    zjupyter-executez7An application used to execute notebook files (*.ipynb)zPath of notebooks to convert)ÚhelpT)ÚconfigNzÈ
            The time to wait (in seconds) for output from executions.
            If a cell execution takes longer, a TimeoutError is raised.
            ``-1`` will disable the timeout.
            )Ú
allow_noner   r   é<   z¢
            The time to wait (in seconds) for the kernel to start.
            If kernel startup takes longer, a RuntimeError is
            raised.
            r   FaB  
            When a cell raises an error the default behavior is that
            execution is stopped and a :py:class:`nbclient.exceptions.CellExecutionError`
            is raised.
            If this flag is provided, errors are ignored and execution
            is continued until the end of the notebook.
            r   zskip-executionz^
            Name of the cell tag to use to denote a cell that should be skipped.
            Úskip_cells_with_tagÚ z‹
            Name of kernel to use to execute the cells.
            If not set, use the kernel_spec embedded in the notebook.
            r   Ú	log_levelc                 C   s   t jS )N)ÚloggingÚINFO©Úself© r   úO/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/nbclient/cli.pyÚ_log_level_defaulta   s    zNbClientApp._log_level_defaultc                    s>   t ƒ  |¡ ˆ  ¡ ˆ _ˆ js&t d¡ ‡ fdd„ˆ jD ƒ dS )zInitialize the app.éÿÿÿÿc                    s   g | ]}ˆ   |¡‘qS r   )Úrun_notebook)Ú.0Úpathr   r   r    Ú
<listcomp>r   ó    z*NbClientApp.initialize.<locals>.<listcomp>N)ÚsuperÚ
initializeÚget_notebooksÚ	notebooksÚsysÚexit)r   Úargv©Ú	__class__r   r    r)   e   s
    

zNbClientApp.initializec                 C   s   | j r| j }n| j}|S )zGet the notebooks for the app.)Ú
extra_argsr+   )r   r+   r   r   r    r*   t   s    zNbClientApp.get_notebooksc              
   C   s¢   | j  d|› �¡ | dd¡}t |¡j ¡ }|› d�}t|ƒ�}tj	|dd�}W d  ƒ n1 sd0    Y  t
|| j| j| j| j| jdd|iid	�}| ¡  dS )
zRun a notebook by path.z
Executing z.ipynbr   é   )Z
as_versionNÚmetadatar%   )r   r   r   r   r   Ú	resources)ÚlogÚinfoÚreplaceÚpathlibÚPathÚparentÚabsoluteÚopenÚnbformatÚreadr   r   r   r   r   r   Úexecute)r   Znotebook_pathÚnamer%   Z
input_pathÚfÚnbÚclientr   r   r    r#   €   s     

,
ùzNbClientApp.run_notebook)N)#Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r
   Úversionr@   r   Úaliasesr   ÚflagsÚdescriptionr   Útagr+   r   r   r   ÚintÚ__annotations__r   r   r   Úboolr   Ústrr   r   r!   r	   r)   r*   r#   Ú__classcell__r   r   r/   r    r   "   sl   
ÿý
öÿþ	÷
ÿþõÿþùÿþø

)rG   r   r8   r,   Útextwrapr   r=   Zjupyter_core.applicationr   Z	traitletsr   r   r   r   r   Ztraitlets.configr	   Znbclientr
   rC   r   r   ÚdictrN   r   r   Zlaunch_instanceÚmainr   r   r   r    Ú<module>   s0   ýÿÿúÿ~