
    ^h                         S r SSKrSSKrSSKrSSKJrJr  SSKJr  SSK	J
r
Jr  SSKJr  SSKJr  SSS	.r " S
 S\5      rg)z(A class for managing IPython extensions.    N)import_modulereload)Configurable)ensure_dir_existscompress_user)undoc)InstanceF)
storemagic
autoreloadc                      ^  \ rS rSrSr\" SSS9rSU 4S jjr\S 5       r	S r
S	\4S
 jrS	\4S jrS	\4S jrS	\4S jrS rS rSrU =r$ )ExtensionManager   a"  A class to manage IPython extensions.

An IPython extension is an importable Python module that has
a function with the signature::

    def load_ipython_extension(ipython):
        # Do things with ipython

This function is called after your extension is imported and the
currently active :class:`InteractiveShell` instance is passed as
the only argument.  You can do anything you want with IPython at
that point, including defining new magic and aliases, adding new
components, etc.

You can also optionally define an :func:`unload_ipython_extension(ipython)`
function, which will be called if the user unloads or reloads the extension.
The extension manager will only call :func:`load_ipython_extension` again
if the extension is reloaded.

You can put your extension modules anywhere you want, as long as
they can be imported by Python's standard import mechanism.  However,
to make it easy to write extensions, you can also put your extensions
in ``os.path.join(self.ipython_dir, 'extensions')``.  This directory
is added to ``sys.path`` automatically.
z1IPython.core.interactiveshell.InteractiveShellABCT)
allow_nonec                    > [         [        U ]
  " SSU0UD6  U R                  R	                  U R
                  SS9  [        5       U l        g )Nshell)ipython_dir)names )superr   __init__r   observe_on_ipython_dir_changedsetloaded)selfr   kwargs	__class__s      Q/home/james-whalen/.local/lib/python3.13/site-packages/IPython/core/extensions.pyr   ExtensionManager.__init__6   sI    .EUEfE

((0@ 	 	
 e    c                 j    [         R                  R                  U R                  R                  S5      $ )N
extensions)ospathjoinr   r   )r   s    r   ipython_extension_dir&ExtensionManager.ipython_extension_dir=   s!    ww||DJJ22MBBr    c                 .    [        U R                  5        g N)r   r&   )r   changes     r   r   (ExtensionManager._on_ipython_dir_changedA   s    $445r    
module_strc                      U R                  U5      $ ! [         a+    U[        ;   a  S[        U'   U R                  SU-   5      s $ e f = f)zLoad an IPython extension by its module name.

Returns the string "already loaded" if the extension is already loaded,
"no load function" if the module doesn't have a load_ipython_extension
function, or None if it succeeded.
TIPython.extensions.)_load_extensionModuleNotFoundErrorBUILTINS_EXTS)r   r,   s     r   load_extensionExtensionManager.load_extensionD   sS    	''
33" 	]*,0j)++,AJ,NOO		s    1AAc                 n   XR                   ;   a  gSSKJn  U R                  R                     U[
        R                  ;  a  [        U5      n[
        R                  U   nU R                  U5      (       a  U R                   R                  U5        O
 S S S 5        g S S S 5        g ! , (       d  f       g = f)Nzalready loadedr   prepended_to_syspathzno load function)
r   IPython.utils.syspathcontextr6   r   builtin_trapsysmodulesr   _call_load_ipython_extensionaddr   r,   r6   mods       r   r/    ExtensionManager._load_extensionS   s    $#EZZ$$,#J/++j)C0055
+) %$
 , %$$s   A&B&&
B4c                    [         R                  US5      SL a  SU-   nXR                  ;  a  gU[        R                  ;   aF  [        R                  U   nU R                  U5      (       a  U R                  R                  U5        ggg)aK  Unload an IPython extension by its module name.

This function looks up the extension's name in ``sys.modules`` and
simply calls ``mod.unload_ipython_extension(self)``.

Returns the string "no unload function" if the extension doesn't define
a function to unload itself, "not loaded" if the extension isn't loaded,
otherwise None.
FTr.   z
not loadedzno unload functionN)r1   getr   r9   r:   _call_unload_ipython_extensiondiscard)r   r,   r>   s      r   unload_extension!ExtensionManager.unload_extensionb   su     Z/47.;J[[($++j)C22377##J/+ %r    c                    SSK Jn  [        R                  US5      SL a  SU-   nXR                  ;   a  U[
        R                  ;   a}  U R                  U5        [
        R                  U   nU" U R                  5         [        U5        SSS5        U R                  U5      (       a  U R                  R                  U5        ggU R                  U5        g! , (       d  f       NS= f)a  Reload an IPython extension by calling reload.

If the module has not been loaded before,
:meth:`InteractiveShell.load_extension` is called. Otherwise
:func:`reload` is called and then the :func:`load_ipython_extension`
function of the module, if it exists is called.
r   r5   FTr.   N)r7   r6   r1   rA   r   r9   r:   rD   r&   r   r;   r<   r2   r=   s       r   reload_extension!ExtensionManager.reload_extensionx   s     	FZ/47.;J++%J#++,E!!*-++j)C%d&@&@As B0055
+ 6 
+ BAs   >C
C%c                 ^    [        US5      (       a  UR                  U R                  5        gg )Nload_ipython_extensionT)hasattrrJ   r   r   r>   s     r   r;   -ExtensionManager._call_load_ipython_extension   s*    3011&&tzz2 2r    c                 ^    [        US5      (       a  UR                  U R                  5        gg )Nunload_ipython_extensionT)rK   rO   r   rL   s     r   rB   /ExtensionManager._call_unload_ipython_extension   s*    3233((4 4r    )r   r)   )__name__
__module____qualname____firstlineno____doc__r	   r   r   propertyr&   r   strr2   r/   rD   rG   r;   rB   __static_attributes____classcell__)r   s   @r   r   r      sw    4 HUYZE C C6 *# *,3 ,,,3 ,.
 r    r   )rU   r#   os.pathr9   	importlibr   r   traitlets.config.configurabler   IPython.utils.pathr   r   IPython.utils.decoratorsr   	traitletsr	   r1   r   r   r    r   <module>r`      s<    .
 
  
 + 6 ? *   %E:~| ~r    