a
    2b
c                     @   sH  d Z ddlZddlZddlmZ ddlmZmZm	Z	m
Z
 ddl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 dd	lmZ dd
lmZmZmZ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m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7m8Z8 ddl9m:Z: ddl;m<Z<m=Z=m>Z> ddl?m@Z@ dZAdZBeCe	ZDdeDd< deDd< deDd< deDd< deDd< d eDd!< eCe
ZEd"d#d$iid%feEd< d"dd&iid'feEd(< d"d)d$iid*feEd+< e!ZFe, ZGeFeGkrd,e!eGf ZFd-ZHG d.d" d"ee4ZIeCe	ZJd/eJd< d0ZKeCe
ZLd1d2d$iid3eK feLd2< d1d4d$iid5feLd4< d1d6d$iid7feLd6< d1d8d$iid9eK feLd8< G d:d; d;e%ZMG d<d1 d1eZNG d=d> d>eZOG d?d@ d@eZPG dAdB dBeZQG dCdD dDeZRG dEdF dFeZSG dGdH dHeZTeCe	ZUeUVdIdJdKdLdMdNdOdPdQdR	 G dSdT dTeeZWeWjX ZYZZe[dUkrDeY  dS )Vz#A tornado based Jupyter lab server.    N)join)
JupyterAppNoStartbase_aliases
base_flags)version_info)flags)url_path_join)LabServerAppLicensesAppWorkspaceExportAppWorkspaceImportAppWorkspaceListApp)NBClassicConfigShimMixin)BoolInstanceUnicodedefault   )__version__)DEV_DIRHERE
AppOptionsbuildclean
ensure_appensure_core
ensure_devget_app_dirget_app_versionget_user_settings_dirget_workspaces_dirpjoinwatch	watch_dev)
CoreConfig)DebugLogFileMixin)BuilderBuildHandler
build_path)ErrorHandler)ExtensionHandlerExtensionManagerextensions_handler_path)YjsEchoWebSocketzYou're running JupyterLab from source.
If you're working on the TypeScript sources of JupyterLab, try running

    jupyter lab --dev-mode --watch


to have the system incrementally watch and build JupyterLab for you, as you
make changes.
zH
Running the core application with no additional extensions or settings
zLabBuildApp.app_dirapp-dirzLabBuildApp.namenamezLabBuildApp.versionversionzLabBuildApp.dev_buildz	dev-buildzLabBuildApp.minimizeminimizez DebugLogFileMixin.debug_log_pathzdebug-log-pathLabBuildApp	dev_buildTzBuild in development mode.Fz#Do not minimize a production build.zno-minimizesplice_source*Splice source packages into app directory.splice-sourcez%s (dev), %s (app)a  Build failed.
Troubleshooting: If the build failed due to an out-of-memory error, you
may be able to fix it by disabling the `dev_build` and/or `minimize` options.

If you are building via the `jupyter lab build` command, you can disable
these options like so:

jupyter lab build --dev-build=False --minimize=False

You can also disable these options for all JupyterLab builds by adding these
lines to a Jupyter config file named `jupyter_config.py`:

c.LabBuildApp.minimize = False
c.LabBuildApp.dev_build = False

If you don't already have a `jupyter_config.py` file, you can create one by
adding a blank file of that name to any of the Jupyter config directories.
The config directories can be listed by running:

jupyter --paths

Explanation:

- `dev-build`: This option controls whether a `dev` or a more streamlined
`production` build is used. This option will default to `False` (i.e., the
`production` build) for most users. However, if you have any labextensions
installed from local files, this option will instead default to `True`.
Explicitly setting `dev-build` to `False` will ensure that the `production`
build is used in all circumstances.

- `minimize`: This option controls whether your JS bundle is minified
during the Webpack build, which helps to improve JupyterLab's overall
performance. However, the minifier plugin used by Webpack is very memory
intensive, so turning it off may help the build finish successfully in
low-memory environments.
c                   @   s   e Zd ZeZdZeZeZe	e
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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 )r3   z
    Build the JupyterLab application

    The application is built in the JupyterLab app directory in `/staging`.
    When the build is complete it is put in the JupyterLab app `/static`
    directory, where it is used to serve the application.
    T
