
    ^h!                       S r SSKJr  SSKrSSKrSSKrSSKJrJr  SSKJ	r	  SSK
Jr  SSKJrJr  SSKJr  S	S
KJr  S	SKJrJr  S	SKJr  \" \	" SS5      5      \" \	" SS5      5      \" \	" SS5      5      \" \	" SS5      5      \" \	" SS5      5      \" \	" SS5      5      0r\" \	" SSS5      5      r\" \	" SS5      5      rS H'  r\" \	" SS\5      5      r\" \	" S\5      5      r\\\'   M)     / SQr\R@                  r!\!" S5      S\!" S5      S\!" S5      S\!" S5      S \!" S!5      S"0r"S-S# jr#S.S$ jr$S/S0S% jjr%S.S& jr&S.S' jr'S1S( jr(S2S) jr) " S* S+\5      r*\*RV                  r,\-S,:X  a  \," 5         gg)3a  Migrating IPython < 4.0 to Jupyter

This *copies* configuration and resources to their new locations in Jupyter

Migrations:

- .ipython/
  - nbextensions -> JUPYTER_DATA_DIR/nbextensions
  - kernels ->  JUPYTER_DATA_DIR/kernels

- .ipython/profile_default/
  - static/custom -> .jupyter/custom
  - nbconfig -> .jupyter/nbconfig
  - security/

    - notebook_secret, notebook_cookie_secret, nbsignatures.db -> JUPYTER_DATA_DIR

  - ipython_{notebook,nbconvert,qtconsole}_config.py -> .jupyter/jupyter_{name}_config.py


    )annotationsN)datetimetimezone)Path)Any)JSONFileConfigLoaderPyFileConfigLoader)
