o
    iB                     @   s  d Z ddlZ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
Z
ddlmZ z
ddlmZmZ W n eyE   ddlmZmZ Y nw ddlmZmZ ddlmZ ddlmZmZmZ ddlmZ dd	lmZ dd
lmZ zddl m!Z! W n ey   ddl"m!Z! Y nw ddl#m$Z$ e% Z&e'e(e)Z*							d"ddZ+						d#ddZ,	d$ddZ-	d%ddZ.dd Z/d&ddZ0d&ddZ1d'ddZ2d d! Z3dS )(z?Utilities for installing Javascript extensions for the notebook    N)Path)PackageNotFoundErrorversion)basenamenormpath)join)ENV_JUPYTER_PATHSYSTEM_JUPYTER_PATHjupyter_data_dir)ensure_dir_exists)ArgumentConflict)get_federated_extensions)load   )_test_overlapTFc              
   C   s  d}t |||d}	t|	 t| ttfrd}
t|
|s"tt| }tt|	|}|rQt	j
|rQ|r:|d|  t	j
|rLt	j
|sLt| nt	| t	jt	j
|dd |rt	j
| } t	j
|s|rw|d| d|   z	t	| | W |S  ty } zt d	rd
}
t|
| d}~ww t	j
|std| |S t	j
| rtt	j
| d} t	| D ]:\}}}t||t| d }t	j
|s|r|d|  t	| |D ]}t||}t||}t|||d qq|S | }t|||d |S )aZ  Install a prebuilt extension for JupyterLab

    Stages files and/or directories into the labextensions directory.
    By default, this compares modification time, and only stages files that need updating.
    If `overwrite` is specified, matching files are purged before proceeding.

    Parameters
    ----------

    path : path to file, directory, zip or tarball archive, or URL to install
        By default, the file will be installed with its base name, so '/path/to/foo'
        will install to 'labextensions/foo'. See the destination argument below to change this.
        Archives (zip or tarballs) will be extracted into the labextensions directory.
    user : bool [default: False]
        Whether to install to the user's labextensions directory.
        Otherwise do a system-wide install (e.g. /usr/local/share/jupyter/labextensions).
    overwrite : bool [default: False]
        If True, always install the files, regardless of what may already be installed.
    symlink : bool [default: True]
        If True, create a symlink in labextensions, rather than copying files.
        Windows support for symlinks requires a permission bit which only admin users
        have by default, so don't rely on it.
    labextensions_dir : str [optional]
        Specify absolute path of labextensions directory explicitly.
    destination : str [optional]
        name the labextension is installed to.  For example, if destination is 'foo', then
        the source file will be installed to 'labextensions/foo', regardless of the source name.
    logger : Jupyter logger [optional]
        Logger instance to use
    N)user
sys_prefixlabextensions_dirzpath must be a string pointing to a single extension to install; call this function multiple times to install multiple extensionszRemoving: %sT)exist_okzSymlinking:  -> WindowszSymlinks can be activated on Windows 10 for Python version 3.8 or higher by activating the 'Developer Mode'. That may not be allowed by your administrators.
See https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-developmentz%s exists and is not a symlink zMaking directory: %slogger)_get_labextension_dirr   
isinstancelisttuple	TypeErrorr   r   pjoinospathlexistsinfoisdirislinkshutilrmtreeremovemakedirsdirnameabspathexistssymlinkOSErrorplatform
startswith
ValueErrorwalklen_maybe_copy)r!   r-   	overwriter   r   destinationr   r   	full_destlabextmsgeparent_filesdest_dir	file_namesrc	dest_file rB   ]/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/jupyterlab/federated_labextensions.pydevelop_labextension/   sl   )





rD   c                 C   s   t | \}}tj|jd }	g }
|D ]9}tj|	|d }|d }|r/|d| d|  tj|s;t|	|d t	||||||||d}|

| q|
S )zDevelop a labextension bundled in a Python package.

    Returns a list of installed/updated directories.

    See develop_labextension for parameter information.r   r@   destzInstalling r   r   )r5   r-   r   r   r   r6   r   )_get_labextension_metadatar    r!   split__file__r   r#   r,   build_labextensionrD   append)moduler   r   r5   r-   r   r   mlabexts	base_path
full_destsr8   r@   rE   r7   rB   rB   rC   develop_labextension_py   s,   
rP   c           	      C   s   |du r
t tdntt| }tt|  }|r#|d|   t||}d|d||g}|dur:|d|g |rA|	d |rH|	d t
j||d	 dS )
z&Build a labextension in the given pathNstagingBuilding extension in %snode--core-pathz--static-url--development--source-mapcwd)ospr   HEREstrr   resolver#   _ensure_builderextendrJ   
subprocess
check_call)	r!   r   development
static_url
source_map	core_pathext_pathbuilder	argumentsrB   rB   rC   rI      s   $


rI   c                 C   s8  |du r
t tdntt| }tt|  }|r#|d|   t|}tt	|d}t
|}	W d   n1 s>w   Y  |	d |vrPt|dd n(t	||	d  d |	d }
t	||	d	 d
d}t |
sxt|
 t||
 t||}d|d|d|g}|r|d |r|d tj||d dS )z$Watch a labextension in a given pathNrQ   rR   package.jsonnameT)r   ext_dir
jupyterlab	outputDirstaticrS   rT   z--watchrU   rV   rW   )rY   r   rZ   r[   r   r\   r#   r   openr   jsonr   rP   getr%   r&   r'   r    r-   r]   rJ   r_   r`   )r!   labextensions_pathr   ra   rc   rd   re   federated_extensionsfidext_datar7   
output_dirrf   rg   rB   rB   rC   watch_labextension   s,   $




rv   c           
      C   s  t t|d}t|}W d   n1 sw   Y  t t| d}t|}W d   n1 s5w   Y  |d d }|di d}|pS|di d}|du r^td| d|v rt t| |d}t|d}W d   n1 s~w   Y  tt| d	stj	d