allow_none zThe app directory to build inconfighelp
JupyterLabz!The name of the built applicationz$The version of the built applicationNzWhether to build in dev mode. Defaults to True (dev mode) if there are any locally linked extensions, else defaults to False (production mode).)r9   r<   r=   z:Whether to minimize a production build (defaults to True).Fz4Whether to clean before building (defaults to False)r6   c                 C   s   | j p
t }t|| j| j| jd}| jdt |   | j	rZ| jd|  t
|d | jd| z2| jd u rxd n| j }t| j| j||| jd W n0 ty } ztt |W Y d }~n
d }~0 0 W d    n1 s0    Y  d S )N)app_dirloggercore_configr5   zJupyterLab %szCleaning %sapp_optionszBuilding in %s)r0   r1   rC   
productionr2   )r?   r   r   logrA   r5   infor1   Zdebug_logging	pre_cleanr   r4   r   r0   r2   	ExceptionprintbuildFailureMsg)selfr?   rC   rD   e rM   0lib/python3.9/site-packages/jupyterlab/labapp.pystart   s$    



zLabBuildApp.start)__name__
__module____qualname__r1   descriptionbuild_aliasesaliasesbuild_flagsr   r   r%   rA   r   r?   r0   r   r4   r2   rG   r5   rO   rM   rM   rM   rN   r3   s   s6   zLabCleanApp.app_dirzSWARNING: this will delete all of your extensions, which will need to be reinstalledLabCleanApp
extensions$Also delete <app-dir>/extensions.
%ssettingsAlso delete <app-dir>/settingsstaticAlso delete <app-dir>/staticall3Delete the entire contents of the app directory.
%sc                   @   s4   e Zd ZedZedZedZedZedZdS )LabCleanAppOptionsFTN)	rP   rQ   rR   r   rX   rZ   Zstagingr\   r^   rM   rM   rM   rN   r`      s
   r`   c                   @   s~   e Zd ZeZdZeZeZe	e
