/ lib / IPython / core / application.pyc
application.pyc
  1  o

  2  .��c	J�	@s4dZddlZddlmZddlZddlZddlZddlZddlm	Z	ddl
  3  mZmZddl
mZmZddlmZmZddlmZmZdd	lmZmZdd
  4  lmZddlmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ej%dkr�ej&�'d
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-
  5  An application for IPython.
  6  
  7  All top-level applications should use the classes in this module for
  8  handling configuration and creating configurables.
  9  
 10  The job of an :class:`Application` is to create the master configuration
 11  object and then create the configurable objects, passing the config to them.
 12  �N)�deepcopy)�Path)�Application�catch_config_error)�ConfigFileNotFound�PyFileConfigLoader)�release�crashhandler)�
 13  ProfileDir�ProfileDirError)�get_ipython_dir�get_ipython_package_dir)�ensure_dir_exists)	�List�Unicode�Type�Bool�Set�Instance�	Undefined�default�observe�nt�PROGRAMDATA�ipythonz/usr/local/etc/ipythonz/etc/ipython�etc�IPYTHON_SUPPRESS_CONFIG_ERRORS>�N>�1�trueT>�false�0Fz�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
 14              to running `ipython profile create <profile>` prior to startup.
 15              )�debug�quiet�initcs"eZdZdZd�fdd�	Z�ZS)�ProfileAwareConfigLoaderz>A Python file config loader that is aware of IPython profiles.NcsJ|durz	t�t�|�}Wn
 16  tyYdSw|j}tt|�j||d�S)N��path)r
 17  �find_profile_dir_by_namerr�location�superr,�load_subconfig)�self�fnamer.r#�profile_dir��	__class__���C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\IPython\core\application.pyr2qs��z'ProfileAwareConfigLoader.load_subconfig)NN)�__name__�
 18  __module__�__qualname__�__doc__r2�
__classcell__r8r8r6r9r,osr,cs
 19  eZdZdZed�Zeej�ZeZ	e
 20  Zee
g�ZeZe�Ze�Zed�dd��Zed�dd��Zeej�e�dd	d
 21  ��Zee��Zed�dd
��Zedd�jdd�Z ed�dd��Z!ed
 22  dd�jdd�Z"ed	�dd��Z#e$dd�jdd�Z%edd�jdd�Z&ed�dd��Z'dZ(e)e
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
 23  _config.py)�name�replace�r3r8r8r9�_config_file_name_default�sz0BaseIPythonApplication._config_file_name_defaultcCs(|d|dkr|j�|d�dSdS)N�new�old)�config_file_specified�add�r3�changer8r8r9�_config_file_name_changed�s�z0BaseIPythonApplication._config_file_name_changedr$r#r�config_file_pathscCsgS�Nr8rDr8r8r9�_config_file_paths_default�sz1BaseIPythonApplication._config_file_paths_defaultz�Path to an extra config file to load.
 24      
 25      If specified, load this config file in addition to any other IPython config.
 26      )�helpT)r$�extra_config_filecCsP|d}|d}z|j�|�Wn	tyYnw|j�|�|j�|�dS)NrGrF)�config_files�remove�
 27  ValueErrorrHrI�append)r3rKrGrFr8r8r9�_extra_config_file_changed�s�z1BaseIPythonApplication._extra_config_file_changedzThe IPython profile to use.cCstj�t�dd|d�|_dS)Nr$r#rF)�osr.�joinr
