
    @=d+                     X   d dl Z d dl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 d dlmZ d	Zd
Zd Z	 ddZddZddZddZ G d de          Z G d de          Z G d de          Z G d de          Z G d de          Zej        Zedk    r e             dS dS )    N   )BaseExtensionApp_get_config_dirGREEN_ENABLEDRED_DISABLED)__version__)BaseJSONConfigManager)jupyter_config_path)import_item)Boolnotebookbundlerextensionsc                     t          |           }t          |d          s"t          d                    |                     |                                }||fS )a   Gets the list of bundlers associated with a Python package.
    
    Returns a tuple of (the module, [{
        'name': 'unique name of the bundler',
        'label': 'file menu item label for the bundler',
        'module_name': 'dotted package/module name containing the bundler',
        'group': 'download or deploy parent menu item'
    }])
    
    Parameters
    ----------

    module : str
        Importable Python module exposing the
        magic-named `_jupyter_bundlerextension_paths` function
    _jupyter_bundlerextension_pathsz>The Python module {} does not contain a valid bundlerextension)r   hasattrKeyErrorformatr   )modulembundlerss      Clib/python3.11/site-packages/nbclassic/bundler/bundlerextensions.py_get_bundler_metadatar      s^    " 	FA1788 hW^^_effggg0022Hh;    TFc           	      "   |rdn|}t           j                            t          ||          d          }t	          |          }	|r.|                    d                    |rdnd| |                     |r)|	                    t          t          | |||dii           n$|	                    t          t          | d	ii           |	
                    t                    
                    t          i           
                    |           d	u|k    S )
aF  Set whether a bundler is enabled or disabled.
    
    Returns True if the final state is the one requested.
    
    Parameters
    ----------
    name : string
        Unique name of the bundler
    label : string
        Human-readable label for the bundler menu item in the notebook UI
    module_name : string
        Dotted module/package name containing the bundler
    group : string
        'download' or 'deploy' indicating the parent menu containing the label
    state : bool
        The state in which to leave the extension
    user : bool [default: True]
        Whether to update the user's .jupyter/nbconfig directory
    sys_prefix : bool [default: False]
        Whether to update the sys.prefix, i.e. environment. Will override
        `user`.
    logger : Jupyter logger [optional]
        Logger instance to use
    F)user
sys_prefixnbconfig)
config_dirz{} {} bundler {}...Enabling	Disabling)labelmodule_namegroupN)ospathjoinr   r	   infor   updateBUNDLER_SECTIONBUNDLER_SUBSECTIONget)
namer!   r"   r#   stater   r   loggerr   cms
             r   _set_bundler_stater0   )   sD   4 (55DDTj999:G GJ	*	5	5	5B )000JJ[
 
 	 	 	  
		/"#.# !$
 	 	 	 	 			/d!$
 	 	 	 FF?##s%r**s4yy%)./ /r   c                 P     t          |          \  }} fd|D             S )aP  Enables or disables bundlers defined in a Python package.
    
    Returns a list of whether the state was achieved for each bundler.
    
    Parameters
    ----------
    state : Bool
        Whether the extensions should be enabled
    module : str
        Importable Python module exposing the
        magic-named `_jupyter_bundlerextension_paths` function
    user : bool
        Whether to enable in the user's nbconfig directory.
    sys_prefix : bool
        Enable/disable in the sys.prefix, i.e. environment
    logger : Jupyter logger [optional]
        Logger instance to use
    c                 n    g | ]1}t          |d          |d         |d         |d                   2S )r,   r!   r"   r#   )r,   r!   r"   r#   r-   r   r   r.   )r0   ).0bundlerr.   r-   r   r   s     r   
