a
    2b>                     @   s  d Z ddlZddlZddlmZ ddlmZmZmZ ddlm	Z	m
Z
mZmZmZ ddlmZ ddlmZ dd	lmZmZmZmZmZmZmZmZmZmZmZmZmZ dd
l m!Z!m"Z"m#Z# ddl$m%Z% e&eZ'dddiidfe'd< dddiidfe'd< dddiidfe'd< dddiidfe'd< dddiidfe'd< ee'Z(dddiid fe(d!< ee'Z)d"d#diid$fe)d#< ee'Z*d%d&diid'fe*d&< ee'Z+d(d&diid)fe+d&< e&eZ,d*e,d+< d,e,d< d-e,d< d.e,d/< ee,Z-d0e-d1< ee,Z.d2e.d3< ee,Z/d4e/d3< e Z0ej12ej13e4ZG d5d deeZ5G d6d7 d7e5Z6G d8d" d"e5Z7G d9d: d:e5Z8G d;d< d<e5Z9G d=d% d%e5Z:G d>d? d?e5Z;G d@dA dAe5Z<G dBd( d(e5Z=G dCdD dDe5Z>G dEdF dFe5Z?G dGdH dHe5Z@G dId de5ZAdJZBG dKdL dLeZCeCjDZEeFdMkreGeE  dS )Nz"Jupyter LabExtension Entry Points.    N)copy)
JupyterAppbase_aliases
base_flags)BoolInstanceListUnicodedefault)
CoreConfig)DebugLogFileMixin   )HERE
AppOptionsbuildcheck_extensiondisable_extensionenable_extensionget_app_versioninstall_extensionlink_packagelist_extensionsuninstall_extensionunlink_packageupdate_extension)build_labextensiondevelop_labextension_pywatch_labextension)LabAppBaseExtensionAppshould_buildFz(Defer building the app after the action.zno-build	dev_buildTzBuild in development mode.z	dev-buildminimizez#Do not minimize a production build.zno-minimizeshould_cleanz,Cleanup intermediate files after the action.Zcleansplice_source*Splice source packages into app directory.zsplice-sourceCheckLabExtensionsAppshould_check_installed_onlyz)Check only if the extension is installed.	installedDevelopLabExtensionApp	overwritezOverwrite filesUpdateLabExtensionAppallzUpdate all extensionsUninstallLabExtensionAppzUninstall all extensionszBaseExtensionApp.app_dirzapp-dirzBaseExtensionApp.dev_buildzBaseExtensionApp.minimizez DebugLogFileMixin.debug_log_pathzdebug-log-pathzInstallLabExtensionApp.pinzpin-version-aszEnableLabExtensionsApp.levellevelzDisableLabExtensionsApp.levelc                   @   s   e Zd ZeZeZeZdZee	ddZ
eddddZeddddZedddd	d
ZeddddZeddddZeddddZee ddZeddd Zeddd Zdd Zdd Zdd ZdS )r   labT)
allow_none zThe app directory to targetconfighelp)Whether to build the app after the actionNzWhether to build in dev mode. Defaults to True (dev mode) if there are any locally linked extensions, else defaults to False (production mode).)r0   r3   r4   z:Whether to minimize a production build (defaults to True).FzFWhether temporary files should be cleaned up after building jupyterlabr%   z@The standard paths to look in for prebuilt JupyterLab extensionsr4   labextensions_pathc                 C   s   t  }|  |j|j S N)r   Zload_config_fileZextra_labextensions_pathr7   )selfr/    r:   7lib/python3.9/site-packages/jupyterlab/labextensions.py_default_labextensions_pathx   s    z,BaseExtensionApp._default_labextensions_pathr$   c                 C   s   t t| jd}|dS )N)app_dirz-spliced)r   r   r=   endswith)r9   versionr:   r:   r;   _default_splice_source~   s    z'BaseExtensionApp._default_splice_sourcec                 C   s   | j r| j trtd|  d |  }|rx| jrx| jd u rDd n| j }t| j | j	| j
| jd}t| j|| j|d W d    n1 s0    Y  d S )Nz-Cannot run lab extension commands in core app)r=   loggercore_configr$   )Zclean_staging
productionr"   app_options)r=   
startswithr   
ValueErrorZdebug_loggingrun_taskr    r!   r   logrB   r$   r   r#   r"   )r9   ZansrC   rD   r:   r:   r;   start   s    