ddZeddddZeddde dZeddd	dZeddd
dZeddde dZdd ZdS )rW   a	  
    Clean the JupyterLab application

    This will clean the app directory by removing the `staging` directories.
    Optionally, the `extensions`, `settings`, and/or `static` directories,
    or the entire contents of the app directory, can also be removed.
    Tr8   r:   zThe app directory to cleanr;   FrY   r[   r]   r_   c              	   C   s2   t | j| j| j| j| j| j| jd}t|d d S )N)r@   rA   r?   rX   rZ   r\   r^   rB   )	r`   rE   rA   r?   rX   rZ   r\   r^   r   )rK   rC   rM   rM   rN   rO      s    	zLabCleanApp.startN)rP   rQ   rR   r1   rS   clean_aliasesrU   clean_flagsr   r   r%   rA   r   r?   r   ext_warn_msgrX   rZ   r\   r^   rO   rM   rM   rM   rN   rW      s   c                   @   s   e Zd ZeZdZdd ZdS )
LabPathAppaD  
    Print the configured paths for the JupyterLab application

    The application path can be configured using the JUPYTERLAB_DIR
        environment variable.
    The user settings path can be configured using the JUPYTERLAB_SETTINGS_DIR
        environment variable or it will fall back to
        `/lab/user-settings` in the default Jupyter configuration directory.
    The workspaces path can be configured using the JUPYTERLAB_WORKSPACES_DIR
        environment variable or it will fall back to
        '/lab/workspaces' in the default Jupyter configuration directory.
    c                 C   s.   t dt   t dt   t dt   d S )NzApplication directory:   %szUser Settings directory: %szWorkspaces directory: %s)rI   r   r    r!   rK   rM   rM   rN   rO      s    zLabPathApp.startN)rP   rQ   rR   r1   rS   rO   rM   rM   rM   rN   rd      s   rd   c                   @   s    e Zd ZeZeddd ZdS )LabWorkspaceExportAppworkspaces_dirc                 C   s   t  S Nr!   re   rM   rM   rN   _default_workspaces_dir   s    z-LabWorkspaceExportApp._default_workspaces_dirNrP   rQ   rR   r1   r   rj   rM   rM   rM   rN   rf      s   rf   c                   @   s    e Zd ZeZeddd ZdS )LabWorkspaceImportApprg   c                 C   s   t  S rh   ri   re   rM   rM   rN   rj     s    z-LabWorkspaceImportApp._default_workspaces_dirNrk   rM   rM   rM   rN   rl     s   rl   c                   @   s    e Zd ZeZeddd ZdS )LabWorkspaceListApprg   c                 C   s   t  S rh   ri   re   rM   rM   rN   rj     s    z+LabWorkspaceListApp._default_workspaces_dirNrk   rM   rM   rM   rN   rm     s   rm   c                       sl   e Zd ZeZdZe Zeej d fed< e	e	j d fed< e
e
j d fed<  fddZ  ZS )LabWorkspaceAppz
    Import or export a JupyterLab workspace or list all the JupyterLab workspaces

    There are three sub-commands for export, import or listing of workspaces. This app
        should not otherwise do any work.
    r   Zexportimportlistc                    sB   z t    td | d W n ty2   Y n0 | d d S )Nz6One of `export`, `import` or `list` must be specified.r   r   )superrO   rI   exitr   re   	__class__rM   rN   rO   +  s    
zLabWorkspaceApp.start)rP   rQ   rR   r1   rS   dictsubcommandsrf   
splitlinesrl   rm   rO   __classcell__rM   rM   rs   rN   rn     s   rn   c                   @   s|   e Zd ZeZeddddZeddddZi ej	ddiZ	i ej
d	d d
diidfiZ
eddd Zeddd ZdS )LabLicensesAppFT  Whether to start the app in dev mode. Uses the unpublished local
        JavaScript packages in the `dev_mode` folder.  In this case JupyterLab will
        show a red stripe at the top of the page.  It can only be used if JupyterLab
        is installed as `pip install -e .`.
        r;   r:   z,The app directory for which to show licensesr/   zLabLicensesApp.app_dirdev-modedev_mode2Start the app in dev mode for running from source.r?   c                 C   s   t  S rh   )r   re   rM   rM   rN   _default_app_dirS  s    zLabLicensesApp._default_app_dir
static_dirc                 C   s   t | jdS Nr\   r"   r?   re   rM   rM   rN   _default_static_dirW  s    z"LabLicensesApp._default_static_dirN)rP   rQ   rR   r1   r   r|   r   r?   r   rU   r   r   r~   r   rM   rM   rM   rN   ry   5  s4   


ry   zServerApp.ipzServerApp.portzServerApp.port_retrieszServerApp.keyfilezServerApp.certfilezServerApp.client_cazServerApp.root_dirzServerApp.browserzServerApp.pylab)	Zipportzport-retriesZkeyfileZcertfilez	client-caznotebook-dirZbrowserZpylabc                
       s  e Zd ZeZdZdZdZdZdZe	Z	e	
ddi de	d	< 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< d ddiidfed< d ddiidfed< eeej d feej d feej d feej d feej d feej d feej d fdZedddd Zedd!d Zedd"d Zed#dd$d Zee dd%d Zee 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!ed'ddd Z"ed'dd,d Z#ed'ddd Z$e%d-d.d/ Z&e%d0d1d2 Z'e%d3d4d5 Z(e%d6d7d8 Z)e%d9d:d; Z*e%d<d=d> Z+e%d?d@dA Z,e%dBdCdD Z-e%dEdFdG Z.e%dHdIdJ Z/dKdL Z0 fdMdNZ1 fdOdPZ2dS fdQdR	Z3  Z4S )TLabAppZlabr>   TaB  
    JupyterLab - An extensible computational environment for Jupyter.

    This launches a Tornado based HTML Server that serves up an
    HTML5/Javascript JupyterLab client.

    JupyterLab has three different modes of running:

    * Core mode (`--core-mode`): in this mode JupyterLab will run using the JavaScript
      assets contained in the installed `jupyterlab` Python package. In core mode, no
      extensions are enabled. This is the default in a stable JupyterLab release if you
      have no extensions installed.
    * Dev mode (`--dev-mode`): uses the unpublished local JavaScript packages in the
      `dev_mode` folder.  In this case JupyterLab will show a red stripe at the top of
      the page.  It can only be used if JupyterLab is installed as `pip install -e .`.
    * App mode: JupyterLab allows multiple JupyterLab "applications" to be
      created by the user with different combinations of extensions. The `--app-dir` can
      be used to set a directory for different applications. The default application
      path can be found using `jupyter lab path`.
    a  
        jupyter lab                       # start JupyterLab
        jupyter lab --dev-mode            # start JupyterLab in development mode, with no extensions
        jupyter lab --core-mode           # start JupyterLab in core mode, with no extensions
        jupyter lab --app-dir=~/myjupyterlabapp # start JupyterLab with a particular set of extensions
        jupyter lab --certfile=mycert.pem # use SSL/TLS certificate
    r#   zLabApp.watchzLabApp.app_dirr/   	core_modezStart the app in core mode.z	core-moder|   r}   r{   zStart the app in watch mode.r5   r6   r7   expose_app_in_browserzExpose the global app instance to browser via window.jupyterapp.
        It is also available via the deprecated window.jupyterlab name.zexpose-app-in-browserextensions_in_dev_modez%Load prebuilt extensions in dev-mode.zextensions-in-dev-modecollaborativez4Whether to enable collaborative mode (experimental).r   )r   r   pathpathsZ	workspaceZ
workspacesZlicensesz/labz'The default URL to redirect to from `/`r;   z8The override url for static lab assets, typically a CDN.z>The override url for static lab theme assets, typically a CDN.Nz,The app directory to launch JupyterLab from.z The directory for user settings.zThe directory for workspacesFa  Whether to start the app in core mode. In this mode, JupyterLab
        will run using the JavaScript assets that are within the installed
        JupyterLab Python package. In core mode, third party extensions are disabled.
        The `--dev-mode` flag is an alias to this to be used when the Python package
        itself is installed in development mode (`pip install -e .`).
        rz   aW  Whether to load prebuilt extensions in dev mode. This may be
        useful to run and test prebuilt extensions in development installs of
        JupyterLab. APIs in a JupyterLab development install may be
        incompatible with published packages, so prebuilt extensions compiled
        against published packages may not work correctly.z&Whether to serve the app in watch modezJWhether to expose the global app instance to browser via window.jupyterlabr?   c                 C   s    t  }| jrt}n
| jrt}|S rh   )r   r   r   r|   r   )rK   r?   rM   rM   rN   r~     s    zLabApp._default_app_dirZapp_settings_dirc                 C   s   t | jdS )NrZ   r   re   rM   rM   rN   _default_app_settings_dir  s    z LabApp._default_app_settings_dirapp_versionc                 C   s   t S rh   )r   re   rM   rM   rN   _default_app_version  s    zLabApp._default_app_versioncache_filesc                 C   s   dS )NFrM   re   rM   rM   rN   _default_cache_files  s    zLabApp._default_cache_filesZschemas_dirc                 C   s   t | jdS )NZschemasr   re   rM   rM   rN   _default_schemas_dir  s    zLabApp._default_schemas_dirtemplates_dirc                 C   s   t | jdS r   r   re   rM   rM   rN   _default_templates_dir
  s    zLabApp._default_templates_dirZ
themes_dirc                 C   s   | j r
dS t| jdS )Nr:   Zthemes)override_theme_urlr"   r?   re   rM   rM   rN   _default_themes_dir  s    zLabApp._default_themes_dirr   c                 C   s   t | jdS r   r   re   rM   rM   rN   r     s    zLabApp._default_static_dirZstatic_url_prefixc                 C   s,   | j r| j S dj| jd}t| jj|S d S )Nz/static/{name}/)r0   )override_static_urlformatr0   ujoin	serverappZbase_url)rK   Z
static_urlrM   rM   rN   _default_static_url_prefix  s    z!LabApp._default_static_url_prefixZ	theme_urlc                 C   s   | j r| j S dS )Nr:   )r   re   rM   rM   rN   _default_theme_url!  s    zLabApp._default_theme_urlc                 C   s
  | j s| jttj r*d| _ | jd | jsB| jt	tj rTd| _| jd | j
rr| j rr| jd d| _
| j r| jr| jd d| _ | jrtt	d}|g| _|g| _| jsg | _g | _nB| j rttd}|g| _|g| _g | _g | _n| jg| _| jg| _d S )NTzRunning JupyterLab in core modezRunning JupyterLab in dev modez3Cannot watch in core mode, did you mean --dev-mode?Fz3Conflicting modes, choosing dev_mode over core_moder\   )r   r?   
startswithr   osseprE   rF   r|   r   r#   warnr   Zstatic_pathsZtemplate_pathsr   labextensions_pathextra_labextensions_pathr   r   )rK   Zdev_static_dirrM   rM   rN   initialize_templates'  s6    


zLabApp.initialize_templatesc                    s   t    d S rh   )rq   initialize_settingsre   rs   rM   rN   r   L  s    zLabApp.initialize_settingsc                    s  g } j jjdi }|d j o* j  |d j oB j   j|d<  j j|d<  j|d<  j j|d<  j	|d<  j j
j|d	< tt|d
<  jdt   jd j  t j j j j  jd}t j|d}ttd|if}|| dtf}|| d} jr8 jt  t j nz jr` jst  j  jt! nR jrrt  j t" j}|r fdd|D   j#t$d|if}	||	 d} jr jd  jrt% j nt|d d|d< d _& js"|s"t'|d}
t(t)d|
if}|| d j j*v r j j*}|d }||d< |d |d< |d |d< t+|d|d< t, j d r j j-|d!< t./d"d#}||d< | j jjd<  j01| t2 3  d S )$NZpage_config_dataZbuildAvailableZ
buildCheckZdevModetokenZexposeAppInBrowserZ
quitButtonr   Zallow_hidden_filesZnotebookVersionz#JupyterLab extension loaded from %sz&JupyterLab application directory is %s)r@   r?   r   r5   rB   builderz/api/yjs/(.*)Fc                    s   g | ]} j |qS rM   )rE   error).0msgre   rM   rN   
<listcomp>|      z.LabApp.initialize_handlers.<locals>.<listcomp>messagesTz!Starting JupyterLab watch mode...Zmanager
hub_prefixZ	hubPrefixZhub_hostZhubHostuserZhubUserzuser-redirectZshareUrlserver_nameZhubServerNameZJUPYTERHUB_API_TOKENr:   )4r   Zweb_apprZ   
setdefaultr   r|   r   r   Zquit_buttonr   Zcontents_managerZallow_hiddenjsondumpsjpserver_version_inforE   rF   r   r?   r   r   r   r5   r'   r)   r(   appendr.   	CORE_NOTEstripr   r#   r   DEV_NOTEr   Zapp_urlr*   r$   r   r,   r-   r+   tornado_settingsr   hasattrr   r   getenvhandlersextendrq   initialize_handlers)rK   r   Zpage_configZbuild_handler_optionsr   Zbuild_handlerZyjs_echo_handlerZerroredZmsgsZhandlerZext_managerZext_handlerr   r   Z	api_tokenrs   re   rN   r   P  s~    