<listcomp>z-_set_bundler_state_python.<locals>.<listcomp>y   sc     % % %  GFO%,W%5+2=+A%,W%5%*$(Z&,. . . % % %r   )r   )r-   r   r   r   r.   r   r   s   ` ```  r   _set_bundler_state_pythonr6   e   sU    & (//KAx% % % % % % % $% % % %r   c                 *    t          d| |||          S )aI  Enables bundlers defined in a Python package.
    
    Returns whether each bundle defined in the packaged was enabled or not.
    
    Parameters
    ----------
    module : str
        Importable Python module exposing the
        magic-named `_jupyter_bundlerextension_paths` function
    user : bool [default: True]
        Whether to enable in the user's nbconfig directory.
    sys_prefix : bool [default: False]
        Whether to enable in the sys.prefix, i.e. environment. Will override
        `user`
    logger : Jupyter logger [optional]
        Logger instance to use
    Tr.   r6   r   r   r   r.   s       r   enable_bundler_pythonr;      s&    $ %T64,24 4 4 4r   c                 *    t          d| |||          S )aJ  Disables bundlers defined in a Python package.
    
    Returns whether each bundle defined in the packaged was enabled or not.
    
    Parameters
    ----------
    module : str
        Importable Python module exposing the
        magic-named `_jupyter_bundlerextension_paths` function
    user : bool [default: True]
        Whether to enable in the user's nbconfig directory.
    sys_prefix : bool [default: False]
        Whether to enable in the sys.prefix, i.e. environment. Will override
        `user`
    logger : Jupyter logger [optional]
        Logger instance to use
    Fr8   r9   r:   s       r   disable_bundler_pythonr=      s&    $ %UFD*,24 4 4 4r   c                   P    e Zd ZdZdZeZdZ eddd          Z	dZ
d Zd	 Zd
 ZdS )ToggleBundlerExtensionAppz;A base class for apps that enable/disable bundlerextensionsz1jupyter nbclassic-bundlerextension enable/disablez3Enable/disable a bundlerextension in configuration.Tz;Apply the configuration only for the current user (default))confighelpNc                     dS )zThe default config file name.jupyter_notebook_config selfs    r   _config_file_name_defaultz3ToggleBundlerExtensionApp._config_file_name_default   s    ((r   c                 h    | j         rt          nt          } ||| j        | j        | j                  S )aS  Toggle some extensions in an importable Python module.

        Returns a list of booleans indicating whether the state was changed as
        requested.

        Parameters
        ----------
        module : str
            Importable Python module exposing the
            magic-named `_jupyter_bundlerextension_paths` function
        )r   r   r.   )_toggle_valuer;   r=   r   r   log)rF   r   toggles      r   toggle_bundler_pythonz/ToggleBundlerExtensionApp.toggle_bundler_python   sG     ,0+= .''- 	vf9!%!X' ' ' 	'r   c                    | j         st          j        d           n,t          | j                   dk    rt          j        d           | j        r"|                     | j         d                    d S t          d          )Nz?Please specify an bundlerextension/package to enable or disable   z5Please specify one bundlerextension/package at a timer   z0Cannot install bundlers from non-Python packages)
extra_argssysexitlenpythonrL   NotImplementedErrorrE   s    r   startzToggleBundlerExtensionApp.start   s     	NHVWWWW!!A%%HLMMM; 	Z&&tq'9:::::%&XYYYr   )__name__
__module____qualname____doc__r,   r   versiondescriptionr   r   rI   rG   rL   rU   rD   r   r   r?   r?      sw        EE>DGGK4T(efffDM) ) )' ' '&Z Z Z Z Zr   r?   c                       e Zd ZdZdZdZdZdS )EnableBundlerExtensionAppz%An App that enables bundlerextensionsz)jupyter nbclassic-bundlerextension enablez
    Enable a bundlerextension in frontend configuration.
    
    Usage
        jupyter nbclassic-bundlerextension enable [--system|--sys-prefix]
    TNrV   rW   rX   rY   r,   r[   rI   rD   r   r   r]   r]      s'        //6DK MMMr   r]   c                       e Zd ZdZdZdZdZdS )DisableBundlerExtensionAppz&An App that disables bundlerextensionsz*jupyter nbclassic-bundlerextension disablez
    Disable a bundlerextension in frontend configuration.
    
    Usage
        jupyter nbclassic-bundlerextension disable [--system|--sys-prefix]
    Nr^   rD   r   r   r`   r`      s'        007DK MMMr   r`   c                   *    e Zd ZdZdZeZdZd Zd Z	dS )ListBundlerExtensionAppz,An App that lists and validates nbextensionsz jupyter nbclassic-extension listz7List all nbextensions known by the configuration systemc                 0   d t                      D             }t          d           |D ]}d                    |          }d}t          | |          }|                    d          }d|v r|st          |           d}|d                                         D ]z\  }}|                    d	          }	|                    d
          }