�builtin_profile_dirrJr8r8r9�_profile_changed�s
 28  �z'BaseIPythonApplication._profile_changedFahShould the IPython profile directory be added to sys path ?
 29  
 30          This option was non-existing before IPython 8.0, and ipython_dir was added to
 31          sys path to allow import of extensions present there. This was historical
 32          baggage from when pip did not exist. This now default to false,
 33          but can be set to true for legacy reasons.
 34          a
 35          The name of the IPython directory. This directory is used for logging
 36          configuration (through profiles), history storage, etc. The default
 37          is usually $HOME/.ipython. This option can also be specified through
 38          the environment variable IPYTHONDIR.
 39          �ipython_dircCst�}|�d||d��|S)Nr[)rBrGrF)r�_ipython_dir_changed)r3�dr8r8r9�_ipython_dir_default�s�z+BaseIPythonApplication._ipython_dir_default)�
 40  allow_noner5cCs|jrdS|��|jSrN)�_in_init_profile_dir�init_profile_dirr5rDr8r8r9�_profile_dir_default�sz+BaseIPythonApplication._profile_dir_defaultz7Whether to overwrite existing config files when copyingz1Whether to create profile dir if it doesn't existrRcCs|jgSrN)r?rDr8r8r9�_config_files_default�sz,BaseIPythonApplication._config_files_defaulta,Whether to install the default config files into the profile dir.
 41          If a new profile is being created, and IPython contains config files for that
 42          profile, then they will be staged into the new directory.  Otherwise,
 43          default config files will be automatically generated.
 44          z�Create a massive crash report when IPython encounters what may be an
 45          internal error.  The default is to append a short message to the
 46          usual tracebackcsHtt|�jdi|��zt��WdS|j�d�|�d�YdS)Nz(Current working directory doesn't exist.�r8)r1r&�__init__rW�getcwd�log�error�exit)r3�kwargsr6r8r9re�szBaseIPythonApplication.__init__cCs*|�|�|_|jt_dd�}t�|�dS)z?Create a crash handler, typically setting sys.excepthook to it.cSstjt_dSrN)�sys�__excepthook__�
 47  excepthookr8r8r8r9�unset_crashhandlerszEBaseIPythonApplication.init_crash_handler.<locals>.unset_crashhandlerN)�crash_handler_class�
crash_handlerrmrk�atexit�register)r3rnr8r8r9�init_crash_handler
sz)BaseIPythonApplication.init_crash_handlercCs"|jr
 48  |�|||�St�|||�S)z�this is sys.excepthook after init_crashhandler
 49  
 50          set self.verbose_crash=True to use our full crashhandler, instead of
 51          a regular traceback with a short message (crash_handler_lite)
 52          )�
verbose_crashrpr	�crash_handler_lite)r3�etype�evalue�tbr8r8r9rmsz!BaseIPythonApplication.excepthookcCs|d}|d}|turtj�|�}|tjvrtj�|�|jr�tj�|�}tj�|�t|�tj�	|d�}tj�	t
 53  �ddd�}tj�|�sStj�|�rSt�
||�dD])}tj�	||�}	zt|	�WqUty~}
 54  z|j�d|	|
 55  �WYd}
 56  ~
 57  qUd}
 58  ~
 59  ww|j�d|�dSdS)	NrGrF�READMEr$r#)�
 60  extensionsZnbextensionszcouldn't create path %s: %szIPYTHONDIR set to: %s)rrWr.�abspathrkrS�add_ipython_dir_to_sys_pathrUrrXr
�exists�shutil�copy�OSErrorrgrhr))r3rKrGrFZstr_old�str_path�readmeZ
 61  readme_srcr]r.�er8r8r9r\!s4
 62  
 63  ����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
 64  }n|jj}|d|�YqCty�|s��|jj
 65  d|jd	d
 66  �YqCwdS)asLoad the config file.
 67  
 68          By default, errors in loading config are handled, and a warning
 69          printed on screen. For testing, the suppress_errors option is set
 70          to False, so errors will make tests fail.
 71  
 72          `suppress_errors` default value is to be `None` in which case the
 73          behavior default to the one of `traitlets.Application`.
 74  
 75          The default value can be set :
 76             - to `False` by setting 'IPYTHON_SUPPRESS_CONFIG_ERRORS' environment variable to '0', or 'false' (case insensitive).
 77             - to `True` by setting 'IPYTHON_SUPPRESS_CONFIG_ERRORS' environment variable to '1' or 'true' (case insensitive).
 78             - to `None` by setting 'IPYTHON_SUPPRESS_CONFIG_ERRORS' environment variable to '' (empty string) or leaving it unset.
 79  
 80          Any other value are invalid, and will make IPython exit with a non-zero return code.
 81          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)rgr)rMr�raise_config_file_errors�load_config_filerrRr?rH�warning�	Exception)r3Zsuppress_errorsZbase_config�	old_valuer?�msgr8r8r9r�<s^�
 82  ��
 83  �
 84  �
 85  
 86  �
 87  ���z'BaseIPythonApplication.load_config_filecCs�d|_|jdur
 88  dSd|jvrtzt�|j|j|j�}WnMtyh|js*|jdkrXzt�	|j|j|j�}WntyM|j
 89  �d|j�|�d�Ynw|j
 90  �
