o
    œhP&  ã                   @  s,  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
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 ejjZd	e	jd  Zeeeƒjd
ƒZ				d1d2dd„Z	d3d4dd„Z				d5d6dd„Zdd eddddd fd7d,d-„Z G d.d/„ d/eƒZ!e"d0kr”e! #¡  dS dS )8z#The IPython kernel spec for Jupyteré    )ÚannotationsN)ÚPath)ÚAny)ÚKernelSpecManager)ÚUnicode)ÚApplicationzpython%iÚ	resourcesÚipykernel_launcherÚmodÚstrÚ
executableú
str | NoneÚextra_argumentsúlist[str] | NoneÚpython_argumentsÚreturnú	list[str]c                 C  s<   |du rt j}|p
g }|pg }|g|¢d‘| ‘d‘d‘|¢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   )r
   r   r   r   © r   úJc:\Users\shubh\Videos\agent\nova\Lib\site-packages\ipykernel/kernelspec.pyÚmake_ipkernel_cmd   s
   r   údict[str, Any]c                 C  s$   t | |d�dtjd  dddidœS )zConstruct dict for kernel.json©r   r   zPython %i (ipykernel)r   ÚpythonZdebuggerT)ÚargvÚdisplay_nameÚlanguageÚmetadata)r   r   Úversion_infor   r   r   r   Úget_kernel_dict;   s   ÿúr   ÚpathúPath | str | NoneÚ	overridesúdict[str, Any] | Nonec                 C  sº   | du rt tjdd�ƒt } t t| ¡ t | ƒ ¡ j}|tj	@ s*t | ƒ 
|tj	B ¡ t||ƒ}|r6| |¡ tt| dƒdƒ�}tj||dd� W d  ƒ t| ƒS 1 sTw   Y  t| ƒS )zïWrite 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.
    NZ_kernels)Úsuffixzkernel.jsonÚwé   )Úindent)r   ÚtempfileÚmkdtempÚKERNEL_NAMEÚshutilÚcopytreeÚ	RESOURCESÚstatÚst_modeÚS_IWUSRÚchmodr   ÚupdateÚopenÚpjoinÚjsonÚdumpr   )r    r"   r   r   ÚmaskZkernel_dictÚfr   r   r   Úwrite_kernel_specI   s   



ÿýr9   FÚkernel_spec_managerúKernelSpecManager | NoneÚuserÚboolÚkernel_namer   ÚprefixÚprofileÚenvúdict[str, str] | NoneÚfrozen_modulesc                 C  sÚ   | du rt ƒ } |du ri }|tkr|du r|}i }|r||d< |r3d|g}	|s2dtjd |f |d< nd}	d}
tjdkrPt ¡ dkrP|sHdg}
nd	|vrPd
|d	< |rV||d< t||	|
d�}| j||||d�}t 	|¡ |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
    frozen_modules : bool, optional
        Whether to use frozen modules for potentially faster kernel startup.
        Using frozen modules prevents debugging inside of some built-in
        Python modules, such as io, abc, posixpath, ntpath, or stat.
        The frozen modules are used in CPython for faster interpreter startup.
        Ignored for cPython <3.11 and for other Python implementations.

    Returns
    -------
    The path where the kernelspec was installed.
    Nr   ú	--profilezPython %i [profile=%s]r   )é   é   ÚCPythonz-Xfrozen_modules=offZPYDEVD_DISABLE_FILE_VALIDATIONÚ1rA   )r"   r   r   )r>   r<   r?   )
r   r*   r   r   ÚplatformÚpython_implementationr9   Zinstall_kernel_specr+   Úrmtree)r:   r<   r>   r   r?   r@   rA   rC   r"   r   r   r    Údestr   r   r   Úinstalll   s>   ,€ÿÿ
rM   c                   @  s.   e Zd ZdZedƒZdddd	„Zdd
d„ZdS )ÚInstallIPythonKernelSpecAppzDummy app wrapping argparsezipython-kernel-installNr   r   r   ÚNonec                 C  s    |du rt jdd… }|| _dS )zInitialize the app.Nr&   )r   r   )Úselfr   r   r   r   Ú
initializeÎ   s   
z&InstallIPythonKernelSpecApp.initializec              
   C  sZ  ddl }|j| jdd�}|jdddd� |jd	ttd
d� |jdtdd� |jdtdd� |jdtdd� |jddtjddtj d� |jdddddd� |jdddd� | | j	¡}|j
rdt|j
ƒ|_
zt|j|j|j|j|j|j
d �}W n) tyŸ } z|jtjkršt|tjd!� |jr•td"tjd!� |  d#¡ ‚ d}~w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ÚdefaultrV   z--display-namezdSpecify the display name for the kernelspec. This is helpful when you have multiple IPython kernels.)rW   rV   rD   z]Specify an IPython profile to load. This can be used to create custom versions of the kernel.z--prefixz�Specify 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_constr?   z[Install to Python's sys.prefix. Shorthand for --prefix='%s'. For use in conda/virtual-envs.)rU   ÚconstrL   rV   z--envÚappendé   )ÚENVZVALUEz)Set environment variables for the kernel.)rU   ÚnargsÚmetavarrV   z--frozen_modulesz‘Enable frozen modules for potentially faster startup. This has a downside of preventing the debugger from navigating to certain built-in modules.)r<   r>   r@   r?   r   rA   )Úfilez$Perhaps you want `sudo` or `--user`?r&   zInstalled kernelspec z in )ÚargparseÚArgumentParserÚnameÚadd_argumentr   r*   r   r?   Ú
parse_argsr   rA   ÚdictrM   r<   r@   r   ÚOSErrorÚerrnoÚEACCESÚprintÚstderrÚexit)rP   ra   ÚparserÚoptsrL   Úer   r   r   ÚstartÔ   s’   ÿýüýýýÿûûý
ú
€úz!InstallIPythonKernelSpecApp.start)N)r   r   r   rO   )r   rO   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rc   rQ   rp   r   r   r   r   rN   É   s
    rN   Ú__main__)r	   NNN)
r
   r   r   r   r   r   r   r   r   r   )NN)r   r   r   r   r   r   )NNNN)
r    r!   r"   r#   r   r   r   r   r   r   )r:   r;   r<   r=   r>   r   r   r   r?   r   r@   r   rA   rB   rC   r=   r   r   )$rt   Ú
__future__r   rh   r5   ÚosrI   r+   r.   r   r(   Úpathlibr   Útypingr   Zjupyter_client.kernelspecr   Z	traitletsr   Ztraitlets.configr   r    Újoinr4   r   r*   Ú__file__Úparentr-   r   r   r9   rM   rN   rq   Zlaunch_instancer   r   r   r   Ú<module>   sV    üÿü$ø][ÿ