
    7}en                        d Z ddlmZ ddlZddlZddl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 ddlmZ ddlmZ 	 dd	lmZ n# e$ r d
ZY nw xY wej        j        Zdej        d         z  Z e ee          j        d          Z	 	 	 d-d.dZd/d0dZ	 	 	 d1d2dZdd
eddddfd3d(Z dd)l!m"Z"  G d* d+e"          Z#e$d,k    re#%                                 dS dS )4z#The IPython kernel spec for Jupyter    )annotationsN)Path)Any)KernelSpecManager)Unicode   )_is_debugpy_availableFzpython%i	resourcesipykernel_launchermodstr
executable
str | Noneextra_argumentslist[str] | Nonereturn	list[str]c                b    |t           j        }|pg }|d| ddg}|                    |           |S )a  Build Popen command list for launching an IPython kernel.

    Parameters
    ----------
    mod : str, optional (default 'ipykernel')
        A string of an IPython module whose __main__ starts an IPython kernel
    executable : str, optional (default sys.executable)
        The Python executable to use for the kernel process.
    extra_arguments : list, optional
        A list of extra arguments to pass when executing the launch code.

    Returns
    -------
    A Popen command list
    Nz-mz-fz{connection_file})sysr   extend)r   r   r   	argumentss       4lib/python3.11/site-packages/ipykernel/kernelspec.pymake_ipkernel_cmdr   "   sF    ( ^
%+OT3.ABI_%%%    dict[str, Any]c                `    t          |           dt          j        d         z  ddt          idS )zConstruct dict for kernel.jsonr   zPython %i (ipykernel)r   pythondebugger)argvdisplay_namelanguagemetadata)r   r   version_infor	   r   s    r   get_kernel_dictr%   ?   s=     "/BBB/#2B12EE!67	  r   pathPath | str | None	overridesdict[str, Any] | Nonec                Z   | *t          t          j        d                    t          z  } t	          j        t          |            t          |                                           j        }|t          j	        z  s/t          |           
                    |t          j	        z             t          |          }|r|                    |           t          t          | d          d          5 }t          j        ||d           ddd           n# 1 swxY w Y   t#          |           S )zWrite a kernel spec directory to `path`

    If `path` is not specified, a temporary directory is created.
    If `overrides` is given, the kernelspec JSON is updated before writing.

    The path to the kernelspec is always returned.
    N_kernels)suffixzkernel.jsonwr   )indent)r   tempfilemkdtempKERNEL_NAMEshutilcopytree	RESOURCESstatst_modeS_IWUSRchmodr%   updateopenpjoinjsondumpr   )r&   r(   r   maskkernel_dictfs         r   write_kernel_specrA   I   sC    |H$J77788;F OIt$$$ ::??$D$, .T

,--- "/22K &9%%%	eD-((#	.	. ,!	+q++++, , , , , , , , , , , , , , , t99s   /DDDkernel_spec_managerKernelSpecManager | Noneuserboolkernel_namer!   prefixprofileenvdict[str, str] | Nonec                *   | t                      } |t          k    r||}i }|r||d<   |r!d|g}|sdt          j        d         |fz  |d<   nd}|r||d<   t	          ||          }	|                     |	|||          }
t          j        |	           |
S )	a^  Install the IPython kernelspec for Jupyter

    Parameters
    ----------
    kernel_spec_manager : KernelSpecManager [optional]
        A KernelSpecManager to use for installation.
        If none provided, a default instance will be created.
    user : bool [default: False]
        Whether to do a user-only install, or system-wide.
    kernel_name : str, optional
        Specify a name for the kernelspec.
        This is needed for having multiple IPython kernels for different environments.
    display_name : str, optional
        Specify the display name for the kernelspec
    profile : str, optional
        Specify a custom profile to be loaded by the kernel.
    prefix : str, optional
        Specify an install prefix for the kernelspec.
        This is needed to install into a non-default location, such as a conda/virtual-env.
    env : dict, optional
        A dictionary of extra environment variables for the kernel.
        These will be added to the current environment variables before the
        kernel is started

    Returns
    -------
    The path where the kernelspec was installed.
    Nr!   	--profilezPython %i [profile=%s]r   rI   )r(   r   )rF   rD   rG   )r   r1   r   r$   rA   install_kernel_specr2   rmtree)rB   rD   rF   r!   rG   rH   rI   r(   r   r&   dests              r   installrP   k   s    J "/11{"")= # "I 1$0	.! &0 	b(@CDTUVDWY`Ca(aIn%
 	%y/RRRD22+D 3  D M$Kr   )Applicationc                  :    e Zd ZdZ ed          Zd
