
    ^h                        S r SSKJr  SSKrSSKJr  SSKJr  SSKJ	r
  SSKJr  SSKJr  S	S
KJr  S r " S S\\5      rg)zQModule containing a preprocessor that executes the code cells
and updates outputs    )annotationsN)KernelManager)NotebookClient)execute)CellExecutionError)NotebookNode   )Preprocessorc                 <    SSK Jn  U" S[        SS9  [        U 0 UD6$ )zDEPRECATED.r   )warnzThe 'nbconvert.preprocessors.execute.executenb' function was moved to nbclient.execute. We recommend importing that library directly.   )
stacklevel)warningsr   FutureWarning_execute)argskwargsr   s      Y/home/james-whalen/.local/lib/python3.13/site-packages/nbconvert/preprocessors/execute.py	executenbr      s*    	8	 T$V$$    c                  H    \ rS rSrSrS rS r S	       S
S jjrS rSr	g)ExecutePreprocessor&   z&
Executes all the cells in a notebook
c                    UR                  S5      nUc
  [        5       n[        R                  " U 4SU0UD6  [        R                  " X40 UD6  g)zInitialize the preprocessor.nbN)getr   r
   __init__r   )selfkwr   s      r   r   ExecutePreprocessor.__init__+   sF    VVD\:Bd0r0R0/B/r   c                B    U(       d  [        U S5      (       d  Xl        g g )N	resources)hasattrr"   )r   r"   s     r   _check_assign_resources+ExecutePreprocessor._check_assign_resources3   s    GD+66&N 7r   Nc                R   [         R                  " XU5        U R                  5         U R                  U5        U R	                  5          U R
                  (       d   eU R                  U R
                  R                  5       5      nU(       d   eUS   S   U R                  R                  S'   [        U R                  R                  5       H  u  pVU R                  XbU5        M     SSS5        U R                  5         U R                  U R                  4$ ! , (       d  f       N6= f)a  
Preprocess notebook executing each code cell.

The input argument *nb* is modified in-place.

Note that this function recalls NotebookClient.__init__, which may look wrong.
However since the preprocess call acts line an init on execution state it's expected.
Therefore, we need to capture it here again to properly reset because traitlet
assignments are not passed. There is a risk if traitlets apply any side effects for
dual init.
The risk should be manageable, and this approach minimizes side-effects relative
to other alternatives.

One alternative but rejected implementation would be to copy the client's init internals
which has already gotten out of sync with nbclient 0.5 release before nbconvert 6.0 released.

Parameters
----------
nb : NotebookNode
    Notebook being executed.
resources : dictionary (optional)
    Additional resources used in the conversion process. For example,
    passing ``{'metadata': {'path': run_path}}`` sets the
    execution path to ``run_path``.
km: KernelManager (optional)
    Optional kernel manager. If none is provided, a kernel manager will
    be created.

Returns
-------
nb : NotebookNode
    The executed notebook.
resources : dictionary
    Additional resources used in the conversion process.
contentlanguage_infoN)r   r   reset_execution_trackersr$   setup_kernelkcwait_for_replykernel_infor   metadata	enumeratecellspreprocess_cellset_widgets_metadatar"   )r   r   r"   kminfo_msgindexcells          r   
preprocessExecutePreprocessor.preprocess7   s    L 	"-%%'$$Y/ 77N7**477+>+>+@AHO8080CO0TDGG_-(7$$Te<  8 ! 	!!#ww&& ! s   	BD
D&c                ^    U R                  U5        U R                  XSS9nXR                  4$ )a  
Override if you want to apply some preprocessing to each cell.
Must return modified cell and resource dictionary.

Parameters
----------
cell : NotebookNode cell
    Notebook cell being processed
resources : dictionary
    Additional resources used in the conversion process.  Allows
    preprocessors to pass variables into the Jinja engine.
index : int
    Index of the cell being processed
T)store_history)r$   execute_cellr"   )r   r6   r"   r5   s       r   r1   #ExecutePreprocessor.preprocess_celll   s4     	$$Y/  D A^^##r   )r"   )NN)r   r   r"   zt.Anyr3   zKernelManager | Nonereturnz%tuple[NotebookNode, dict[str, t.Any]])
__name__
__module____qualname____firstlineno____doc__r   r$   r7   r1   __static_attributes__ r   r   r   r   &   sC    0'
 UY3'3'+03'=Q3'	.3'j$r   r   )rB   
__future__r   typingtjupyter_client.managerr   nbclient.clientr   r   r   nbclient.exceptionsr   nbformatr   baser
   r   r   rD   r   r   <module>rM      s;    #  0 * / 3 ! 
% W$, W$r   