d|j�n|j
 91  �d|j�|�d�Ynzw|j
 92  �d	|j���nn|jjj}z	t�||j�}WnBty�|jr�z	t�||j�}Wnty�|j
 93  �d
 94  |�|�d�Ynw|j
 95  �d|�n
|j
 96  �d|�|�d�Ynw|j
 97  �d	|j���tj�|j�}|�d
�r�|dd�|_||_|j�|j�d|_dS)zinitialize the profile dirTNr"rzCould not create profile: %rrdzCreated profile dir: %rzProfile %r not found.zUsing existing profile dir: z&Could not create profile directory: %rzCreating new profile dir: %rzProfile directory %r not found.�profile_�F)r`r5r$r
 98  r/r[r#rr(�create_profile_dir_by_namerg�fatalri�infor0r)�find_profile_dir�create_profile_dirrWr.�basename�
 99  startswithrMrU)r3�pr0�dir_namer8r8r9ra|sV
100  
101  �
102  ��
103  �
104  ��
105  
106  z'BaseIPythonApplication.init_profile_dircCs�|j�t�|j�t�t|j�}|jrC|j}|j}|r=||�	�r=|j
107  �d|||jj
|jf�|jj|||jd�dS|��dS|�d�}|D]}|j}|jj||dd�rf|j
108  �d||j|jj
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)rM�extend�ENV_CONFIG_DIRS�SYSTEM_CONFIG_DIRSrrYr'r#r?r}rgr�r5r0r��copy_config_file�stage_default_config_file�globrB)r3r.�src�cfg�files�fullpathr8r8r9�init_config_files�s.
109  ��
110  ���z(BaseIPythonApplication.init_config_filescCsN|��}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)
111  �generate_config_filerr5r0r?r�r}rgr��
112  write_text)r3�s�config_filer8r8r9r��s�z0BaseIPythonApplication.stage_default_config_fileNcCsP|�|�|��|jdurdSt|j�}|��|��|��|�|�dSrN)	�parse_command_liners�subapprr$rar�r��
update_config)r3�argvZ	cl_configr8r8r9�
113  initialize�s
114  
115  
116  z!BaseIPythonApplication.initializerN)Br:r;r<rBr�descriptionr�version�base_aliases�aliases�
117  base_flags�flagsrr
118  �classesr,�python_config_loader_classrrHr?rrErrLrWr.rXr
rYrMrO�tagrQrVr#rZrr|r[r^r`rr5rbr�r(rRrcr'rtrr	�CrashHandlerrorrersrmr\rr�rar�r�r�r>r8r8r6r9r&}s�
119  
120  
121  
122  �
123  
124  ��
125  
126  ��
127  �	���
128  	
129  ����
130  
131  ����
132  
133  @6 )@r=rqrr�loggingrWr~rk�pathlibr�traitlets.config.applicationrr�traitlets.config.loaderrr�IPython.corerr	�IPython.core.profiledirr
134  r�
IPython.pathsrr
�IPython.utils.pathr�	traitletsrrrrrrrrrrB�environ�get�programdata�strr�r�r.rX�prefix�_env_config_dirrU�_envvarr�lowerrir��
135  isinstancer��dict�updater�r��DEBUG�CRITICALr,r&r8r8r8r9�<module>s�
,
136  �
137  ��
138  �������