zBaseExtensionApp.startc                 C   s   d S r8   r:   r9   r:   r:   r;   rG      s    zBaseExtensionApp.run_taskc                 C   s   dS )zA default format for messagesz%(message)sr:   rJ   r:   r:   r;   _log_format_default   s    z$BaseExtensionApp._log_format_default)__name__
__module____qualname__VERSIONr?   flagsaliasesnamer   r   rB   r	   r=   r   r    r!   r"   r#   r$   r   r7   r
   r<   r@   rI   rG   rK   r:   r:   r:   r;   r   [   s>   

c                   @   s*   e Zd ZdZeZeddddZdd ZdS )	InstallLabExtensionAppa  Install labextension(s)

     Usage

        jupyter labextension install [--pin-version-as <alias,...>] <package...>

    This installs JupyterLab extensions similar to yarn add or npm install.

    Pass a list of comma separate names to the --pin-version-as flag
    to use as aliases for the packages providers. This is useful to
    install multiple versions of the same extension.
    These can be uninstalled with the alias you provided
    to the flag, similar to the "alias" feature of yarn add.
    r1   Tz%Pin this version with a certain aliasr2   c                    s<   j d jpt g_t fddtjD S )N,c                    sF   g | ]>\}}t ||t k r$ | nd tjjjjddqS )Nr=   rA   rB   r7   )pinrD   )r   lenr   r=   rH   rB   r7   ).0iargZpinned_versionsr9   r:   r;   
<listcomp>   s   z3InstallLabExtensionApp.run_task.<locals>.<listcomp>)rV   split
extra_argsosgetcwdany	enumeraterJ   r:   r[   r;   rG      s
    zInstallLabExtensionApp.run_taskN)	rL   rM   rN   descriptioninstall_aliasesrQ   r	   rV   rG   r:   r:   r:   r;   rS      s   rS   c                   @   sb   e Zd ZdZeZeddddZeddddZeddddZ	eddddZ
ed	dd
dZdd ZdS )r)   zDevelop labextensionFTzWhether to do a user installr2   z Use the sys.prefix as the prefixzWhether to overwrite fileszWhether to use a symlinkr1   z<Full path to labextensions dir (probably use prefix or user)c              
   C   sD   | j pt g| _ | j D ]&}t|| j| j| j| j| j| j	d qdS )z Add config for this labextension)user
