a
    ø£Be¾0  ã                   @   s°  d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ zd dlZW n e	yb   d dl
ZY n0 zd dlmZ W n e	y’   d dlmZ Y n0 d dlmZ zd dlZW n  e	yÌ   dZeeƒd‚Y n0 g d¢Ze d¡Zd eee edd	œ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dd� e ¡ Zeej ƒd Z!e! "¡ �r–dZe#ej$ %d¡ƒdk�rŒed7 Ze&eƒ neej ej'ej(du ƒ dS )!é    N)ÚOptional)Úfiles)ÚPathz%Please install copier and jinja2-time)z".github/workflows/binder-on-pr.ymlz.github/workflows/build.ymlz#.github/workflows/check-release.ymlz#.github/workflows/enforce-label.ymlz".github/workflows/prep-release.ymlz%.github/workflows/publish-release.ymlz..github/workflows/update-integration-tests.ymlzbinder/postBuildú.eslintignoreú.eslintrc.jsz
.gitignorez.prettierignoreú.prettierrcú.stylelintrcz
RELEASE.mdzbabel.config.jsúconftest.pyújest.config.jsúpyproject.tomlúsetup.pyztsconfig.jsonztsconfig.test.jsonzui-tests/README.mdz&ui-tests/jupyter_server_test_config.pyzui-tests/package.jsonzui-tests/playwright.config.jsz^jupyter_server([^\w]|$)T)ÚtargetÚvcs_refÚinteractiveÚreturnc           .      C   s>  t | ƒ ¡ } | d }| d }| d }| ¡ s>d| ›�}t|ƒ‚t|ƒ�}t |¡}W d  ƒ n1 sf0    Y  d}	| ¡ rœt | 	¡ ¡}
|
 