g| d | }tt|d	ddst
||krd}t|t
|}tt|d	ddrt||ddd}	|	st t|d	ddd}t|d}W d   n1 sw   Y  t||ddd}	|	sd| d| }t|t|d	ddddS )zIEnsure that we can build the extension and return the builder script pathrh   NdevDependenciesz@jupyterlab/builderdependenciesz<Extensions require a devDependency on @jupyterlab/builder@%s/r   node_modulesjlpmrW   z@jupyterlabrf   z"Could not find @jupyterlab/builderT)drop_prerelease1drop_prerelease2z:Extensions require a devDependency on @jupyterlab/builder@z, you have a dependency on libzbuild-labextension.js)rn   rY   r   ro   r   rp   r1   r,   r_   r`   r*   r   )
re   rd   rs   	core_datart   dep_version1dep_version2targetr9   overlaprB   rB   rC   r]     sZ   
r]   c                 C   sX   t j|sdS t | jt |j dkr!|r|d|  dS |r*|d|  dS )am  Should a file be copied, if it doesn't exist, or is newer?

    Returns whether the file needs to be updated.

    Parameters
    ----------

    src : string
        A path that should exist from which to copy a file
    src : string
        A path that might exist to which to copy a file
    logger : Jupyter logger [optional]
        Logger instance to use
    Tgư>zOut of date: %szUp to date: %sF)r    r!   r,   statst_mtimewarningr#   r@   rE   r   rB   rB   rC   _should_copy:  s   r   c                 C   s<   t | ||dr|r|d|  d|  t| | dS dS )a!  Copy a file if it needs updating.

    Parameters
    ----------

    src : string
        A path that should exist from which to copy a file
    src : string
        A path that might exist to which to copy a file
    logger : Jupyter logger [optional]
        Logger instance to use
    r   z	Copying: r   N)r   r#   r&   copy2r   rB   rB   rC   r4   V  s
   r4   c                 C   s   d| fd|fd|fd|fg}dd |D }t |dkr'dd	|}t|| r1tt d
}|S |r<ttd d
}|S |rGt|ddd
}|S |rM|}|S ttd d
}|S )a  Return the labextension directory specified

    Parameters
    ----------

    user : bool [default: False]
        Get the user's .jupyter/labextensions directory
    sys_prefix : bool [default: False]
        Get sys.prefix, i.e. ~/.envs/my-env/share/jupyter/labextensions
    prefix : str [optional]
        Get custom prefix
    labextensions_dir : str [optional]
        Get what you put in
    r   prefixr   r   c                 S   s"   g | ]\}}|r| d |qS )=rB   ).0nvrB   rB   rC   
<listcomp>~  s   " z)_get_labextension_dir.<locals>.<listcomp>r   z[cannot specify more than one of user, sys_prefix, prefix, or labextensions_dir, but got: {}z, labextensionsr   sharejupyter)r3   formatr   r   r   r
   r   r	   )r   r   r   r   conflictingconflicting_setr9   r8   rB   rB   rC   r   i  s2   	r   c                 C   s4  t | }t |sd| d}t|g }zt| }t|dr(|| fW S W n ty@ } z|	| W Y d}~nd}~ww d}t
jt
j|drutt
j|dd}t|}W d   n1 sgw   Y  |di d}|sztjtjd	d
g|dd }W n tjy   d| }t|dw zt| W n ty   ttjdddd|g tjd| Y nw ddlm}	m}
 |ddg}| |
| | |	| |D ]/}zt|}t|dr|| fW   S W q ty } z|	| W Y d}~qd}~ww d|  d| }t!|)af  Get the list of labextension paths associated with a Python module.

    Returns a tuple of (the module path,             [{
        'src': 'mockextension',
        'dest': '_mockdestination'
    }])

    Parameters
    ----------

    module : str
        Importable Python module exposing the
        magic-named `_jupyter_labextension_paths` function
    z
The path `z` does not exist._jupyter_labextension_pathsNzpyproject.tomlrbprojectri   zsetup.pyz--namerW   utf8zRThe Python package `{}` is not a valid package, it is missing the `setup.py` file.z-mpipinstallz-er   )find_namespace_packagesfind_packages-r<   zThere is no labextension at z. Errors encountered: )"rY   r+   r,   FileNotFoundError	importlibimport_modulehasattrr   	ExceptionrJ   r    r!   r   rn   r   rp   r_   check_outputsys
executabledecodestripCalledProcessErrorr   r   r   r`   insert
setuptoolsr   r   replacer^   ModuleNotFoundError)rK   mod_pathr9   errorsrL   excpackagers   datar   r   package_candidatesrB   rB   rC   rF     sv   








rF   )TFFNNNF)FFTTNN)NFNFN)NFFN)N)FFNN)4__doc__r   ro   r    os.pathr!   rY   r/   r&   r_   r   pathlibr   importlib.metadatar   r   ImportErrorimportlib_metadatar   r   r   r   jupyter_core.pathsr   r	   r
   jupyter_core.utilsr   (jupyter_server.extension.serverextensionr   jupyterlab_server.configr   tomllibr   tomlicommandsr   objectDEPRECATED_ARGUMENTr+   r*   rH   rZ   rD   rP   rI   rv   r]   r   r4   r   rF   rB   rB   rB   rC   <module>   sj    

m
,

(
5

(