zLabApp.initialize_handlersc                    s   t    dS )zMSubclass because the ExtensionApp.initialize() method does not take argumentsN)rq   
initialize)rK   argvrs   rM   rN   r     s    zLabApp.initialize)N)5rP   rQ   rR   r1   r0   Zapp_nameZload_other_extensionsrS   ZexamplesrU   updater   ru   r3   rw   rW   rd   rn   ry   rv   r   Zdefault_urlr   r   r?   r    Zuser_settings_dirr!   rg   r   r   r|   r   r#   r5   r   r   r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   rx   rM   rM   rs   rN   r   j  s   

















%Xr   __main__)\__doc__r   r   Zos.pathr   r"   Zjupyter_core.applicationr   r   r   r   Zjupyter_server._versionr   r   Zjupyter_server.serverappr   Zjupyter_server.utilsr	   r   Zjupyterlab_serverr
   r   r   r   r   Znbclassic.shimr   Z	traitletsr   r   r   r   Z_versionr   Zcommandsr   r   r   r   r   r   r   r   r   r   r    r!   r#   r$   Z
coreconfigr%   Zdebuglogr&   Zhandlers.build_handlerr'   r(   r)   Zhandlers.error_handlerr*   Z"handlers.extension_manager_handlerr+   r,   r-   Zhandlers.yjs_echo_wsr.   r   r   ru   rT   rV   r1   r   rJ   r3   ra   rc   rb   r`   rW   rd   rf   rl   rm   rn   ry   rU   r   r   Zlaunch_instancemainZlaunch_new_instancerP   rM   rM   rM   rN   <module>   s   D



%8

( '  H