di ¡ 
d¡}	|	du rþ| ¡ rÎtjtjddg| d	� d
¡ ¡ }	n|d }	d|	v rê|	dd… }	|	 dd¡ dd¡}	| d }| ¡ �rt |¡ | 
dd¡}d}t|tƒ�rP| 
dd¡}| 
d|¡}n|}d}| d  ¡ �rld}n| 
di ¡ 
dd¡�r†d}| d  ¡ �p¬| d  ¡ �p¬| d  ¡ }||||d |	| 
dd¡t| 
di ¡ 
d d¡ƒt| d!  ¡ ƒt|ƒ| 
d"i ¡ 
d#d$¡d%œ
}d&}ttj d'¡ƒd(k �r8tj||||d)d*� ntj||||d)d)d+� |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/¡�rZ| "d0¡ | #d1i ¡ |d1  ¡ D ]\}}||d1 |< �qd2|d1 v �r@|d1 d2= d3|d1 v �rd|d1 d3= n
| "d4¡ |d d5 |d d5< d6d7d8d9d:œ}| ¡ D ]J\}}||v �rŽ|| ||< | | }| ¡ �rŽ| $¡  | "d;|› �¡ �qŽt%dƒ &d<¡}| ¡ �}t |¡}W d  ƒ n1 �s0    Y  | #d=i ¡ | #d,i ¡ |d>  ¡ D ]N\}}||d= v �rj| d?d@¡|d= |< ||d, v �r@| d?d@¡|d, |< �q@dAD ]0}|| �r¼tt'||  ¡ ƒƒ||< n||= �q”| #dBdC¡ t| 
dD¡t(ƒ�r dC|dD v�r |dD  "dC¡ dE|v �r&dC|dE v�r&|dE  "dC¡ | )tj*|dFdG�¡ dH}| +dI¡D �]}| ,|¡}t-|ƒdk�rj�qH| .¡ �rx�qH| | } |  ¡ �s¸| j/j0d)d)dJ� t || ¡ | j1dk�rPd)}n˜| 2¡ }!|  2¡ }"|!|"k�rÖ�qH| 3¡ t4v �rèd.ndK}#|�rtdL|›dM|#› dN�ƒ�p|#ndK}|  ¡  !d/¡�r@t || ¡ | j1dk�rPd)}n| "dO|›�¡ �qH|�r| dP  ¡ �røzdQdl5}$W n" t6�y–   dR}t7|ƒ Y �nb0 t8 9¡ }%| dP  ¡ �}&|% :|&¡ W d  ƒ n1 �sÎ0    Y  | d }t | 	¡ ¡}
|%j
dSdTddU�}'|'du�r t(t;dVdW„ |' <¡ ƒƒ}(ng }(|
d  
d=g ¡|( |
d d=< |% =dX¡�rÒ|% dX¡D ]z\})}*t(t;dYdW„ |* <¡ ƒƒ}+|)|
d  
dZi ¡v �r¾|
d  
dZ¡du �rªi |
d dZ< |
d dZ |) |+ }+|+|
d dZ |)< �qV| )|$ *|
¡¡ | dP  $¡  | "d[¡ | d\ },|, ¡ �r|, $¡  | "d]¡ |D ]}-t7d^|-ƒ �q t7d_ƒ dS )`a#  Update an extension to the current JupyterLab

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

    zpackage.jsonr   r   zNo package.json exists in NÚprojectÚnamez--name)ÚcwdÚutf8ú@é   ú/Ú_ú-Z_temp_extensionÚauthorz<author_name>Ú ÚemailZfrontendzjupyter-configÚserverZ
jupyterlabZ	themePathÚthemer	   r
   zui-testsÚdescriptionz<description>Z	schemaDirZbinderÚ
repositoryÚurlz<repository)
ÚkindÚauthor_nameÚauthor_emailZlabextension_nameÚpython_nameZproject_short_descriptionZhas_settingsZ
has_binderÚtestr    z0https://github.com/jupyterlab/extension-templateÚ.©Ú8Ú0r*   T)r   ÚdataÚdefaults)r   r+   r,   ÚunsafeÚdevDependenciesz(Overwrite scripts in package.json? [n]: ÚyÚYzUpdated scripts in package.jsonÚscriptszinstall-extÚpreparez-package.json scripts must be updated manuallyZ	outputDirr   r   r   r   )ZeslintConfigZeslintIgnoreZprettierZ	stylelintzDELETED zstaging/package.jsonÚdependenciesÚresolutionsú~ú^)r1   r3   r.   ZstyleModulezstyle/index.jsZsideEffectsr   é   )ÚindentFÚ*)ÚparentsÚexist_okÚnzoverwrite "z"? [z]: zskipped _temp_extension/z	setup.cfgr   z5To update pyproject.toml, you need to install tomli-wÚoptionsZinstall_requires)Úfallbackc                 S   s   | ot  | ¡d u S ©N)ÚJUPYTER_SERVER_REQUIREMENTÚmatch©Úr© rD   ú_/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/jupyterlab/upgrade_extension.pyÚ<lambda>   ó    z"update_extension.<locals>.<lambda>zoptions.extras_requirec                 S   s   | S r?   rD   rB   rD   rD   rE   rF   .  rG   zoptional-dependencieszDELETED setup.cfgzMANIFEST.inzDELETED MANIFEST.inz**z2** Remove _temp_extensions directory when finished)>r   ÚresolveÚexistsÚRuntimeErrorÚopenÚjsonÚloadÚtomllibÚloadsÚ	read_textÚgetÚ
subprocessÚcheck_outputÚsysÚ
executableÚdecodeÚstripÚreplaceÚshutilÚrmtreeÚ
isinstanceÚdictÚboolÚtupleÚcopierÚ__version__ÚsplitZrun_autoZrun_copyÚitemsÚcopyÚinputÚupperÚ
startswithÚappendÚ
setdefaultÚunlinkr   ÚjoinpathÚsortedÚlistÚ
write_textÚdumpsÚrglobÚrelative_toÚstrÚis_dirÚparentÚmkdirr   Ú
read_bytesÚas_posixÚRECOMMENDED_TO_OVERRIDEÚtomli_wÚImportErrorÚprintÚconfigparserÚConfigParserÚ	read_fileÚfilterÚ
splitlinesÚhas_section).r   r   r   Zpackage_fileZpyproject_fileZ
setup_fileÚmsgÚfidr+   r%   Ú	pyprojectÚ
output_dirr   r$   r#   r"   Zhas_testZextra_contextÚtemplateZ	temp_dataÚkeyÚvalueÚwarningsÚchoiceZlintersÚfileZlinter_fileZroot_jlab_packageZroot_jlab_dataZoverride_pyprojectÚpÚrelpathZfile_targetZold_dataZnew_dataÚdefaultrx   ÚconfigZsetup_cfg_fileZrequirements_rawÚrequirementsÚextraZdeps_rawÚdepsZmanifest_inÚwarningrD   rD   rE   Úupdate_extension>   sh   

(ÿýÿ


ÿ
ý
öÿ*


ü


*

 



ÿ ý*
þÿÿ



r“   Ú__main__zUpgrade a JupyterLab extension)r   z
--no-inputÚ
store_truez!whether to prompt for information)ÚactionÚhelpÚpathÚstorezthe target path)r–   Útyper—   z	--vcs-refzthe template hash to checkout)r—   r�   z.copier-answers.ymlzrThis script won't do anything for copier template, instead execute in your extension directory:

    copier updater'   r(   z	 --UNSAFEF)NT))r{   rL   ÚrerY   rR   rT   Útypingr   rN   ry   ÚtomliÚimportlib.resourcesr   Zimportlib_resourcesÚpathlibr   r_   r�   rJ   rw   Úcompiler@   rq   r]   r“   Ú__name__ÚargparseÚArgumentParserÚparserÚadd_argumentÚ
parse_argsÚargsr˜   Zanswer_filerI   r^   r`   ra   rz   r   Úno_inputrD   rD   rD   rE   Ú<module>   sV   
 ÿ
þ  	


