
    Mh)                        d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZmZmZmZ d	Zd
ZdZdZdZdZd Zd Z G d de          Z G d de          Zi Ze                    e           e                    d           dddiidfed<   dddiidfed<    G d de          Z  G d de          Z!dS ) zx
An application for managing IPython profiles.

To be invoked as the `ipython profile` subcommand.

Authors:

* Min RK

    N)Application)BaseIPythonApplication
base_flags)
ProfileDir)import_item)get_ipython_dirget_ipython_package_dir)UnicodeBoolDictobservea&  Create an IPython profile by name

Create an ipython profile directory by its name or
profile directory path. Profile directories contain
configuration, log and security related files and are named
using the convention 'profile_<name>'. By default they are
located in your ipython directory. Once created, you will
can edit the configuration files in the profile
directory to configure IPython. Most users will create a
profile directory by name,
`ipython profile create myprofile`, which will put the directory
in `<ipython_dir>/profile_myprofile`.
zList available IPython profiles

List all available profiles, by profile location, that can
be found in the current working directly or in the ipython
directory. Profile directories are named using the convention
'profile_<profile>'.
a-  Manage IPython profiles

Profile directories contain
configuration, log and security related files and are named
using the convention 'profile_<name>'. By default they are
located in your ipython directory.  You can create profiles
with `ipython profile create <name>`, or see the profiles you
already have with `ipython profile list`

To get started configuring IPython, simply do:

$> ipython profile create

and IPython will create the default profile in <ipython_dir>/profile_default,
where you can edit ipython_config.py to start configuring IPython.

z)ipython profile list  # list all profilesz
ipython profile create foo         # create profile foo w/ default config files
ipython profile create foo --reset # restage default config files over current
ipython profile create foo --parallel # also stage parallel config files
z
ipython profile create -h  # show the help string for the create subcommand
ipython profile list -h    # show the help string for the list subcommand

ipython locate profile foo # print the path to the directory for profile 'foo'
c                     g }t          j        |           }|D ]d}|                                rN|j                            d          r4|                    |j                            dd          d                    e|S )z'list profiles in a given root directoryprofile__   )osscandiris_dirname
startswithappendsplit)pathprofilesfilesfs       W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/core/profileapp.pylist_profiles_inr   a   s{    H JtE 6 688:: 	6!&++J77 	6OOAFLLa004555O    c                     t           j                            t                      dd          } g }t          j        |           }|D ];}|                                r%|j        dk    r|                    |j                   <|S )z,list profiles that are bundled with IPython.coreprofile__pycache__)r   r   joinr	   r   r   r   r   )r   r   r   r#   s       r   list_bundled_profilesr&   m   s}    7<</117JGGDH ZE * *>> 	* = =OOGL)))Or    c                   *     e Zd ZdZd fd	Zd Z xZS )ProfileLocatez(print the path to an IPython profile dirNc                     t          t          |                               |           | j        r| j        d         | _        d S d S Nr   )superr(   parse_command_line
extra_argsr#   selfargv	__class__s     r   r,   z ProfileLocate.parse_command_line}   sG    mT""55d;;;? 	.?1-DLLL	. 	.r    c                 8    t          | j        j                   d S N)printprofile_dirlocationr/   s    r   startzProfileLocate.start   s    d'(((((r    r3   )__name__
__module____qualname__descriptionr,   r8   __classcell__r1   s   @r   r(   r(   z   sQ        @K. . . . . .
) ) ) ) ) ) )r    r(   c                       e Zd ZdZeZeZ eddd          Z	 e e
dddiidf	                    Z e e            d
                              d          Zd Zd Zd ZdS )ProfileListipython-profilezProfileList.ipython_dirzApplication.log_level)zipython-dirz	log-levelr   	log_levelr   z6Set Application.log_level to 0, maximizing log output.)debuga  
        The name of the IPython directory. This directory is used for logging
        configuration (through profiles), history storage, etc. The default
        is usually $HOME/.ipython. This options can also be specified through
        the environment variable IPYTHONDIR.
        helpTconfigc                 4    |D ]}t          d|z             dS )z!print list of profiles, indented.z    %sN)r4   )r/   r   r#   s      r   _print_profileszProfileList._print_profiles   s1     	& 	&G(W$%%%%	& 	&r    c                    t                      }|rut                       t          d           |                     |           t                       t          d           t          d| j        z             t          d           t	          | j                  }|r:t                       t          d| j        z             |                     |           t	          t          j                              }|rt                       t          d           t                       t          d           t          d           t                       d S )	NzAvailable profiles in IPython:z8    The first request for a bundled profile will copy itz%    into your IPython directory (%s),z    where you can customize it.zAvailable profiles in %s:zLProfiles from CWD have been removed for security reason, see CVE-2022-21699:z5To use any of the above profiles, start IPython with:z    ipython --profile=<name>)r&   r4   rI   ipython_dirr   r   getcwd)r/   r   s     r   list_profile_dirszProfileList.list_profile_dirs   s:   (** 	5GGG2333  ***GGGLMMM9D<LLMMM3444#D$455 	+GGG-0@@AAA  ***#BIKK00 	GGG^   	EFFF,---r    c                 .    |                                   d S r3   )rM   r7   s    r   r8   zProfileList.start   s         r    N)r9   r:   r;   r   	list_helpr<   _list_examplesexamplesr   aliasesdictflagsr
   r   tagrK   rI   rM   r8    r    r   r@   r@      s        DKHd1-   G D;"34D
    E '//++   