sys_prefixlabextensions_dirrA   r*   symlinkN)
r^   r_   r`   r   re   rf   rg   rH   r*   rh   )r9   rZ   r:   r:   r;   rG      s
    
zDevelopLabExtensionApp.run_taskN)rL   rM   rN   rc   develop_flagsrP   r   re   rf   r*   rh   r	   rg   rG   r:   r:   r:   r;   r)      s   c                   @   sh   e Zd ZdZeddddZeddddZeddddZee	j
ed	dd
dZdddddZdd ZdS )BuildLabExtensionAppBuild labextensionr1   Tz,Sets the url for static assets when buildingr2   FBuild in development modeGenerate source mapsstaging7Directory containing core application package.json filezBuildLabExtensionApp.static_url BuildLabExtensionApp.developmentBuildLabExtensionApp.source_mapBuildLabExtensionApp.core_path)z
static-urldevelopment
source-map	core-pathc                 C   sB   | j pt g| _ t| j d | j| j| jp,d | j| jp8d d d S )Nr   )rA   rs   
static_url
source_map	core_path)	r^   r_   r`   r   rH   rs   rv   rw   rx   rJ   r:   r:   r;   rG      s    zBuildLabExtensionApp.run_taskN)rL   rM   rN   rc   r	   rv   r   rs   rw   r_   pathjoinr   rx   rQ   rG   r:   r:   r:   r;   rj      s&   rj   c                   @   sX   e Zd ZdZeddddZeddddZeej	
eddddZd	d
ddZdd ZdS )WatchLabExtensionAppWatch labextensionTrl   r2   Frm   rn   ro   rp   rq   rr   )rs   rt   ru   c                 C   sB   | j pt g| _ | j}t| j d || j| j| j| jp8d d d S )Nr   )rA   rs   rw   rx   )	r^   r_   r`   r7   r   rH   rs   rw   rx   )r9   r7   r:   r:   r;   rG      s
    zWatchLabExtensionApp.run_taskN)rL   rM   rN   rc   r   rs   rw   r	   r_   ry   rz   r   rx   rQ   rG   r:   r:   r:   r;   r{      s   r{   c                   @   s*   e Zd ZdZeZeddddZdd ZdS )	r+   Update labextension(s)FTz Whether to update all extensionsr2   c                    s^   | j s| js| jd dS t| j| j| j| jd | j rFtd dS t	 fdd| jD S )NzESpecify an extension to update, or use --all to update all extensionsFrU   TZall_rD   c                    s   g | ]}t | d qS ))rR   rD   )r   rX   rZ   rD   r:   r;   r\     s   z2UpdateLabExtensionApp.run_task.<locals>.<listcomp>)
r,   r^   rH   warnr   r=   rB   r7   r   ra   rJ   r:   r   r;   rG     s    
zUpdateLabExtensionApp.run_taskN)	rL   rM   rN   rc   update_flagsrP   r   r,   rG   r:   r:   r:   r;   r+     s   c                   @   s&   e Zd ZdZeddddZdd ZdS )LinkLabExtensionAppz
    Link local npm packages that are not lab extensions.

    Links a package to the JupyterLab build process. A linked
    package is manually re-installed from its source location when
    `jupyter lab build` is run.
    Tr5   r2   c                    sB   | j pt g| _ t| j| j| j| jd t fdd| j D S )Nr=   rA   r7   rB   c                    s   g | ]}t | d qS r   )r   r   optionsr:   r;   r\   ,  s
   z0LinkLabExtensionApp.run_task.<locals>.<listcomp>	r^   r_   r`   r   r=   rH   r7   rB   ra   rJ   r:   r   r;   rG   &  s    zLinkLabExtensionApp.run_taskN)rL   rM   rN   rc   r   r    rG   r:   r:   r:   r;   r     s
   r   c                   @   s   e Zd ZdZdd ZdS )UnlinkLabExtensionAppzUnlink packages by name or pathc                    sB   | j pt g| _ t| j| j| j| jd t fdd| j D S )Nr   c                    s   g | ]}t | d qS r   )r   r   r   r:   r;   r\   =  s
   z2UnlinkLabExtensionApp.run_task.<locals>.<listcomp>r   rJ   r:   r   r;   rG   7  s    zUnlinkLabExtensionApp.run_taskNrL   rM   rN   rc   rG   r:   r:   r:   r;   r   4  s   r   c                   @   s*   e Zd ZdZeZeddddZdd ZdS )	r-   z!Uninstall labextension(s) by nameFTz#Whether to uninstall all extensionsr2   c                    sD   j pt g_ tjjjjd t fddj D S )Nr   c                    s   g | ]}t |j d qS )r~   )r   r,   r   r   r9   r:   r;   r\   S  s
   z5UninstallLabExtensionApp.run_task.<locals>.<listcomp>r   rJ   r:   r   r;   rG   L  s    z!UninstallLabExtensionApp.run_taskN)	rL   rM   rN   rc   uninstall_flagsrP   r   r,   rG   r:   r:   r:   r;   r-   E  s   c                   @   s   e Zd ZdZdd ZdS )ListLabExtensionsAppz List the installed labextensionsc                 C   s"   t t| j| j| j| jdd d S )NrU   r   )r   r   r=   rH   rB   r7   rJ   r:   r:   r;   rG   ^  s    zListLabExtensionsApp.run_taskNr   r:   r:   r:   r;   r   [  s   r   c                   @   s0   e Zd ZdZeZedddjddZdd Z	d	S )
