
    XhB                        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 	 ddlmZmZ 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 	 ddl m!Z! ddl#m$Z$  e%       Z& ejN                   ejP                  e)            Z*	 	 	 	 	 	 	 ddZ+	 	 	 	 	 	 ddZ,	 ddZ-	 ddZ.d Z/ddZ0ddZ1ddZ2d Z3y# e$ r ddlmZmZ Y w xY w# e$ r	 ddl"m!Z! Y w xY w)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_overlapc                 Z   d}t        |||      }	t        |	       t        | t        t        f      rd}
t        |
      |st        t        |             }t        t        |	|            }|rt        j                  j                  |      r|r|j                  d|        t        j                  j                  |      r5t        j                  j                  |      st        j                   |       nt        j"                  |       t        j$                  t        j                  j'                  |      d       |rt        j                  j)                  |       } t        j                  j+                  |      s2|r|j                  d| d|         	 t        j,                  | |       |S t        j                  j                  |      s| d}
t5        |
      |S t        j                  j                  |       rt        t        j                  j)                  |       d      } t        j6                  |       D ]  \  }}}t        ||t9        |       d       }t        j                  j+                  |      s+|r|j                  d|        t        j$                  |       |D ](  }t        ||      }t        ||      }t;        |||       *  |S | }t;        |||       |S # t.        $ r7}t1        j0                         j3                  d	      rd
}
t/        |
      | d}~ww xY w)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: T)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 exists and is not a symlink zMaking directory: 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_files                      V/var/www/html/myenv/lib/python3.12/site-packages/jupyterlab/federated_labextensions.pydevelop_labextensionrE   .   s   R I"j<MF f$u& Rnx~.v{34IRWW__Y/KK*YK0177==#BGGNN9,EMM)$IIi  KK	*T:wwt$ww~~i(l9+T$@A


4+> ) 	*K;<CS/!$ ! 
t	RWW__T*B/ " 		;FAuYs4y{(;<H77>>(+KK"4XJ ?@H%" ;	FI.!(I6	C6:;		;  C62=  $$&11)<{ 
 "#,A-s   K* *	L*32L%%L*c                    t        |       \  }}t        j                  j                  |j                        d   }	g }
|D ]  }t        j                  j                  |	|d         }|d   }|r|j                  d| d|        t        j                  j                  |      st        |	|       t        ||||||||      }|
j                  |        |
S )zDevelop a labextension bundled in a Python package.

    Returns a list of installed/updated directories.

    See develop_labextension for parameter information.r   rB   destzInstalling r   r   )r7   r/   r   r   r   r8   r   )_get_labextension_metadatar"   r#   split__file__r   r%   r.   build_labextensionrE   append)moduler   r   r7   r/   r   r   mlabexts	base_path
full_destsr:   rB   rG   r9   s                  rD   develop_labextension_pyrR      s     ,F3JAwajj)!,IJ %ggll9fUm4f~KK+cU$tf56ww~~c"y8(!/	
	 	)$'%*     c                    |t        j                  t        d      n!t        t	        |      j                               }t        t	        |       j                               }|r|j                  d|         t        ||      }d|d||g}||j                  d|g       |r|j                  d       |r|j                  d       t        j                  ||	       y)
z&Build a labextension in the given pathNstagingBuilding extension in node--core-pathz--static-url--development--source-mapcwd)ospr   HEREstrr   resolver%   _ensure_builderextendrL   
subprocess
check_call)	r#   r   development
static_url
source_map	core_pathext_pathbuilder	argumentss	            rD   rK   rK      s     .7->y)CYH_H_HaDbI4:%%'(H,TF34h	2G-HEI.*56)()2rS   c                 >   |t        j                  t        d      n!t        t	        |      j                               }t        t	        |       j                               }|r|j                  d|         t        |      }t        t        |d            5 }t        j                  |      }	ddd       	d   |vrt        |d       nwt        ||	d      d   |	d         }
t        ||	d	   j                  d
d            }t        j                  |
      s+t        j                   |
       t#        j$                  ||
       t'        ||      }d|d|d|g}|r|j)                  d       |r|j)                  d       t+        j,                  ||       y# 1 sw Y   xY w)z$Watch a labextension in a given pathNrU   rV   package.jsonnameT)r   ext_dir