get_logger   )
JupyterApp)jupyter_config_dirjupyter_data_dir)ensure_dir_existsz{ipython_dir}nbextensionsz{jupyter_data}kernelsz	{profile}nbconfigz{jupyter_config}staticcustom)notebook_secretnotebook_cookie_secretznbsignatures.dbsecurity)notebook	nbconvert	qtconsolez\bIPythonQtConsoleApp\bJupyterQtConsoleAppz\bIPythonWidget\bJupyterWidgetz\bRichIPythonWidget\bRichJupyterWidgetz\bIPython\.html\br   z\bIPython\.nbconvert\br   c                     [         R                  R                  S[        [	        S5      R                  5       5      5      $ )a  Return the IPython directory location.

Not imported from IPython because the IPython implementation
ensures that a writable directory exists,
creating a temporary directory if not.
We don't want to trigger that when checking if migration should happen.

We only need to support the IPython < 4 behavior for migration,
so importing for forward-compatibility and edge cases is not important.

IPYTHONDIRz
~/.ipython)osenvirongetstrr   
expanduser     N/home/james-whalen/.local/lib/python3.13/site-packages/jupyter_core/migrate.pyget_ipython_dirr(   H   s,     ::>>,D,>,I,I,K(LMMr&   c                   [        5       n[        U 5      n[        U5      n[        UR                  5       5      (       d  UR	                  SU 5        gUR                  5       (       aA  [        UR                  5       5      (       a  UR	                  SU5        gUR                  5         UR                  SX5        [        UR                  5        [        R                  " XSS9  g)z#Migrate a directory from src to dstzNo files in %sF%s already existsCopying %s -> %sT)symlinks)r
   r   anyiterdirdebugexistsrmdirinfor   parentshutilcopytree)srcdstlogsrc_pathdst_paths        r'   migrate_dirr;   V   s    
,CCyHCyHx!""		"C(x!""II)3/HH*hoo&
OOCt,r&   c                J   [        5       n[        U5      nUR                  5       (       a  UR                  SU5        gUR	                  SX5        [        UR                  5        [        R                  " X5        U(       a  UR                  5        nUR                  5       nSSS5        UR                  5        H  u  pxUR                  UW5      nM     UR                  S5       nUR                  W5        SSS5        gg! , (       d  f       Nf= f! , (       d  f       g= f)zMigrate a single file from src to dst

substitutions is an optional dict of {regex: replacement} for performing replacements on the file.
r*   Fr+   NwT)r
   r   r0   r/   r2   r   r3   r4   copyopenreaditemssubwrite)	r6   r7   substitutionsr8   r:   ftextpatreplacements	            r'   migrate_filerI   j   s    
 ,CCyH		%s+HH*hoo&
KK]]_668D  - 3 3 5C77;-D !6]]31GGDM   _  s   D'D
D
D"c                    [        5       n[        U 5      R                  5       (       a  [        X5      $ [        U 5      R	                  5       (       a  [        X5      $ UR                  SU 5        g)z2Migrate one item

dispatches to migrate_dir/_file
zNothing to migrate for %sF)r
   r   is_filerI   is_dirr;   r/   )r6   r7   r8   s      r'   migrate_onerM      sY    
 ,CCyC%%Cy3$$II)3/r&   c                \   [        5       nSn[        U S5      n[        U S5      nSn[        U5      R                  5       (       a  [        R                  " USS9 nUR	                  5       R                  5       nUR                  5        HB  n	U	R                  5       (       a  M  U	R                  5       R                  S5      (       a  M@  Sn  O   SSS5        Sn
[        U5      R                  5       (       ae  [        R                  " USS9 nUR	                  5       R                  5       nUR                  S	5      =(       a    UR                  S
5      n
SSS5        U(       a  UR                  SU5        U
(       a  UR                  SU5        U(       a  U
(       a  g[        U5        U(       a  U
(       d  [        U5        U(       d  [        U[        US5      5      (       a  SnU
(       d  [        U[        US5      5      (       a  SnU$ ! , (       d  f       GNC= f! , (       d  f       N= f)znMigrate non-empty custom.js,css from src to dst

src, dst are 'custom' directories containing custom.{js,css}
Fz	custom.jsz
custom.cssTutf-8encoding)/**z//NrR   z*/zIgnoring empty %s)r
   r   rK   r?   r@   strip
splitlinesisspace
startswithendswithr/   r   rI   )r6   r7   r8   migrated	custom_js
custom_csscustom_js_emptyrE   jslinecustom_css_emptycsss               r'   migrate_static_customra      s   
 ,CHS+&Ic<(JOI  YYy73q!B$**,*A*ABS*T*T&+O ( 4 J!!YYzG4&&(.."C"~~d3JT8J 5 		%y1		%z2+c"2#|ItC7MNNZc<9P Q QOA 43 54s&   AH#"H	HAH
H
H+c                   [        5       n[        [        US    SU  S35      5      n[        [        US    SU  S35      5      n[        [        S.n/ nS H  nX7-   nXG-   n	[        U5      R                  5       (       d  M+  XW   " U5      R                  5       n
U
(       a(  [        X[        S9(       a  UR                  U5        Mp  Mr  UR                  SU5        M     U$ )	zOMigrate a config file.

Includes substitutions for updated configurable names.
profileipython__configjupyter_configjupyter_)z.pyz.json)rD   z#Not migrating empty config file: %s)r
   r#   r   r	   r   r0   load_configrI   config_substitutionsappendr/   )nameenvr8   src_basedst_baseloadersrY   extr6   r7   cfgs              r'   migrate_configrr      s    
 ,C43y>*xvW-EFGH43/01htfG4LMNH!%G Hnn9,s#//1C8LMOOC( N 		?E   Or&   c            	     x   [        5       [        5       [        5       [        [	        [        5       S5      5      S.n Sn[
        R                  5        H]  u  p#UR                  " S0 U D6nUR                  " S0 U D6n[	        U5      R                  5       (       d  MI  [        XE5      (       d  M[  SnM_     [         H  n[        X`5      (       d  M  SnM     [        R                  " S0 U D6n[        R                  " S0 U D6n[	        U5      R                  5       (       a  [        Xx5      (       a  Sn[        U S   5        [        R                   " [	        U S   S5      SSS	9 n	U	R#                  [$        R&                  " [(        R*                  S
9R-                  5       5        SSS5        U$ ! , (       d  f       U$ = f)z(Migrate IPython configuration to Jupyterprofile_default)jupyter_datarf   ipython_dirrc   FTrf   rY   r=   rO   rP   )tzNr%   )r   r   r(   r#   r   
migrationsrA   formatr0   rM   config_migrationsrr   custom_src_tcustom_dst_tra   r   r?   rC   r   nowr   utc	isoformat)
rl   rY   src_tdst_tr6   r7   rk   
custom_src
custom_dstrE   s
             r'   migrater      sh    )*,.&(tO-/@AB	C H"((*ll!S!ll!S!9+c"7"7H	 + "$$$H " $$+s+J$$+s+JJ  %::%R%R c*+,	4,-z:C'	RVW	-779: 
S O 
S	R Os    A F**
F9c                  *    \ rS rSrSrSrSrSS jrSrg)	JupyterMigrate   zA Jupyter Migration App.zjupyter-migratea  
    Migrate configuration and data from .ipython prior to 4.0 to Jupyter locations.

    This migrates:

    - config files in the default profile
    - kernels in ~/.ipython/kernels
    - notebook javascript extensions in ~/.ipython/extensions
    - custom.js/css to .jupyter/custom

    to their new Jupyter locations.

    All files are copied, not moved.
    If the destinations already exist, nothing will be done.
    c                Z    [        5       (       d  U R                  R                  S5        gg)zStart the application.zFound nothing to migrate.N)r   r8   r2   )selfs    r'   startJupyterMigrate.start  s    yyHHMM56 r&   r%   N)returnNone)	__name__
__module____qualname____firstlineno____doc__rk   descriptionr   __static_attributes__r%   r&   r'   r   r      s    "DK 7r&   r   __main__)r   r#   )r6   r#   r7   r#   r   bool)N)r6   
str | Pathr7   r   rD   r   r   r   )rk   r#   rl   r   r   z	list[Any])r   r   ).r   
__future__r   r    rer4   r   r   pathlibr   typingr   traitlets.config.loaderr   r	   traitlets.logr
   applicationr   pathsr   r   utilsr   r#   rx   r{   r|   security_filer6   r7   rz   compileregexri   r(   r;   rI   rM   ra   rr   r   r   launch_instancemainr   r%   r&   r'   <module>r      s  0 # 	 	  '   L $ # 7 $ _n-.D9I>4Z0[_i()3t4Di/P+Q[*%&D1CZ,P(Q
 4Xx894*H56UM
d;
M:
;C
d#]3
4CJsO V
 ; 


 

$%'<	
	
"#%8	
	
#$k N(0-`6B7Z 74 %% zF r&   