|	|
d                    |t                    }nd                    |	|
t                    }t          |           {dS )zList all the nbextensionsc                 N    g | ]"}t           j                            |d           #S )r   )r$   r%   r&   )r3   ps     r   r5   z=ListBundlerExtensionApp.list_nbextensions.<locals>.<listcomp>   s(    RRRqrw||Az22RRRr   zKnown bundlerextensions:z  config dir: {}F)parentr   r   r   Tr!   r"   Nz	    {} {}z    "{}" from {} {})r
   printr   r	   r+   itemsr   r   )rF   config_dirsr   head
head_shownr/   data
bundler_idr'   r!   r   msgs               r   list_nbextensionsz)ListBundlerExtensionApp.list_nbextensions   s6   RR<O<Q<QRRR()))% 	 	J&--j99DJ&dzJJJB66*%%D"d**! &$KKK!%J(,-@(A(G(G(I(I 	 	$J HHW--E!XXm44F}*11*lKK4;;!6=  #JJJJ+	 	r   c                 .    |                                   dS ))Perform the App's functions as configuredN)ro   rE   s    r   rU   zListBundlerExtensionApp.start  s         r   N)
rV   rW   rX   rY   r,   r   rZ   r[   ro   rU   rD   r   r   rb   rb      sG        66-DGKK  :! ! ! ! !r   rb   c                   Z     e Zd ZdZdZeZdZdZ e	e
dfedfedf          Z fd	Z xZS )
BundlerExtensionAppz;Base jupyter nbclassic-bundlerextension command entry pointz"jupyter nbclassic-bundlerextensionz$Work with Jupyter bundler extensionsa8  
jupyter nbclassic-bundlerextension list                          # list all configured bundlers
jupyter nbclassic-bundlerextension enable --py <packagename>     # enable all bundlers in a Python package
jupyter nbclassic-bundlerextension disable --py <packagename>    # disable all bundlers in a Python package
zEnable a bundler extensionzDisable a bundler extensionzList bundler extensions)enabledisablelistc                     t                                                       d                    t          | j                            }t          j        d|z             dS )rq   z, z)Please supply at least one subcommand: %sN)superrU   r&   sortedsubcommandsrP   rQ   )rF   subcmds	__class__s     r   rU   zBundlerExtensionApp.start'  sN     ))F4#34455<wFGGGGGr   )rV   rW   rX   rY   r,   r   rZ   r[   examplesdictr]   r`   rb   rz   rU   __classcell__)r|   s   @r   rs   rs     s        EE/DG8KH $)+GH+-JK%'@A  KH H H H H H H H Hr   rs   __main__)TFN)N) rP   r$   
extensionsr   r   r   r   _versionr   nbclassic.config_managerr	   jupyter_core.pathsr
   traitlets.utils.importstringr   	traitletsr   r)   r*   r   r0   r6   r;   r=   r?   r]   r`   rb   rs   launch_instancemainrV   rD   r   r   <module>r      s   


 				 W W W W W W W W W W W W " " " " " " : : : : : : 2 2 2 2 2 2 4 4 4 4 4 4      (   0 <@9/ 9/ 9/ 9/x% % % %:4 4 4 4*4 4 4 4*)Z )Z )Z )Z )Z 0 )Z )Z )ZV	 	 	 	 	 9 	 	 		 	 	 	 	!: 	 	 	%! %! %! %! %!. %! %! %!PH H H H H* H H H4 *zDFFFFF r   