cc & & &
  :! ! ! ! !r    r@   initProfileCreate	overwriteTz3reset config files in this profile to the defaults.resetparallelzSInclude the config files for parallel computing apps (ipengine, ipcontroller, etc.)c                       e Zd ZdZeZeZ ed          	                    d          Z
d Zd Z edd          	                    d          Z ed	          d
             Z fdZ ee          ZegZd Z fdZd Z xZS )rX   rA   TrF   c                     dS )Nz[%(name)s] %(message)srV   r7   s    r   _log_format_defaultz!ProfileCreate._log_format_default   s    ''r    c                     dS )NTrV   r7   s    r   _copy_config_files_defaultz(ProfileCreate._copy_config_files_default   s    tr    Fz2whether to include parallel computing config filesrD   r[   c                     g d}|d         r!|D ]}| j                             |           d S |D ]%}|| j         v r| j                             |           &d S )N)zipcontroller_config.pyzipengine_config.pyzipcluster_config.pynew)config_filesr   remove)r/   changeparallel_filescfs       r   _parallel_changedzProfileCreate._parallel_changed   s       %= 	1$ - -!((,,,,- - % 1 1***%,,R0001 1r    c                     t          t          |                               |           | j        r| j        d         | _        d S d S r*   )r+   rX   r,   r-   r#   r.   s     r   r,   z ProfileCreate.parse_command_line   sG    mT""55d;;;? 	.?1-DLLL	. 	.r    c                 
   d}|                     dd          d         }	 t          |          }nS# t          $ r | j                            d|           Y n,t
          $ r  | j                            d|d           Y nw xY w|S )	zimport an app classN.r   r   z0Couldn't import %s, config file will be excludedzUnexpected error importing %sT)exc_info)rsplitr   ImportErrorloginfo	Exceptionwarning)r/   app_pathappr   s       r   _import_appzProfileCreate._import_app   s    sA&&r*	Sh''CC 	T 	T 	THMMLdSSSSS 	S 	S 	SH<dTRRRRR	S
s   0 %B &B ?B c                    t          t          |                                            ddlm} |g}dD ].}|                     |          }||                    |           /| j        r*ddlm	} ddl
m} ddlm} |                    |||g           |D ]v} |            }|j                            | j                   | j        |_        | j        |_        d|_        | j        |_        | j        |_        |                                 wd S )Nr   )TerminalIPythonApp)zipykernel.kernelapp.IPKernelApp)IPControllerApp)IPEngineApp)IPClusterStartT)r+   rX   init_config_filesIPython.terminal.ipapprw   ru   r   r[    ipyparallel.apps.ipcontrollerapprx   ipyparallel.apps.ipengineappry   ipyparallel.apps.ipclusterapprz   extendrG   updatero   rY   copy_config_filesrK   r5   )
r/   rw   appsrs   rt   rx   ry   rz   Appr1   s
            r   r{   zProfileCreate.init_config_files  s\   mT""44666======"#
 	! 	!H ""8,,CC   = 	HHHHHH@@@@@@DDDDDDKK   
  	$ 	$C#%%CJdk***hCG NCM"&C! ,CO ,CO!!####	$ 	$r    c                     d S r3   rV   r7   s    r   stage_default_config_filez'ProfileCreate.stage_default_config_file!  s    r    )r9   r:   r;   r   create_helpr<   _create_examplesrQ   r   rU   auto_creater^   r`   r[   r   rh   r,   r   create_flagsrT   r   classesru   r{   r   r=   r>   s   @r   rX   rX      s$       DKH$t**...--K( ( (   tEA  	cc  WZ1 1 1. . . . . DElG
 
 
$ $ $ $ $<      r    c            	          e Zd ZdZeZeZ e e	e
e
j                                        d         feej                                        d         feej                                        d         f                    Zd ZdS )
ProfileAppzipython profiler   )createlistlocatec           	      @   | j         t          dd                    t          t          | j                            z   dz              |                                  |                                  |                     d           d S | j         	                                S )Nz.No subcommand specified. Must specify one of: z, z.
r   )
subappr4   r%   mapreprsubcommandsprint_descriptionprint_subcommandsexitr8   r7   s    r   r8   zProfileApp.start0  s    ;@))Cd&677889  
 ""$$$""$$$IIaLLLLL;$$&&&r    N)r9   r:   r;   r   profile_helpr<   _main_examplesrQ   r   rS   rX   
splitlinesr@   r(   r   r8   rV   r    r   r   r   %  s        DKH$tt!:!E!E!G!G!JK[4??AA!DE!:!E!E!G!G!JK    K' ' ' ' 'r    r   )"__doc__r   traitlets.config.applicationr   IPython.core.applicationr   r   IPython.core.profiledirr   IPython.utils.importstringr   IPython.pathsr   r	   	traitletsr
   r   r   r   r   rO   r   rP   r   r   r   r&   r(   r@   r   r   poprX   r   rV   r    r   <module>r      s)  	 	, 
			 4 4 4 4 4 4        / . . . . . 2 2 2 2 2 2 B B B B B B B B 2 2 2 2 2 2 2 2 2 2 2 2	$ = 	 	 	
 
 
	) 	) 	) 	) 	)* 	) 	) 	)<! <! <! <! <!+ <! <! <!~    J         )K$+?@MOW ,zD.ABHIZ 
R R R R R* R R Rj' ' ' ' ' ' ' ' ' 'r    