o
    ik                     @   s^   d dl Z d dlmZ d dlmZ ddlmZ dd Zdd Z	d	d
 Z
dd ZG dd dZdS )    N)filterfalse   )HEREc                  G   s   t t j|  S )z!Join paths to create a real path.)ospabspathjoin)args r	   P/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/jupyterlab/coreconfig.pypjoin   s   r   c                  C   s>   t ttdd} t| W  d   S 1 sw   Y  dS )z"Get the data for the app template.stagingzpackage.jsonN)openr   r   jsonload)fidr	   r	   r
   _get_default_core_data   s   $r   c                 C   s
   |  dS )z.Whether a package name is in the lab namespacez@jupyterlab/)
startswith)namer	   r	   r
   _is_lab_package   s   
r   c                 C   sD   t | trdd |  D S t | ttfrttt| S d}t|)zFilter a dict/sequence to remove all lab packages

    This is useful to take the default values of e.g. singletons and filter
    away the '@jupyterlab/' namespace packages, but leave any others (e.g.
    lumino and react).
    c                 S   s   i | ]\}}t |s||qS r	   )r   ).0kvr	   r	   r
   
<dictcomp>#   s    z _only_nonlab.<locals>.<dictcomp>z2collection arg should be either dict or list/tuple)
isinstancedictitemslisttupler   r   	TypeError)
collectionmsgr	   r	   r
   _only_nonlab   s   
r!   c                   @   sr   e Zd ZdZdd ZdddZdd Zdd
dZedd Z	edd Z
edd Zedd Zejdd ZdS )
CoreConfigzAn object representing a core config.

    This enables custom lab application to override some parts of the core
    configuration of the build system.
    c                 C   s   t  | _d S )N)r   _dataselfr	   r	   r
   __init__1   s   zCoreConfig.__init__Fc                 C   s   | j }|sd}t||sd}t|||d v r"d|}t|||d |< |r:d|d d |< ||d |< dS |rLd|d d	 |< ||d |< dS |d d
 | dS )a  Remove an extension/singleton.

        If neither extension or mimeExtension is True (the default)
        the package is added as a singleton dependency.

        name: string
            The npm package name
        semver: string
            The semver range for the package
        extension: bool
            Whether the package is an extension
        mime_extension: bool
            Whether the package is a MIME extension
        zMissing package namezMissing package semverresolutionszPackage already present:  
jupyterlabmimeExtensionsdependencies
extensionssingletonPackagesN)r#   
ValueErrorappend)r%   r   semver	extensionmime_extensiondatar    r	   r	   r
   add4   s$   
zCoreConfig.addc              	   C   sf   | j }|d |d |d d |d d f}|D ]}z||= W q ty'   Y qw |d d | dS )z[Remove a package/extension.

        name: string
            The npm package name
        r+   r'   r)   r,   r*   r-   N)r#   KeyErrorremove)r%   r   r3   mapsmr	   r	   r
   r6   Z   s   


zCoreConfig.removeTc                 C   s   | j }|r;t|d |d< t|d |d< t|d d |d d< t|d d |d d< t|d d |d d< dS i |d< i |d< i |d d< i |d d< g |d d< dS )zClear the packages/extensions.r+   r'   r)   r,   r*   r-   N)r#   r!   )r%   lab_onlyr3   r	   r	   r
   clear_packageso   s    

zCoreConfig.clear_packagesc                        | j   fdd d d D S )z2A dict mapping all extension names to their semverc                       i | ]	}| d  | qS r'   r	   r   r   r3   r	   r
   r          z)CoreConfig.extensions.<locals>.<dictcomp>r)   r,   r#   r$   r	   r?   r
   r,         zCoreConfig.extensionsc                    r;   )z7A dict mapping all MIME extension names to their semverc                    r<   r=   r	   r>   r?   r	   r
   r      r@   z.CoreConfig.mime_extensions.<locals>.<dictcomp>r)   r*   rA   r$   r	   r?   r
   mime_extensions   rB   zCoreConfig.mime_extensionsc                    r;   )z2A dict mapping all singleton names to their semverc                    s   i | ]}| d   |dqS )r'   N)getr>   r?   r	   r
   r      s    z)CoreConfig.singletons.<locals>.<dictcomp>r)   r-   rA   r$   r	   r?   r
   
singletons   s   

zCoreConfig.singletonsc                 C   s   | j d d S Nr)   	staticDirrA   r$   r	   r	   r
   
static_dir   s   zCoreConfig.static_dirc                 C   s   || j d d< d S rF   rA   )r%   rH   r	   r	   r
   rH      s   N)FF)T)__name__
__module____qualname____doc__r&   r4   r6   r:   propertyr,   rC   rE   rH   setterr	   r	   r	   r
   r"   *   s     
&




r"   )r   os.pathpathr   	itertoolsr   jlpmappr   r   r   r   r!   r"   r	   r	   r	   r
   <module>   s   