
    ^hp+                     B   S SK r S SKrSSKJrJrJrJr  SSKJr  S SK	J
r
  S SKJr  S SKJr  S SKJr  S	rS
rS r SS jrSS jrSS jrSS jr " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r\R:                  r\S:X  a  \" 5         gg)    N   )BaseExtensionApp_get_config_dirGREEN_ENABLEDRED_DISABLED)__version__)BaseJSONConfigManager)jupyter_config_path)import_item)Boolnotebookbundlerextensionsc                     [        U 5      n[        US5      (       d  [        SR                  U 5      5      eUR	                  5       nX4$ )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      ]/home/james-whalen/.local/lib/python3.13/site-packages/nbclassic/bundler/bundlerextensions.py_get_bundler_metadatar      sJ    " 	FA1788W^^_efgg002H;    c           	         U(       a  SOUn[         R                  R                  [        XVS9S5      n[	        US9n	U(       a+  UR                  SR                  U(       a  SOSU U5      5        U(       a#  U	R                  [        [        U UUUS.005        OU	R                  [        [        U S	005        U	R                  [        5      R                  [        0 5      R                  U 5      S	LU:H  $ )
a  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   )   s    4 5DDT9:GJ	*	5B)00J[
 	 
		/"#.#!$
 	 			/d!$
 	 FF?#s%r*s4y%)./ /r   c                 ~    [        U5      u  pVU Vs/ s H  n[        US   US   US   US   U X#US9PM      sn$ s  snf )a  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
r,   r!   r"   r#   )r,   r!   r"   r#   r-   r   r   r.   )r   r0   )r-   r   r   r   r.   r   r   bundlers           r   _set_bundler_state_pythonr3   e   sg    & (/KA $% $ GFO%,W%5+2=+A%,W%5%*$(&,. $% % %s   %:c                     [        SXUUS9$ )a	  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.   r3   r   r   r   r.   s       r   enable_bundler_pythonr8      s    $ %T6,24 4r   c                     [        SXUUS9$ )a
  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
Fr5   r6   r7   s       r   disable_bundler_pythonr:      s    $ %UF*,24 4r   c                   J    \ rS rSrSrSr\rSr\	" SSSS9r
SrS	 rS
 rS rSrg)ToggleBundlerExtensionApp   z;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                     g)zThe default config file name.jupyter_notebook_config selfs    r   _config_file_name_default3ToggleBundlerExtensionApp._config_file_name_default   s    (r   c                     U R                   (       a  [        O[        nU" UU R                  U R                  U R
                  S9$ )a  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_valuer8   r:   r   r   log)rD   r   toggles      r   toggle_bundler_python/ToggleBundlerExtensionApp.toggle_bundler_python   s<     ,0+=+='- 	f99!%!XX' 	'r   c                 &   U R                   (       d  [        R                  " S5        O/[        U R                   5      S:  a  [        R                  " S5        U R                  (       a  U R                  U R                   S   5        g [        S5      e)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pythonrK   NotImplementedErrorrC   s    r   startToggleBundlerExtensionApp.start   s^    HHVW!A%HHLM;;&&tq'9:%&XYYr   rB   )__name__
__module____qualname____firstlineno____doc__r,   r   versiondescriptionr   r   rH   rE   rK   rU   __static_attributes__rB   r   r   r<   r<      s8    E>DGGKT(efDM)'&Zr   r<   c                   $    \ rS rSrSrSrSrSrSrg)EnableBundlerExtensionApp   z%An App that enables bundlerextensionsz)jupyter nbclassic-bundlerextension enablez
    Enable a bundlerextension in frontend configuration.

    Usage
        jupyter nbclassic-bundlerextension enable [--system|--sys-prefix]
    TrB   N	rW   rX   rY   rZ   r[   r,   r]   rH   r^   rB   r   r   r`   r`      s    /6DK Mr   r`   c                   $    \ rS rSrSrSrSrSrSrg)DisableBundlerExtensionApp   z&An App that disables bundlerextensionsz*jupyter nbclassic-bundlerextension disablez
    Disable a bundlerextension in frontend configuration.

    Usage
        jupyter nbclassic-bundlerextension disable [--system|--sys-prefix]
    NrB   rb   rB   r   r   rd   rd      s    07DK Mr   rd   c                   0    \ rS rSrSrSr\rSrS r	S r
Srg)	ListBundlerExtensionApp   z,An App that lists and validates nbextensionsz jupyter nbclassic-extension listz7List all nbextensions known by the configuration systemc                 0   [        5        Vs/ s H#  n[        R                  R                  US5      PM%     nn[	        S5        U H  nSR                  U5      nSn[        XS9nUR                  S5      nSU;   d  M8  U(       d  [	        U5        SnUS   R                  5        He  u  pU	R                  S	5      n
U	R                  S
5      nU
b  Uc  SR                  U[        5      nOSR                  X[        5      n[	        U5        Mg     M     gs  snf )zList all the nbextensionsr   zKnown bundlerextensions:z  config dir: {}F)parentr   r   r   Tr!   r"   Nz	    {} {}z    "{}" from {} {})r
   r$   r%   r&   printr   r	   r+   itemsr   r   )rD   pconfig_dirsr   head
head_shownr/   data
bundler_idr'   r!   r   msgs                r   list_nbextensions)ListBundlerExtensionApp.list_nbextensions   s    <O<QR<Qqrww||Az2<QR()%J&--j9DJ&dJB66*%D"d*!$K!%J(,-@(A(G(G(I$J HHW-E!XXm4F}*11*lK4;;!= #J )J &	 Ss   *Dc                 $    U R                  5         g))Perform the App's functions as configuredN)rt   rC   s    r   rU   ListBundlerExtensionApp.start  s     r   rB   N)rW   rX   rY   rZ   r[   r,   r   r\   r]   rt   rU   r^   rB   r   r   rg   rg      s    6-DGKK:!r   rg   c                   X   ^  \ rS rSrSrSr\rSrSr	\
" \S4\S4\S4S	9rU 4S
 jrSrU =r$ )BundlerExtensionAppi  z;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U ]  5         SR                  [        U R                  5      5      n[
        R                  " SU-  5        g)rw   z, z)Please supply at least one subcommand: %sN)superrU   r&   sortedsubcommandsrP   rQ   )rD   subcmds	__class__s     r   rU   BundlerExtensionApp.start'  s9     ))F4#3#345<wFGr   rB   )rW   rX   rY   rZ   r[   r,   r   r\   r]   examplesdictr`   rd   rg   r   rU   r^   __classcell__)r   s   @r   rz   rz     sO    E/DG8KH )+GH+-JK%'@AKH Hr   rz   __main__)TFN)N) rP   r$   
extensionsr   r   r   r   _versionr   nbclassic.config_managerr	   jupyter_core.pathsr
   traitlets.utils.importstringr   	traitletsr   r)   r*   r   r0   r3   r8   r:   r<   r`   rd   rg   rz   launch_instancemainrW   rB   r   r   <module>r      s     	 W W " : 2 4 ( 0 <@9/x%:4*4*)Z 0 )ZV	 9 		!: 	%!. %!PH* H4 **zF r   