
    G@dd!                         d Z ddlmZ ddl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dlmZ dd	lmZ dd
lmZ  ej        e          Z G d d          Z G d de          ZdS )zPythopath container.    )OrderedDictN)Signal)_)PluginMainContainer)get_conf_path)get_system_pythonpath)PathManagerencodingc                       e Zd ZdZdS )PythonpathActionsmanager_actionN)__name__
__module____qualname__Manager     Clib/python3.11/site-packages/spyder/plugins/pythonpath/container.pyr   r      s        GGGr   r   c                        e Zd Z ed          Z ed          Z eee          Z fdZ	d Z
d Zd Zd Zd Zd	 Zd
 Zd Zd ZddZ xZS )PythonpathContainerpathnot_active_pathc                 d     t                      j        |i | d| _        d| _        d| _        d S )Nr   )super__init__r   r   project_path)selfargskwargs	__class__s      r   r   zPythonpathContainer.__init__+   s<    $)&)))	!r   c                    |                                   |                     d|                                            t          | d          | _        | j        j                            | j                   | j        j                            | j	                   | 
                    t          j        t          d          |                     d          | j                  | _        d S )Nspyder_pythonpathT)parentsynczPYTHONPATH manager
pythonpath)icon	triggered)_load_pythonpathset_confget_spyder_pythonpathr	   path_manager_dialogsig_path_changedconnect_update_python_pathredirect_stdiosig_redirect_stdio_requestedcreate_actionr   r   r   create_iconshow_path_managerpath_manager_actionr   s    r   setupzPythonpathContainer.setup3   s     	 	)4+E+E+G+GHHH $/d#F#F#F  199$	& 	& 	& /77-	/ 	/ 	/ $(#5#5%"##!!,//,	 $6 $
 $
   r   c                     d S Nr   r6   s    r   update_actionsz"PythonpathContainer.update_actionsJ   s    r   c                 J    |                      dt                                 d S )Nsystem_path)r*   r   r6   s    r   on_closezPythonpathContainer.on_closeM   s#    m%:%<%<=====r   c                    |t                               d           d}n t                               d|            |f}|                                 }|| _        || j        _        |                                 }|                     d|                                            | j                            ||           dS )zUpdate active project path.Nz,Update Pythonpath because project was closedr   z$Add to Pythonpath project's path -> r#   )	loggerdebug_get_spyder_pythonpath_dictr   r,   r*   r+   sig_pythonpath_changedemit)r   r   old_path_dict_pnew_path_dict_ps       r   update_active_project_pathz.PythonpathContainer.update_active_project_pathS   s    <LLGHHHDDLLFFFGGG7D ::<< !04 - ::<< 	)4+E+E+G+GHHH#((/JJJJJr   c                 d   | j                             | j        | j        t	                                 | j                                          | j                                          | j                                          | j                                          | j         	                                 dS )zShow path manager dialog.N)
