a
    2b¯  ã                   @   sö   d dl Z d dlZd dlmZ d dlZd dlZd dlZd dlm	Z	 d dl
Z
zd dlmZ W n eyr   edƒ‚Y n0 dZedfdd„Zed	kròd dlZejd
dZejdddd ejddedd ejdded e ¡ Zeejejejdkƒ dS )é    N)ÚPath)ÚcookiecutterzPlease install cookiecutterz3.0Tc                 C   sl  t  | ¡} t  | d¡}t  | d¡}t  |¡s8td|  ƒ‚t|ƒ}t |¡}W d  ƒ n1 s`0    Y  t  |¡r–tj	t
jddg| d d¡ ¡ }n,|d }d	|v rÂ|d
d…  dd¡ dd¡}t  | d¡}t  |¡rât |¡ t| dd¡|d | dd¡t  t  | d¡¡rdndt  t  | d¡¡r0dnd| di ¡ dd¡|d}	d}
t|
|||	| d t |¡d }t t  ||¡t  |d¡¡ t t  |d¡¡D ]$}t t  |d|¡t  ||¡¡ q t t  |d¡¡ d}d D ]~}||vròqàt||  ¡ ƒD ].\}}| d!¡rd"}||| | d!d#¡< qt|| ƒD ]}| d!¡r>|| |= q>qàtt  |d¡ƒ}t |¡}W d  ƒ n1 s’0    Y  | d$¡rÎ|d$  ¡ D ]\}}||d$ |< q´n|d$  ¡ |d$< g }|ròtd%ƒ}nd}| ¡  d&¡r\| d'¡ | d(tƒ ¡ |d(  ¡ D ]\}}||d( |< q*d)|d( v rf|d( d)= n
| d*¡ |d+ d, |d+ d,< t  d+d-¡}t|ƒ}t |¡}W d  ƒ n1 s°0    Y  | d.tƒ ¡ | d$tƒ ¡ |d/  ¡ D ]N\}}||d. v r| d0d1¡|d. |< ||d$ v râ| d0d1¡|d$ |< qâd2D ]0}|| r^tt!||  ¡ ƒƒ||< n||= q6| d3d4¡ t"| d5¡tƒr¢d4|d5 vr¢|d5  d4¡ d6|v rÈd4|d6 vrÈ|d6  d4¡ t|d7ƒ }tj#||d8d9 W d  ƒ n1 sú0    Y  t$|ƒ}| %d:¡D ]"}t  &||¡}|dkr6q| '¡ rDqt  | |¡}t  |¡s~tj(t  )|¡d"d; t ||¡ nºt|d<ƒ}| *¡ }W d  ƒ n1 s¨0    Y  t|d<ƒ}| *¡ }W d  ƒ n1 sÜ0    Y  ||krôq|rtd=| ƒ}nd}| ¡  d&¡r*t ||¡ n| d>| ¡ q|D ]}t+d?|ƒ q@t+d@ƒ |rht+dAƒ dS )Ba8  Update an extension to the current JupyterLab

    target: str
        Path to the extension directory containing the extension
    branch: str [default: DEFAULT_COOKIECUTTER_BRANCH]
        Template branch to checkout
    interactive: bool [default: true]
        Whether to ask before overwriting content

    zpackage.jsonzsetup.pyzNo package.json exists in %sNz--name)ÚcwdÚutf8Únameú@é   ú/Ú_ú-Z_temp_extensionZauthorz<author_name>Údescriptionz<description>zjupyter-configÚyÚnZbinderÚ
repositoryÚurlz<repository)Zauthor_nameZlabextension_nameZproject_short_descriptionZhas_server_extensionZ
has_binderr   Úpython_namez7https://github.com/jupyterlab/extension-cookiecutter-ts)ÚtemplateZcheckoutÚ
output_dirÚextra_contextÚno_inputr   Z_tempF)ÚdevDependenciesÚdependenciesz
@phosphor/Tz@lumino/r   z(overwrite scripts in package.json? [n]: ÚYzUpdated scripts in package.jsonÚscriptszinstall-extz-package.json scripts must be updated manuallyZ
jupyterlabZ	outputDirzstaging/package.jsonr   Zresolutionsú~ú^)r   r   r   ZstyleModulezstyle/index.jsZsideEffectsÚfilesÚwé   )ÚindentÚ*)Úexist_okÚrbzoverwrite "%s"? [n]: zskipped _temp_extension/%sz**z2** Remove _temp_extensions directory when finishedzW** Phosphor dependencies were upgraded to lumino dependencies, update imports as needed),ÚospÚabspathÚjoinÚexistsÚRuntimeErrorÚopenÚjsonÚloadÚ
subprocessZcheck_outputÚsysÚ
executableÚdecodeÚstripÚreplaceÚshutilÚrmtreeÚdictÚgetr   ÚosÚlistdirÚmoveÚlistÚitemsÚ
startswithÚcopyÚinputÚupperÚappendÚ
setdefaultÚpkg_resourcesZresource_filenameÚsortedÚ
isinstanceÚdumpr   ÚrglobÚrelpathÚis_dirÚmakedirsÚdirnameÚreadÚprint)ÚtargetÚbranchÚinteractiveZpackage_fileZ
setup_fileZfidÚdatar   r   r   r   ÚfilenameZhas_phosphorr   ÚkeyÚvalueZ	temp_dataÚwarningsÚchoiceZroot_jlab_packageZroot_jlab_dataÚpathÚprE   Zfile_targetZold_dataZnew_dataZwarning© rV   ú;lib/python3.9/site-packages/jupyterlab/upgrade_extension.pyÚupdate_extension   sà    


(
"



ù
ÿ"
*



*

 0

((
rX   Ú__main__zUpgrade a JupyterLab extension)r   z
--no-inputÚ
store_truez!whether to prompt for information)ÚactionÚhelprT   Ústorezthe target path)r[   Útyper\   z--branchzthe template branch to checkout)r\   ÚdefaultF)r)   r5   Zos.pathrT   r#   r1   r+   r,   Úpathlibr   r@   Zcookiecutter.mainr   ÚImportErrorr'   ZDEFAULT_COOKIECUTTER_BRANCHrX   Ú__name__ÚargparseÚArgumentParserÚparserÚadd_argumentÚstrÚ
parse_argsÚargsrL   r   rV   rV   rV   rW   Ú<module>   s@    /þýþ