EnableLabExtensionsAppzEnable labextension(s) by namerf   2Level at which to enable: sys_prefix, user, systemr6   Tr3   c                    s2   t jjjjd  fddjD  d S )NrU   c                    s   g | ]}t | jd qS )rD   r.   )r   r.   r   rD   r9   r:   r;   r\   n      z3EnableLabExtensionsApp.run_task.<locals>.<listcomp>r   r=   rH   rB   r7   r^   rJ   r:   r   r;   rG   j  s
    zEnableLabExtensionsApp.run_taskN)
rL   rM   rN   rc   enable_aliasesrQ   r	   tagr.   rG   r:   r:   r:   r;   r   d  s   r   c                   @   s0   e Zd ZdZeZedddjddZdd Z	d	S )
DisableLabExtensionsAppzDisable labextension(s) by namerf   r   r6   Tr   c                    s2   t jjjjd  fddjD  d S )NrU   c                    s   g | ]}t | jd qS r   )r   r.   r   r   r:   r;   r\   {  r   z4DisableLabExtensionsApp.run_task.<locals>.<listcomp>r   rJ   r:   r   r;   rG   w  s
    z DisableLabExtensionsApp.run_taskN)
rL   rM   rN   rc   disable_aliasesrQ   r	   r   r.   rG   r:   r:   r:   r;   r   q  s   r   c                   @   s*   e Zd ZdZeZeddddZdd ZdS )	r&   zCheck labextension(s) by nameFTz;Whether it should check only if the extensions is installedr2   c                    sD   t jjjjd t fddjD }|s@d d S )NrU   c                 3   s   | ]}t |j d V  qdS ))r(   rD   N)r   r'   r   r   r:   r;   	<genexpr>  s   z1CheckLabExtensionsApp.run_task.<locals>.<genexpr>r   )r   r=   rH   rB   r7   r,   r^   exit)r9   Zall_enabledr:   r   r;   rG     s    zCheckLabExtensionsApp.run_taskN)	rL   rM   rN   rc   check_flagsrP   r   r'   rG   r:   r:   r:   r;   r&   ~  s   a  
jupyter labextension list                        # list all configured labextensions
jupyter labextension develop                     # develop a prebuilt labextension
jupyter labextension build                       # build a prebuilt labextension
jupyter labextension watch                       # watch a prebuilt labextension
jupyter labextension install <extension name>    # install a labextension
jupyter labextension uninstall <extension name>  # uninstall a labextension
c                       s   e Zd ZdZdZeZdZeZ	e
edfedfedfedfedfed	fed
fedfedfedfedfedfdZ fddZ  ZS )LabExtensionAppz-Base jupyter labextension command entry pointzjupyter labextensionzWork with JupyterLab extensionszInstall labextension(s)zDevelop labextension(s)rk   r|   r}   zUninstall labextension(s)zList labextensionszLink labextension(s)zUnlink labextension(s)zEnable labextension(s)zDisable labextension(s)zCheck labextension(s))installZdevelopr   ZwatchupdateZ	uninstalllistlinkunlinkenabledisablecheckc                    s0   t t|   dt| j}| d|  dS )z)Perform the App's functions as configuredz, z)Please supply at least one subcommand: %sN)superr   rI   rz   sortedsubcommandsr   )r9   Zsubcmds	__class__r:   r;   rI     s    zLabExtensionApp.start)rL   rM   rN   __doc__rR   rO   r?   rc   	_examplesZexamplesdictrS   r)   rj   r{   r+   r-   r   r   r   r   r   r&   r   rI   __classcell__r:   r:   r   r;   r     s(   r   __main__)Hr   r_   sysr   Zjupyter_core.applicationr   r   r   Z	traitletsr   r   r   r	   r
   Zjupyterlab.coreconfigr   Zjupyterlab.debuglogr   Zcommandsr   r   r   r   r   r   r   r   r   r   r   r   r   Zfederated_labextensionsr   r   r   Zlabappr   r   rP   r   ri   r   r   rQ   rd   r   r   rO   ry   abspathdirname__file__r   rS   r)   rj   r{   r+   r   r   r-   r   r   r   r&   r   r   Zlaunch_instancemainrL   r   r:   r:   r:   r;   <module>   s   <








<'	
 
