Format: application/x-python-code
⬇ Download File (7.8 KB)
   1  o
   2  
   3  �hP&�@s,dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
   4  Z
   5  ddlmZddl
   6  mZddlmZddlmZddlmZejjZd	e	jdZeee�jd
   7  �Z				d1d2dd�Z	d3d4dd�Z				d5d6dd�Zdd eddddd fd7d,d-�Z Gd.d/�d/e�Z!e"d0kr�e!�#�dSdS)8z#The IPython kernel spec for Jupyter�)�annotationsN)�Path)�Any)�KernelSpecManager)�Unicode)�Applicationzpython%i�	resources�ipykernel_launcher�mod�str�
   8  executable�
   9  str | None�extra_arguments�list[str] | None�python_arguments�return�	list[str]cCs<|durtj}|p
  10  g}|pg}|g|�d�|�d�d�|�S)a�Build Popen command list for launching an IPython kernel.
  11  
  12      Parameters
  13      ----------
  14      mod : str, optional (default 'ipykernel')
  15          A string of an IPython module whose __main__ starts an IPython kernel
  16      executable : str, optional (default sys.executable)
  17          The Python executable to use for the kernel process.
  18      extra_arguments : list, optional
  19          A list of extra arguments to pass when executing the launch code.
  20  
  21      Returns
  22      -------
  23      A Popen command list
  24      Nz-mz-fz{connection_file})�sysr)r
  25  rrr�r�Jc:\Users\shubh\Videos\agent\nova\Lib\site-packages\ipykernel/kernelspec.py�make_ipkernel_cmds
  26  r�dict[str, Any]cCs$t||d�dtjddddid�S)zConstruct dict for kernel.json�rrzPython %i (ipykernel)r�pythonZdebuggerT)�argv�display_name�language�metadata)rr�version_inforrrr�get_kernel_dict;s��r�path�Path | str | None�	overrides�dict[str, Any] | NonecCs�|durttjdd��t}t�t|�t|���j}|tj	@s*t|��
  27  |tj	B�t||�}|r6|�|�t
  28  t|d�d��}tj||dd�Wd�t|�S1sTwYt|�S)z�Write a kernel spec directory to `path`
  29  
  30      If `path` is not specified, a temporary directory is created.
  31      If `overrides` is given, the kernelspec JSON is updated before writing.
  32  
  33      The path to the kernelspec is always returned.
  34      NZ_kernels)�suffixzkernel.json�w�)�indent)r�tempfile�mkdtemp�KERNEL_NAME�shutil�copytree�	RESOURCES�stat�st_mode�S_IWUSR�chmodr�update�open�pjoin�json�dumpr)r r"rr�maskZkernel_dict�frrr�write_kernel_specIs
  35  
  36  
  37  
  38  
  39  ��r9F�kernel_spec_manager�KernelSpecManager | None�user�bool�kernel_namer�prefix�profile�env�dict[str, str] | None�frozen_modulesc
  40  Cs�|durt�}|dur
  41  i}|tkr|dur|}i}|r||d<|r3d|g}	|s2dtjd|f|d<nd}	d}
  42  tjdkrPt��dkrP|sHdg}
  43  nd	|vrPd
  44  |d	<|rV||d<t||	|
  45  d�}|j||||d
  46  �}t�	|�|S)a�Install the IPython kernelspec for Jupyter
  47  
  48      Parameters
  49      ----------
  50      kernel_spec_manager : KernelSpecManager [optional]
  51          A KernelSpecManager to use for installation.
  52          If none provided, a default instance will be created.
  53      user : bool [default: False]
  54          Whether to do a user-only install, or system-wide.
  55      kernel_name : str, optional
  56          Specify a name for the kernelspec.
  57          This is needed for having multiple IPython kernels for different environments.
  58      display_name : str, optional
  59          Specify the display name for the kernelspec
  60      profile : str, optional
  61          Specify a custom profile to be loaded by the kernel.
  62      prefix : str, optional
  63          Specify an install prefix for the kernelspec.
  64          This is needed to install into a non-default location, such as a conda/virtual-env.
  65      env : dict, optional
  66          A dictionary of extra environment variables for the kernel.
  67          These will be added to the current environment variables before the
  68          kernel is started
  69      frozen_modules : bool, optional
  70          Whether to use frozen modules for potentially faster kernel startup.
  71          Using frozen modules prevents debugging inside of some built-in
  72          Python modules, such as io, abc, posixpath, ntpath, or stat.
  73          The frozen modules are used in CPython for faster interpreter startup.
  74          Ignored for cPython <3.11 and for other Python implementations.
  75  
  76      Returns
  77      -------
  78      The path where the kernelspec was installed.
  79      Nr�	--profilezPython %i [profile=%s]r)���CPythonz-Xfrozen_modules=offZPYDEVD_DISABLE_FILE_VALIDATION�1rA)r"rr)r>r<r?)
  80  rr*rr�platform�python_implementationr9Zinstall_kernel_specr+�rmtree)
  81  r:r<r>rr?r@rArCr"rrr �destrrr�installls>,���
  82  rMc@s.eZdZdZed�Zdd
  83  dd	�Zdd
  84  d�ZdS)�InstallIPythonKernelSpecAppzDummy app wrapping argparsezipython-kernel-installNrrr�NonecCs |durtjdd�}||_dS)zInitialize the app.Nr&)rr)�selfrrrr�
  85  initialize�s
  86  z&InstallIPythonKernelSpecApp.initializec
  87  CsZddl}|j|jdd�}|jdddd�|jd	ttd
  88  d�|jdtd
  89  d�|jdtdd�|jdtdd�|jddtjddtjd�|jdddddd�|jdddd�|�|j	�}|j
  90  rdt|j
  91  �|_
  92  zt|j
  93  |j|j|j|j|j
  94  d �}Wn)ty�}z|jtjkr�t|tjd!�|j
  95  r�td"tjd!�|�d#��d}~wwtd$|j�d%|���dS)&zStart the app.rNz Install the IPython kernel spec.)�prog�descriptionz--user�
  96  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�defaultrVz--display-namezdSpecify the display name for the kernelspec. This is helpful when you have multiple IPython kernels.)rWrVrDz]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�constrLrVz--env�append�)�ENVZVALUEz)Set environment variables for the kernel.)rU�nargs�metavarrVz--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?rrA)�filez$Perhaps you want `sudo` or `--user`?r&zInstalled kernelspec z in )�argparse�ArgumentParser�name�add_argumentrr*rr?�
  97  parse_argsrrA�dictrMr<r@r�OSError�errno�EACCES�print�stderr�exit)rPra�parser�optsrL�errr�start�s�����������
  98  �
  99  ��z!InstallIPythonKernelSpecApp.start)N)rrrrO)rrO)�__name__�
 100  __module__�__qualname__�__doc__rrcrQrprrrrrN�s
 101  rN�__main__)r	NNN)
 102  r
 103  rrr
 104  rrrrrr)NN)rrrrrr)NNNN)
 105  r r!r"r#rrrrrr)r:r;r<r=r>rrr
 106  r?r
 107  r@r
 108  rArBrCr=rr)$rt�
 109  __future__rrhr5�osrIr+r.rr(�pathlibr�typingrZjupyter_client.kernelspecrZ	traitletsrZtraitlets.configrr �joinr4rr*�__file__�parentr-rrr9rMrNrqZlaunch_instancerrrr�<module>sV���$�][