jupyterlab	outputDirstaticrW   rX   z--watchrY   rZ   r[   )r]   r   r^   r_   r   r`   r%   r   openr!   jsonr   rR   getr'   r(   r)   r"   r/   ra   rL   rc   rd   )r#   labextensions_pathr   re   rg   rh   ri   federated_extensionsfidext_datar9   
output_dirrj   rk   s                 rD   watch_labextensionr{      sl    .7->y)CYH_H_HaDbI4:%%'(H,TF34 44FG	eHn-	. "#99S>" 33T:.x/?@KXV\M]^	8Xl%;%?%?X%VW
zz)$MM)$JJz9-h	2G-IxPI)()2'" "s   FFc           	         t        t        j                  |d            5 }t        j                  |      }ddd       t        t        j                  | d            5 }t        j                  |      }ddd       d   d   }j                  di       j                  d      }|xs! |j                  di       j                  d      }|d| }t        |      d|v rMt        t        j                  | |d            5 }t        j                  |      j                  d      }ddd       t        j                  t        j                  | d	            st        j                  d
g|        | }t        j                  t        j                  |d	dd            sft        j                  |      |k(  rd}t        |      t        j                  |      }t        j                  t        j                  |d	dd            sft        ||dd      }	|	s^t        t        j                  |d	ddd            5 }t        j                  |      j                  d      }ddd       t        ||dd      }	|	sd| d| }t        |      t        j                  |d	dddd      S # 1 sw Y   jxY w# 1 sw Y   :xY w# 1 sw Y   xY w# 1 sw Y   nxY w)zIEnsure that we can build the extension and return the builder script pathrm   NdevDependenciesz@jupyterlab/builderdependenciesz:Extensions require a devDependency on @jupyterlab/builder@/r   node_modulesjlpmr[   z@jupyterlabrj   z"Could not find @jupyterlab/builderT)drop_prerelease1drop_prerelease2z, you have a dependency on libzbuild-labextension.js)rs   r]   r   rt   r   ru   r3   r.   rc   rd   r,   r   )
ri   rh   rx   	core_datary   dep_version1dep_version2r;   targetoverlaps
             rD   ra   ra     s    
chhy.1	2 #cIIcN	#	chhx0	1 "S99S>"./0EFL<< 126::;PQL^8<<#C#G#GH]#^LJ<.Yo l#((8\>BC 	9s99S>--i8L	9::chhx89vhH5 Fjj&.-ST;;v&(6CS/!V$	 jj&.-ST lTDG HHV^]I~V
 	999S>--i8L	9  ,PT
 J<.Xs  uA  tB  Co88y%AX Y# #" "	9 	9$	9 	9s/   JJ+?%J83%KJ(+J58KKc                 "   t         j                  j                  |      syt        j                  |       j                  t        j                  |      j                  z
  dkD  r|r|j                  d|        y|r|j                  d|        y)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: zUp to date: F)r"   r#   r.   statst_mtimewarningr%   rB   rG   r   s      rD   _should_copyr   9  st     77>>$	wws|rwwt}555< NN]4&12l4&)*rS   c                     t        | ||      r0|r|j                  d|  d|        t        j                  | |       yy)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   s      rD   r6   r6   U  s?     Cf-KK)C5TF34S$ .rS   c                    d| fd|fd|fd|fg}|D cg c]  \  }}|s	| d| }}}t        |      dkD  r+dj                  dj                  |            }t        |      | rt	        t               d	      }	|	S |rt	        t        d
   d	      }	|	S |rt	        |ddd	      }	|	S |r|}	|	S t	        t        d
   d	      }	|	S c c}}w )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   =r   z[cannot specify more than one of user, sys_prefix, prefix, or labextensions_dir, but got: {}z, labextensionsr   sharejupyter)r5   formatr   r   r!   r   r	   r
   )
r   r   r   r   conflictingnvconflicting_setr;   r:   s
             rD   r   r   h  s
     
	6	/0	z"	K 1<A1q!AaU|AOA
?akrrIIo&
 s##')?; M 
'*O< M 
vw	?C
 M	 
" M *1-?M! Bs
   
C 	C c           	         t        j                  |       }t        j                  |      sd| d}t        |      g }	 t	        j
                  |       }t        |d      r||j                         fS 	 d}t        j                  j                  t        j                  j                  |d            r_t        t        j                  j                  |d      d      5 }t        |      }ddd       j                  di       j                  d      }|sF	 t!        j"                  t$        j&                  d	d
g|      j)                  d      j+                         }	 t/        |       ddlm}	m}
 |j=                  dd      g}|j?                   |
|             |j?                   |	|             |D ]8  }	 t	        j
                  |      }t        |d      r||j                         fc S : d|  d| }tA        |      # t        $ r}|j                  |       Y d}~d}~ww xY w# 1 sw Y   @xY w# t         j,                  $ r d|  d}t        |      dw xY w# t0        $ rM t!        j2                  t$        j&                  dddd|g       t$        j                  j5                  d|       Y Lw xY w# t        $ r}|j                  |       Y d}~%d}~ww xY w)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projectrn   zsetup.pyz--namer[   utf8zThe Python package `z<` 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: )!r]   r-   r.   FileNotFoundError	importlibimport_modulehasattrr   	ExceptionrL   r"   r#   r   rs   r   ru   rc   check_outputsys
executabledecodestripCalledProcessErrorr   r   rd   insert
setuptoolsr   r   replacerb   ModuleNotFoundError)rM   mod_pathr;   errorsrN   excpackagerx   datar   r   package_candidatess               rD   rH   rH     s    {{6"H::h8*$56$$F##F+134a33555 5 G 
ww~~bggll8-=>?"'',,x)9:DA 	S9D	((9b)--f5 	3''^^Z:    %
 B 	S! mH56) & 	''0Aq78!77999 9 )0Fvh
OC
c
""q  c	 	 ,, 	3&vh /5 5  $C(d2	3   %s~~tUItXVW8$%&  	MM#	s[   2G> H&AH3 I 42J5>	H#HH#&H03&IAJ21J25	K>KK)TFFNNNF)FFTTNN)NFNFN)NFFN)N)FFNN)4__doc__r   rt   r"   os.pathr#   r]   r1   r(   rc   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,   rJ   r^   rE   rR   rK   r{   ra   r   r6   r   rH    rS   rD   <module>r      s   E
   	     
 A@ ' ! V V 0 E = $h s{{;3;;x() 	i\ 
(X X\32 [_ 3P1h8 &%PS#}  A@@A  s#   C C CCC'&C'