ddZdd	ZdS )InstallIPythonKernelSpecAppzDummy app wrapping argparsezipython-kernel-installNr    r   r   Nonec                @    |t           j        dd         }|| _        dS )zInitialize the app.Nr   )r   r    )selfr    s     r   
initializez&InstallIPythonKernelSpecApp.initialize   s!    <8ABB<D			r   c                   ddl }|                    | j        d          }|                    ddd           |                    d	t          t
          d
           |                    dt          d           |                    dt          d           |                    dt          d           |                    ddt          j        ddt          j        z             |                    ddddd           |                    | j	                  }|j
        rt          |j
                  |_
        	 t          |j        |j        |j        |j        |j        |j
                  }nz# t           $ rm}|j        t"          j        k    rRt'          |t          j                   |j        rt'          d t          j                   |                     d!            d}~ww xY wt'          d"|j         d#|            dS )$zStart the app.r   Nz Install the IPython kernel spec.)progdescriptionz--user
store_truez3Install for the current user instead of system-wide)actionhelpz--namezdSpecify a name for the kernelspec. This is needed to have multiple IPython kernels at the same time.)typedefaultr]   z--display-namezdSpecify the display name for the kernelspec. This is helpful when you have multiple IPython kernels.)r^   r]   rL   z]Specify an IPython profile to load. This can be used to create custom versions of the kernel.z--prefixzSpecify an install prefix for the kernelspec. This is needed to install into a non-default location, such as a conda/virtual-env.z--sys-prefixstore_constrG   z[Install to Python's sys.prefix. Shorthand for --prefix='%s'. For use in conda/virtual-envs.)r\   constrO   r]   z--envappend   )ENVVALUEz)Set environment variables for the kernel.)r\   nargsmetavarr]   )rD   rF   rH   rG   r!   rI   )filez$Perhaps you want `sudo` or `--user`?r   zInstalled kernelspec z in )argparseArgumentParsernameadd_argumentr   r1   r   rG   
parse_argsr    rI   dictrP   rD   rH   r!   OSErrorerrnoEACCESprintstderrexit)rV   ri   parseroptsrO   es         r   startz!InstallIPythonKernelSpecApp.start   s{   (((J ) 
 
 	F 	 	
 	
 	

 	Q	 	 	
 	
 	
 	G 	 	
 	
 	
 	H 	 	
 	
 	
 	c 	 	
 	
 	
 	 *KMPZX 	 	
 	
 	
 	$< 	 	
 	
 	
   ++8 	&DH~~DH	Y I{!.H  DD  	 	 	w%,&&acj))))9 S@szRRRR		!	 	;di;;T;;<<<<<s   93E- -
G$7A(GG$N)r    r   r   rT   )r   rT   )__name__
__module____qualname____doc__r   rk   rW   rx    r   r   rS   rS      s]        %%7+,,D    G= G= G= G= G= G=r   rS   __main__)r   NN)r   r   r   r   r   r   r   r   ry   )r   r   r   r   )NNN)r&   r'   r(   r)   r   r   r   r   )rB   rC   rD   rE   rF   r   r!   r   rG   r   rH   r   rI   rJ   r   r   )&r}   
__future__r   rp   r<   osr2   r5   r   r/   pathlibr   typingr   jupyter_client.kernelspecr   	traitletsr   r   r	   ImportErrorr&   joinr;   r$   r1   __file__parentr4   r   r%   rA   rP   traitlets.configrQ   rS   rz   launch_instancer~   r   r   <module>r      s)   ) )
 # " " " " "   				   



              7 7 7 7 7 7      "/////// " " "!" 	3+A.. E$$x..'55	 $!(,    :     #'+(,    F 59"#!%> > > > >F ) ( ( ( ( (R= R= R= R= R=+ R= R= R=j z//11111 s   A AA