r,   update_pathsr   r   r   r7   showactivateWindowraise_setFocusr6   s    r   r4   z%PythonpathContainer.show_path_managerj   s     	 --It+-B-D-D	
 	
 	

 	 &&((( 	 %%''' //111 ''))) ))+++++r   c                 j    |                                  }d |                                D             }|S )zW
        Return active Spyder PYTHONPATH plus project path as a list of paths.
        c                     g | ]	\  }}||
S r   r   ).0kvs      r   
<listcomp>z=PythonpathContainer.get_spyder_pythonpath.<locals>.<listcomp>   s!    555da15555r   )rA   itemsr   	path_dictr   s      r   r+   z)PythonpathContainer.get_spyder_pythonpathz   s7     4466	55ioo//555r   c                    t                      }|                     dd          }t          j        | j                  rt          | j        dd          5 }|                                                                }ddd           n# 1 swxY w Y   g }|D ]5}t          j        |          s||v r||vr |	                    |           6t          |          | _        	 t          j        | j        | j                   n># t          $ r1}t                              t#          |                     Y d}~nd}~ww xY w|                     d|           |r| j        |z   | _        t          j        | j                  rut          | j        dd          5 }|                                                                }ddd           n# 1 swxY w Y   t          d |D                       | _        dS dS )	zLoad Python paths.r<   r   )defaultrzutf-8r
   Nc              3   B   K   | ]}t          j        |          |V  d S r9   )ospisdir)rO   names     r   	<genexpr>z7PythonpathContainer._load_pythonpath.<locals>.<genexpr>   sB       )= )=$,/IdOO)= )= )= )= )= )= )=r   )r   get_confrZ   isfile	PATH_FILEopenread
splitlinesr[   appendtupler   r   
writelinesOSErrorr?   errorstrr*   NOT_ACTIVE_PATH_FILEr   )	r   r<   previous_system_pathfprevious_pathspathsr   er   s	            r   r)   z$PythonpathContainer._load_pythonpath   s    ,--  $}}]B}GG :dn%% 	%dncG<<< 7!"!4!4!6!67 7 7 7 7 7 7 7 7 7 7 7 7 7 7 E& 
# 
# y  ///D4K4KT""""eDI	!	4>:::: 	! 	! 	!LLQ        	!
 	m[111  	0	K/DI :d/00 	=d/wGGG 81"#&&(("5"5"7"78 8 8 8 8 8 8 8 8 8 8 8 8 8 8#( )= )=/ )= )= )= $= $=D   	= 	=s<   'B		BB#D 
D>'D99D>'GGGc                    t          d D                       }t          fdD                       }|| j        k    s|| j        k    r	 t          j        || j                   t          j        || j                   n># t          $ r1}t          	                    t          |                     Y d}~nd}~ww xY w|| _        || _        dS dS )a  
        Save Spyder PYTHONPATH to configuration folder and update attributes.

        `new_path_dict` is an OrderedDict that has the new paths as keys and
        the state as values. The state is `True` for active and `False` for
        inactive.
        c              3      K   | ]}|V  d S r9   r   )rO   ps     r   r]   z8PythonpathContainer._save_python_path.<locals>.<genexpr>   s"      ..1Q......r   c              3   ,   K   | ]}|         
|V  d S r9   r   )rO   rr   new_path_dicts     r   r]   z8PythonpathContainer._save_python_path.<locals>.<genexpr>   s@        9  9a'4Q'7 9  9  9  9  9  9  9r   N)re   r   r   r   rf   r`   rj   rg   r?   rh   ri   )r   rt   r   r   ro   s    `   r   _save_python_pathz%PythonpathContainer._save_python_path   s    .......  9  9  9  9=  9  9  9 9 9 4943G G G%#D$.999#O$($=? ? ? ? % % %SVV$$$$$$$$% DI#2D    !H Gs   4B 
B='B88B=c                 l    t                      }| j        D ]}d||<   | j        D ]}|| j        v||<   |S )aJ  
        Return Spyder PYTHONPATH plus project path as dictionary of paths.

        The returned ordered dictionary has the paths as keys and the state
        as values. The state is `True` for active and `False` for inactive.

        Example:
            OrderedDict([('/some/path, True), ('/some/other/path, False)])
        T)r   r   r   r   rT   s      r   rA   z/PythonpathContainer._get_spyder_pythonpath_dict   sV      MM	 % 	# 	#D"IdOOI 	? 	?D"$*>>IdOOr   Nc                 X   |                                  }||                     |           |                                  }||k    rd|                                 }t                              d|            |                     d|           | j                            ||           dS dS )z
        Update Python path on language server and kernels.

        The new_path_dict should not include the project path.
        NzUpdate Pythonpath to r#   )rA   ru   r+   r?   r@   r*   rB   rC   )r   rt   rD   rE   pypaths        r   r/   z'PythonpathContainer._update_python_path   s     ::<< $""=111 ::<< o--//11FLL999:::MM-v666',,_oNNNNN	 .-r   r9   )r   r   r   r   r`   rj   r   objectrB   r   r7   r:   r=   rF   r4   r+   r)   ru   rA   r/   __classcell__)r!   s   @r   r   r   $   s       f%%I(=):;;#VFF33    
 
 
.  > > >K K K., , ,   0= 0= 0=d3 3 30  ,O O O O O O O Or   r   )__doc__collectionsr   loggingos.pathr   rZ   qtpy.QtCorer   spyder.api.translationsr   !spyder.api.widgets.main_containerr   spyder.config.baser   spyder.plugins.pythonpath.utilsr   -spyder.plugins.pythonpath.widgets.pathmanagerr	   spyder.utilsr   	getLoggerr   r?   r   r   r   r   r   <module>r      s=     # # # # # #              % % % % % % A A A A A A , , , , , , A A A A A A E E E E E E ! ! ! ! ! ! 
	8	$	$
       UO UO UO UO UO- UO UO UO UO UOr   