
    
d%                     R    d Z ddlZddlZddlmZ ddlmZmZ  G d de          Z	dS )zUser module reloader.    N)path_is_library)PY2_printc                   2    e Zd ZdZddZd Zd Zd Zd ZdS )	UserModuleReloaderz
    User Module Reloader (UMR) aims at deleting user modules
    to force Python to deeply reload them during import

    pathlist [list]: blacklist in terms of module path
    namelist [list]: blacklist in terms of module name
    Nc                 ^   |g }n)	 |                     d          }n# t          $ r g }Y nw xY wdg}g d}g d}t          r	ddg}||z   }||z   |z   |z   | _        || _        t          t          j                                                  | _	        g | _
        d| _        |                                  t          j                            dd	          }|                                d
k    | _        t          j                            dd	          }|                                d
k    | _        d S )N,spyder_kernels)
matplotlibtkinterTkinter)pytorch	pythoncom
tensorflowastropyfastmatFSPY_UMR_ENABLED trueSPY_UMR_VERBOSE)split	Exceptionr   namelistpathlistlistsysmoduleskeysprevious_modulesmodnames_to_reload
has_cythonactivate_cythonosenvirongetlowerenabledverbose)	selfr   r   spy_modulesmpl_modulesother_modulespy2_modulesr'   r(   s	            <lib/python3.11/site-packages/spyder_kernels/customize/umr.py__init__zUserModuleReloader.__init__   sI   HH#>>#..    (( ;:: ?>> 	8$i0K)K7M ;.<}L  !%S[%5%5%7%7 8 8 #%   *..!2B77}}&0 *..!2B77}}&0s    ,,c                     | j         rdS t          t          |dd          | j                  s|                     |          rdS dS )z(Decide if a module is reloadable or not.F__file__NT)r!   r   getattrr   is_module_in_namelist)r)   modulemodnames      r.   is_module_reloadablez'UserModuleReloader.is_module_reloadableG   sX    ? 		5
D A A $/ / ..w77 ut    c                 p    t          |                    d                    t          | j                  z  S )z@Decide if a module can be reloaded or not according to its name..)setr   r   )r)   r5   s     r.   r3   z(UserModuleReloader.is_module_in_namelistT   s+    7==%%&&T]););;;r7   c                 J   t           j                            d          dk    }|r{	 t          d           d| _        n# t
          $ r Y nw xY w| j        rNddl}i }	 ddl}|                                |d<   n# t
          $ r Y nw xY w|	                    |d           dS dS dS )	z
        Activate Cython support.

        We need to run this here because if the support is
        active, we don't to run the UMR at all.
        SPY_RUN_CYTHONTrueCythonTr   Ninclude_dirs)
setup_argsreload_support)
r#   r$   r%   
__import__r!   r   	pyximportnumpyget_includeinstall)r)   
run_cythonrC   pyx_setup_argsrD   s        r.   r"   z"UserModuleReloader.activate_cythonX   s	    Z^^$455?
 	78$$$"&     7 !   !# LLL5:5F5F5H5HN>22    D !!^15 " 7 7 7 7 7+	7 	77 7s!   > 
A
AA8 8
BBc           	         g | _         t          t          j                                                  D ]M\  }}|| j        vr?|                     ||          r(| j                             |           t          j        |= LMN| j        r<| j         r7| j         }t          ddddd
                    |          z   d           dS dS dS )z
        Delete user modules to force Python to deeply reload them

        Do not del modules which are considered as system modules, i.e.
        modules installed in subdirectories of Python interpreter's binary
        Do not del C modules
        z[4;33mzReloaded modulesz[24mz: z, z[0mN)r    r   r   r   itemsr   r6   appendr(   r   join)r)   r5   r4   modnamess       r.   runzUserModuleReloader.runy   s
    #%#CK$5$5$7$788 	 	OGVd333,,VW== +227;;;G,, 4 < 	ED3 	E.HF((($tyy/B/B*B*B*BD E E E E E	E 	E 	E 	Er7   )NN)	__name__
__module____qualname____doc__r/   r6   r3   r"   rN    r7   r.   r   r      su         -1 -1 -1 -1^  < < <7 7 7BE E E E Er7   r   )
rR   r#   r   spyder_kernels.customize.utilsr   spyder_kernels.py3compatr   r   objectr   rS   r7   r.   <module>rW      s      				 



 : : : : : : 0 0 0 0 0 0 0 0@E @E @E @E @E @E @E @E @E @Er7   