o
    ^i0                  	   @   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	y1   d dl
ZY nw d dlmZ d dlmZ zd dlZW n eyR   dZeedw g dZedZ	d#d	ed
ee deddfddZedkrd 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!" rdZe#ej$%dd kred!7 Ze&e dS eej ej'ej(d"u  dS dS )$    N)Optional)files)PathzNPlease install copier; you can use `pip install jupyterlab[upgrade-extension]`)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   s4  t |  } | d }| d }| d }| sd| }t|t|}t|}W d   n1 s3w   Y  d}	| rNt|	 }
|

di 
d}	|	du r| rgtjtjddg| d	d
 }	n|d }	d|	v ru|	dd }	|	dddd}	| d }| rt| |
dd}d}t|tr|
dd}|
d|}n|}d}| d  rd}n|
di 
ddrd}| 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 rtj||||d)d* ntj||||d)d)d+ |d  }t|}W d   n	1 s8w   Y  |
d,rV|d,  D ]\}}||d, |< qIn|d,  |d,< g }|rgtd-nd.}|  !d/r|"d0 |#d1i  |d1  D ]\}}||d1 |< qd2|d1 v r|d1 d2= d3|d1 v r|d1 d3= n|"d4 |d d5 |d d5< d6d7d8d9d:}| D ]%\}}||v r|| ||< | | }| r|$  |"d;|  qt%d&d<}| }t|}W d   n	1 sw   Y  |#d=i  |#d,i  |d>  D ]'\}}||d= v r/|d?d@|d= |< ||d, v r@|d?d@|d, |< qdAD ]}|| rYtt'||  ||< qD||= qD|#dBdC t|
dDt(r{dC|dD vr{|dD "dC dE|v rdC|dE vr|dE "dC |)tj*|dFdG dH}|+dID ]}|,|}t-|dkrq|. rq| | } |  s| j/j0d)d)dJ t||  | j1dkrd)}q|2 }!| 2 }"|!|"krq|3 t4v rd.ndK}#|rtdL|dM|# dNp|#ndK}|  !d/rt||  | j1dkrd)}q|"dO| q|r	| dP  rzdQdl5}$W n t6yF   dR}t7| Y nw t89 }%| dP  }&|%:|& W d   n	1 sbw   Y  | d }t|	 }
|%j
dSdTddU}'|'durt(t;dVdW |'< }(ng }(|
d 
d=g |( |
d d=< |%=dXr|%dXD ]=\})}*t(t;dYdW |*< }+|)|
d 
dZi v r|
d 
dZdu ri |
d dZ< |
d dZ |) |+ }+|+|
d dZ |)< q|)|$*|
 | 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@   /_-_temp_extensionauthorz<author_name> emailfrontendzjupyter-configserver
jupyterlab	themePaththemer	   r
   zui-testsdescriptionz<description>	schemaDirbinder
repositoryurlz<repository)
kindauthor_nameauthor_emaillabextension_namepython_nameproject_short_descriptionhas_settings
has_bindertestr&   z0https://github.com/jupyterlab/extension-template.80r4   T)r   datadefaults)r   r5   r6   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 manually	outputDirr   r   r   r   )eslintConfigeslintIgnoreprettier	stylelintzDELETED zstaging/package.jsondependenciesresolutions~^)r;   rB   r8   styleModulezstyle/index.js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optionsinstall_requires)fallbackc                 S   s   | ot | d u S N)JUPYTER_SERVER_REQUIREMENTmatchr rV   W/home/ubuntu/hpml_nyu/venv/lib/python3.10/site-packages/jupyterlab/upgrade_extension.py<lambda>  s    z"update_extension.<locals>.<lambda>zoptions.extras_requirec                 S   s   | S rQ   rV   rT   rV   rV   rW   rX   ,  s    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__splitrun_auto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   package_filepyproject_file
setup_filemsgfidr5   r,   	pyproject
output_dirr   r*   r)   r(   has_testextra_contexttemplate	temp_datakeyvaluewarningschoicelintersfilelinter_fileroot_jlab_packageroot_jlab_dataoverride_pyprojectprelpathfile_targetold_datanew_datadefaultr   configsetup_cfg_filerequirements_rawrequirementsextradeps_rawdepsmanifest_inwarningrV   rV   rW   update_extension;   s  


	













 








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 updater1   r2   z --trustF)NT))r   r]   rerj   rc   re   typingr   r_   r   tomliimportlib.resourcesr   pathlibr   rp   ModuleNotFoundErrorr   r[   r   compilerR   r   rn   r   __name__argparseArgumentParserparseradd_argument
parse_argsargsr   answer_filerZ   ro   rq   rr   r   r   no_inputrV   rV   rV   rW   <module>   sb   


  
