Format: application/x-python-code
⬇ Download File (13.9 KB)
   1  o
   2  
   3  ��h�I�	@s4dZddlZddlmZddlZddlZddlZddlZddlm	Z	ddl
   4  mZmZddl
   5  mZmZddlmZmZddlmZmZdd	lmZmZdd
   6  lmZddlmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ej%dkr�ej&�'d
   7  d�Z(e(dur�e)e	e(�d�gZ*ngZ*nddgZ*gZ+ej,�-ej.dd�Z/e/e*vr�e+�0e/�ej&�'d�Z1e1dvr�dZ2ne1�3�dvr�dZ2ne1�3�dvr�dZ2ne�4de1�iZ5e6ej7e8�r�e5�9ej7�e5�9dddddd��e8�Z:e6ej;e8�r�e:�9ej;�e:�9e8dd ej<iid!fdd ej=iid"fd#ddd$�id%fd&��Gd'd(�d(e�Z>Gd)d#�d#e�Z?dS)*a-
   8  An application for IPython.
   9  
  10  All top-level applications should use the classes in this module for
  11  handling configuration and creating configurables.
  12  
  13  The job of an :class:`Application` is to create the master configuration
  14  object and then create the configurable objects, passing the config to them.
  15  �N)�deepcopy)�Path)�Application�catch_config_error)�ConfigFileNotFound�PyFileConfigLoader)�release�crashhandler)�
  16  ProfileDir�ProfileDirError)�get_ipython_dir�get_ipython_package_dir)�ensure_dir_exists)	�List�Unicode�Type�Bool�Set�Instance�	Undefined�default�observe�ntZPROGRAMDATA�ipythonz/usr/local/etc/ipythonz/etc/ipython�etc�IPYTHON_SUPPRESS_CONFIG_ERRORS>�N>�1�trueT>�0�falseFz�Unsupported value for environment variable: 'IPYTHON_SUPPRESS_CONFIG_ERRORS' is set to '%s' which is none of  {'0', '1', 'false', 'true', ''}.�ProfileDir.locationzBaseIPythonApplication.profilez"BaseIPythonApplication.ipython_dirzApplication.log_levelz(BaseIPythonApplication.extra_config_file)zprofile-dir�profilezipython-dirz	log-level�configr�	log_levelz8set log level to logging.DEBUG (maximize logging output)z;set log level to logging.CRITICAL (minimize logging output)�BaseIPythonApplication)�copy_config_files�auto_createz�Initialize profile with default config files.  This is equivalent
  17              to running `ipython profile create <profile>` prior to startup.
  18              )�debug�quiet�initcs"eZdZdZd�fdd�	Z�ZS)�ProfileAwareConfigLoaderz>A Python file config loader that is aware of IPython profiles.NcsJ|durz	t�t�|�}Wn
  19  tyYdSw|j}tt|�j||d�S)N��path)r
  20  �find_profile_dir_by_namerr�location�superr+�load_subconfig)�self�fnamer-r"�profile_dir��	__class__��Nc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/application.pyr1qs��z'ProfileAwareConfigLoader.load_subconfig)NN)�__name__�
  21  __module__�__qualname__�__doc__r1�
  22  __classcell__r7r7r5r8r+osr+cseZdZdZdZeej�ZeZ	e
  23  Zee
  24  g�ZeZe�Ze�Zed�dd��Zed�dd��Zeej�e�dd	d
  25  ��Zee��Zed�dd
  26  ��Zedd�jdd�Z ed�dd��Z!ed
  27  dd�jdd�Z"ed	�dd��Z#e$dd�jdd�Z%edd�jdd�Z&ed�dd��Z'dZ(e)e
  28  dd�Z*ed�d d!��Z+e$dd"d�jdd�Z,e$dd#d�jdd�Z-ee��Z.ed$�d%d&��Z/e$dd'd�jdd�Z0e$dd(d�jdd�Z1e2e3j4�Z5e6�fd)d*��Z7d+d,�Z8d-d.�Z9ed�d/d0��Z:e;fd1d2�Z<d3d4�Z=d5d6�Z>d7d8�Z?e6d<d:d;��Z@�ZAS)=r%rz.IPython: an enhanced interactive Python shell.�config_file_namecCs|j�dd�dS)N�-�_z
  29  _config.py)�name�replace�r2r7r7r8�_config_file_name_default�sz0BaseIPythonApplication._config_file_name_defaultcCs(|d|dkr|j�|d�dSdS)N�new�old)�config_file_specified�add�r2�changer7r7r8�_config_file_name_changed�s�z0BaseIPythonApplication._config_file_name_changedr#r"r�config_file_pathscCsgS�Nr7rCr7r7r8�_config_file_paths_default�sz1BaseIPythonApplication._config_file_paths_defaultz�Path to an extra config file to load.
  30      
  31      If specified, load this config file in addition to any other IPython config.
  32      )�helpT)r#�extra_config_filecCsP|d}|d}z|j�|�Wn	tyYnw|j�|�|j�|�dS)NrFrE)�config_files�remove�
  33  ValueErrorrGrH�append)r2rJrFrEr7r7r8�_extra_config_file_changed�s�z1BaseIPythonApplication._extra_config_file_changedzThe IPython profile to use.cCstj�t�dd|d�|_dS)Nr#r"rE)�osr-�joinr
  34  �builtin_profile_dirrIr7r7r8�_profile_changed�s
  35  �z'BaseIPythonApplication._profile_changedFahShould the IPython profile directory be added to sys path ?
  36  
  37          This option was non-existing before IPython 8.0, and ipython_dir was added to
  38          sys path to allow import of extensions present there. This was historical
  39          baggage from when pip did not exist. This now default to false,
  40          but can be set to true for legacy reasons.
  41          a
  42          The name of the IPython directory. This directory is used for logging
  43          configuration (through profiles), history storage, etc. The default
  44          is usually $HOME/.ipython. This option can also be specified through
  45          the environment variable IPYTHONDIR.
  46          �ipython_dircCst�}|�d||d��|S)NrZ)rArFrE)r�_ipython_dir_changed)r2�dr7r7r8�_ipython_dir_default�s�z+BaseIPythonApplication._ipython_dir_default)�
  47  allow_noner4cCs|jrdS|��|jSrM)�_in_init_profile_dir�init_profile_dirr4rCr7r7r8�_profile_dir_default�sz+BaseIPythonApplication._profile_dir_defaultz7Whether to overwrite existing config files when copyingz1Whether to create profile dir if it doesn't existrQcCs|jgSrM)r>rCr7r7r8�_config_files_default�sz,BaseIPythonApplication._config_files_defaulta,Whether to install the default config files into the profile dir.
  48          If a new profile is being created, and IPython contains config files for that
  49          profile, then they will be staged into the new directory.  Otherwise,
  50          default config files will be automatically generated.
  51          z�Create a massive crash report when IPython encounters what may be an
  52          internal error.  The default is to append a short message to the
  53          usual tracebackcsHtt|�jdi|��zt��WdS|j�d�|�d�YdS)Nz(Current working directory doesn't exist.�r7)r0r%�__init__rV�getcwd�log�error�exit)r2�kwargsr5r7r8rdszBaseIPythonApplication.__init__cCs*|�|�|_|jt_dd�}t�|�dS)z?Create a crash handler, typically setting sys.excepthook to it.cSstjt_dSrM)�sys�__excepthook__�
  54  excepthookr7r7r7r8�unset_crashhandlerszEBaseIPythonApplication.init_crash_handler.<locals>.unset_crashhandlerN)�crash_handler_class�
  55  crash_handlerrlrj�atexit�register)r2rmr7r7r8�init_crash_handlersz)BaseIPythonApplication.init_crash_handlercCs"|jr
  56  |�|||�St�|||�S)z�this is sys.excepthook after init_crashhandler
  57  
  58          set self.verbose_crash=True to use our full crashhandler, instead of
  59          a regular traceback with a short message (crash_handler_lite)
  60          )�
  61  verbose_crashror	Zcrash_handler_lite)r2�etypeZevalue�tbr7r7r8rlsz!BaseIPythonApplication.excepthookcCs|d}|d}|turtj�|�}|tjvrtj�|�|jr�tj�|�}tj�|�t|�tj�	|d�}tj�	t
  62  �ddd�}tj�|�sStj�|�rSt�
  63  ||�dD])}tj�	||�}	zt|	�WqUty~}
  64  z|j�d|	|
  65  �WYd}
  66  ~
  67  qUd}
  68  ~
  69  ww|j�d|�dSdS)	NrFrEZREADMEr#r")�
  70  extensionsZnbextensionszcouldn't create path %s: %szIPYTHONDIR set to: %s)rrVr-�abspathrjrR�add_ipython_dir_to_sys_pathrTrrWr
  71  �exists�shutil�copy�OSErrorrfrgr()r2rJrFrEZstr_old�str_pathZreadmeZ
  72  readme_srcr\r-�er7r7r8r[$s4
  73  
  74  ����z+BaseIPythonApplication._ipython_dir_changedc	Cs*|j�d|j�d}|j�d|�z|durtj}|t_tj|||jd�Wnty8|j�d|�Ynw|dur@|t_|jD]O}|rK||krLqC|j�d|j�ztj|||jd�WqCty|||j	vrq|jj
  75  }n|jj}|d|�YqCty�|s��|jj
  76  d|jd	d
  77  �YqCwdS)asLoad the config file.
  78  
  79          By default, errors in loading config are handled, and a warning
  80          printed on screen. For testing, the suppress_errors option is set
  81          to False, so errors will make tests fail.
  82  
  83          `suppress_errors` default value is to be `None` in which case the
  84          behavior default to the one of `traitlets.Application`.
  85  
  86          The default value can be set :
  87             - to `False` by setting 'IPYTHON_SUPPRESS_CONFIG_ERRORS' environment variable to '0', or 'false' (case insensitive).
  88             - to `True` by setting 'IPYTHON_SUPPRESS_CONFIG_ERRORS' environment variable to '1' or 'true' (case insensitive).
  89             - to `None` by setting 'IPYTHON_SUPPRESS_CONFIG_ERRORS' environment variable to '' (empty string) or leaving it unset.
  90  
  91          Any other value are invalid, and will make IPython exit with a non-zero return code.
  92          z"Searching path %s for config fileszipython_config.pyz"Attempting to load config file: %sNr,zConfig file %s not foundz#Config file not found, skipping: %szError loading config file: %sT)�exc_info)rfr(rLrZraise_config_file_errors�load_config_filerrQr>rG�warning�	Exception)r2Zsuppress_errorsZbase_config�	old_valuer>�msgr7r7r8r�?s^�
  93  ��
  94  �
  95  �
  96  
  97  �
  98  ���z'BaseIPythonApplication.load_config_filecCs�d|_|jdur
  99  dSd|jvrrzt�|j|j|j�}WnMtyh|js*|jdkrXzt�	|j|j|j�}WntyM|j
 100  �d|j�|�d�Ynw|j
 101  �
 102  d|j�n|j
 103  �d|j�|�d�Ynvw|j
 104  �d	|j�nl|jjj}z	t�||j�}WnBty�|jr�z	t�||j�}Wnty�|j
 105  �d
 106  |�|�d�Ynw|j
 107  �d|�n
 108  |j
 109  �d|�|�d�Yn	w|j
 110  �d	|j�tj�|j�}|�d
 111  �r�|dd�|_||_|j�|j�d|_dS)zinitialize the profile dirTNr!rzCould not create profile: %rrczCreated profile dir: %rzProfile %r not found.zUsing existing profile dir: %rz&Could not create profile directory: %rzCreating new profile dir: %rzProfile directory %r not found.Zprofile_�F)r_r4r#r
 112  r.rZr"rr'Zcreate_profile_dir_by_namerf�fatalrh�infor/r(Zfind_profile_dirZcreate_profile_dirrVr-�basename�
 113  startswithrLrT)r2�pr/�dir_namer7r7r8r`sV
 114  
 115  �
 116  ��
 117  �
 118  ��
 119  
 120  z'BaseIPythonApplication.init_profile_dircCs�|j�t�|j�t�t|j�}|jrC|j}|j}|r=||�	�r=|j
 121  �d|||jj
 122  |jf�|jj|||jd�dS|��dS|�d�}|D]}|j}|jj||dd�rf|j
 123  �d||j|jj
 124  f�qJdS)z8[optionally] copy default config files into profile dir.z)Staging %r from %s into %r [overwrite=%s])r-�	overwritez*.pyFz"Staging bundled %s from %s into %rN)rL�extend�ENV_CONFIG_DIRS�SYSTEM_CONFIG_DIRSrrXr&r"r>ryrfr�r4r/r�Zcopy_config_file�stage_default_config_file�globrA)r2r-�src�cfg�files�fullpathr7r7r8�init_config_files�s.
 125  ��
 126  ���z(BaseIPythonApplication.init_config_filescCsL|��}t|jj�|j}|js|��s$|j�d|�|j	|dd�dSdS)zAauto generate default config file, and stage it into the profile.z"Generating default config file: %rzutf-8)�encodingN)
 127  Zgenerate_config_filerr4r/r>r�ryrfr��
 128  write_text)r2�s�config_filer7r7r8r��s�z0BaseIPythonApplication.stage_default_config_fileNcCsP|�|�|��|jdurdSt|j�}|��|��|��|�|�dSrM)	Zparse_command_linerrZsubapprr#r`r�r�Z
 129  update_config)r2�argvZ	cl_configr7r7r8�
 130  initialize�s
 131  
 132  
 133  z!BaseIPythonApplication.initializerM)Br9r:r;rA�descriptionrr�version�base_aliases�aliases�
 134  base_flags�flagsrr
 135  �classesr+Zpython_config_loader_classrrGr>rrDrrKrVr-rWr
 136  rXrLrN�tagrPrUr"rYrrxrZr]r_rr4rar�r'rQrbr&rsrr	ZCrashHandlerrnrrdrrrlr[rr�r`r�r�r�r=r7r7r5r8r%}s�
 137  
 138  
 139  
 140  �
 141  
 142  ��
 143  
 144  ��
 145  �	���
 146  	
 147  ����
 148  
 149  ����
 150  
 151  @6 )@r<rpr{r�loggingrVrzrj�pathlibrZtraitlets.config.applicationrrZtraitlets.config.loaderrrZIPython.corerr	ZIPython.core.profiledirr
 152  rZ
 153  IPython.pathsrr
 154  ZIPython.utils.pathrZ	traitletsrrrrrrrrrrA�environ�getZprogramdata�strr�r�r-rW�prefixZ_env_config_dirrTZ_envvarr�lowerrhr��
 155  isinstancer��dict�updater�r��DEBUG�CRITICALr+r%r7r7r7r8�<module>s�
 156  ,
 157  �
 158  ��
 159  �������