o
    tf}                     @  s   U d Z ddlmZ ddlZddlZddlZddlm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dZded< dddiidfdddiidfdZded< G dd deZejZdS )znbclient cli.    )annotationsN)Path)dedent)
JupyterApp)BoolIntegerListUnicodedefault)catch_config_error)__version__   )NotebookClientzNbClientApp.timeoutzNbClientApp.startup_timeoutzNbClientApp.kernel_namezNbClientApp.output_base)timeoutstartup_timeoutkernel_nameoutputzdict[str, str]nbclient_aliasesNbClientAppallow_errorsTzLErrors are ignored and execution is continued until the end of the notebook.inplacez/Overwrite input notebook with executed results.)zallow-errorsr   zdict[str, typing.Any]nbclient_flagsc                      s(  e Zd ZdZeeZdZeZ	e
ZdZee ddjddZedded	d
jddZededdjddZededdjddZededdjddZededdjddZededdjddZeddedd
jddZedd&ddZed'd( fddZd)d d!Zd*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   <   z
            The time to wait (in seconds) for the kernel to start.
            If kernel startup takes longer, a RuntimeError is
            raised.
            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.
            zskip-executionz^
            Name of the cell tag to use to denote a cell that should be skipped.
             z
            Name of kernel to use to execute the cells.
            If not set, use the kernel_spec embedded in the notebook.
            z
            Default is execute notebook without writing the newly executed notebook.
            If this flag is provided, the newly generated notebook will
            overwrite the input notebook.
            a8  
            Write executed notebook to this file base name.
            Supports pattern replacements ``'{notebook_name}'``,
            the name of the input notebook file without extension.
            Note that output is always relative to the parent directory of the
            input notebook.
            	log_levelreturnintc                 C  s   t jS N)loggingINFO)self r$   U/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/nbclient/cli.py_log_level_default   s   zNbClientApp._log_level_defaultargvlist[str] | NoneNonec                   sn   t  | |  | _| jstd t| jdkr*| jdur*d| jvr*d}t|| jD ]}| 	| q-dS )zInitialize the app.r   Nz{notebook_name}zgIf passing multiple notebooks with `--output=output` option, output string must contain {notebook_name})
super
initializeget_notebooks	notebookssysexitlenoutput_base
ValueErrorrun_notebook)r#   r'   msgpath	__class__r$   r%   r,      s   



zNbClientApp.initialize	list[str]c                 C  s   | j r| j }|S | j}|S )zGet the notebooks for the app.)
extra_argsr.   )r#   r.   r$   r$   r%   r-      s
   zNbClientApp.get_notebooksnotebook_pathstrc           	   
   C  s  | j d|  t|d}|j }| jr|}n| jr1|j| jj	|dj
dd}nd}|rE|j sEd|j d}t|| }tj|dd	}W d   n1 s[w   Y  t|| j| j| j| j| jd
d|iid}|  |r| j d|  t|| dS dS )zRun a notebook by path.z
Executing z.ipynbr   )Znotebook_nameNzCannot write to directory=z that does not exist   )Z
as_versionmetadatar6   )r   r   skip_cells_with_tagr   r   	resourceszSave executed results to )loginfor   with_suffixparentabsoluter   r2   joinpathformatnameis_dirr3   opennbformatreadr   r   r   r?   r   r   executewrite)	r#   r;   Z
input_pathr6   Zoutput_pathr5   fnbclientr$   r$   r%   r4      s@   


zNbClientApp.run_notebook)r   r   r    )r'   r(   r   r)   )r   r9   )r;   r<   r   r)   )!__name__
__module____qualname____doc__r	   r   versionrH   r   aliasesr   flagsdescriptionr   tagr.   r   r   r   r   r   r   r?   r   r   r2   r
   r&   r   r,   r-   r4   __classcell__r$   r$   r7   r%   r   0   s    
	
		

)rU   
__future__r   r!   r/   typingpathlibr   textwrapr   rK   Zjupyter_core.applicationr   Z	traitletsr   r   r   r	   r
   Ztraitlets.configr   Znbclientr   rQ   r   r   __annotations__r   r   Zlaunch_instancemainr$   r$   r$   r%   <module>   sD    

 
0