
    G@dh                     t   d Z ddlZddlZddlmZ ddlmZmZm	Z	m
Z
mZmZ ddlZddlmZ ddlmZmZmZmZmZ ddlmZmZmZ ddlmZmZ ddlmZmZm Z m!Z! dd	l"m#Z#  ej$        e%          Z&g d
Z' G d de(          Z)	  e)            Z*dS # e+$ r ddl,m-Z-m.Z.  e-j/                    Z0e0" e-ddg          Z0e01                    d            e.j2        dd ed          e.j3        e.j4                  Z5e5e.j3        k    r% e              e.j6        dd ed                      ej7        d           Y dS w xY w)zL
Configuration manager providing access to user/site/project configuration.
    N)AnyDictListOptionalSetTuple)PrefixedTuple)_get_conf_pathsget_conf_pathget_home_dirreset_config_files)CONF_VERSIONDEFAULTSNAME_MAP)ConfigurationKeyConfigurationObserver)
UserConfigMultiUserConfig	NoDefaultcp)check_version)r
   array_builderconsolefind_replacec                      e Zd ZdZ	 	 d,dZd Zd Zd Zd-dZd Z	d	 Z
	 d-d
ededee         fdZ	 	 d.d
edee         dee         fdZd Z	 d/dededefdZdededefdZdefdZdefdZdedefdZdedefdZd Zd Zd Zd Zd Zd Ze fdZ!	 	 d0d!Z"d" Z#d# Z$d$ Z%d1d%Z&d-d&Z'd-d'Z(d-d(Z)d) Z*d* Z+d+ Z,dS )2ConfigurationManagerzN
    Configuration manager to provide access to user/site/project config.
    Nc                    |r|n|                                  }t          j        |          st          j        |           t                      }t          }t          |          D ]q}t          j        	                    |d          }t          j        
                    |          r0t          d||dt          ddd          }|                                }r|| _        || _        t!          t"          ||dt          ddd          | _        | j        j        d         j        | _        i | _        i | _        i | _        t3          j                    | _        g | _        |                                  dS )zV
        Configuration manager to provide access to user/site/project config.
        z
spyder.inispyderFT)pathdefaultsloadversionbackupraw_moderemove_obsoleteN)get_user_config_pathospisdirosmakedirsr   r   reversedr    joinisfiler   r   to_list_parent_active_project_callbackr   r   _user_config_configs_map_old_versionold_spyder_version_plugin_configs_project_configs
_observersweakrefWeakKeyDictionary_observer_map_keys_disabled_options"remove_deprecated_config_locations)	selfparentactive_project_callback	conf_pathr    
conf_pathssite_defaults
conf_fpathsite_configs	            5lib/python3.11/site-packages/spyder/config/manager.py__init__zConfigurationManager.__init__+   s   
 &Fyy4+D+D+F+Fy 	K $%%
 !*-- 	6 	6Ii>>Jw~~j)) 6("*( !$)	 	 	 !, 3 3 5 5(?%+" !	
 	
 	
 *84A 	  " !#  #*";"="= "$ 	//11111    c                 `    |j         }|| j        v r| j                            |d            d S d S N)CONF_SECTIONr6   pop)r>   plugin_instanceconf_sections      rF   unregister_pluginz&ConfigurationManager.unregister_pluginy   s?    &34/// $$\488888 0/rH   c                    |j         }|j        r|r|                     |          }|j        }|r|nd}|j        }|r|ndg i}|j        }|| j        v r"t          d                    |                    t          |||d|dddd	  	        }t          | j        dd          r>	 |                                 n# t          $ r Y nw xY wt          |||d|dddd	  	        }||f| j        |<   d	S d	S d	S )
zRegister plugin configuration.z0.0.0r   z*A plugin with section "{}" already exists!TF)r    r!   r"   r#   r$   r%   r&   external_pluginz54.0.0<N)rK   	CONF_FILEget_plugin_config_pathr   _CONF_NAME_MAPCONF_DEFAULTSr6   RuntimeErrorformatr   r   r5   cleanupEnvironmentError)r>   plugin_classrN   r    r#   name_mapr!   plugin_configs           rF   register_pluginz$ConfigurationManager.register_plugin~   s   #0! .	Ol .	O..|<<D"/G!(5gggG#2H#+?xx(BH#1Ht333" $--3VL-A-AC C C ,! % $
 
 
M T4hDD !))++++'   D !0%#!$)$(
! 
! 
! 3?1ND ...].	O .	O .	O .	Os   #B8 8
CCc                     t          j        t                      d          }t          j        |          rt	          j        |           dS dS )z"Removing old .spyder.ini location.z.spyder.iniN)r(   r-   r   r.   r*   remove)r>   old_locations     rF   r=   z7ConfigurationManager.remove_deprecated_config_locations   sI    x>>:l## 	$Il#####	$ 	$rH   c                 \    || j         }n!|| j        v r| j        |         \  }}n| j         }|S )zM
        Return the active user or project configuration for plugin.
        )r2   r6   )r>   sectionconfigr
   s       rF   get_active_confz$ConfigurationManager.get_active_conf   sC    
 ?&FF,,,,W5IAvv &FrH   c                     t                      }t          j        |d          }t          j        |          st	          j        |           |S )z#Return the user configuration path.rd   )r   r(   r-   r)   r*   r+   )r>   	base_pathr    s      rF   r'   z)ConfigurationManager.get_user_config_path   sA    !OO	x	8,,y 	KrH   c                     t                      }t          j        |d          }|t          d          t          j        |d|          }t          j        |          st          j        |           |S )z%Return the plugin configuration path.pluginsNz&Plugin needs to define `CONF_SECTION`!)r   r(   r-   rW   r)   r*   r+   )r>   plugin_folderrg   r    s       rF   rT   z+ConfigurationManager.get_plugin_config_path   si    !OO	x	9-- GHHHx	9m<<y 	KrH   observerrc   optionc                 f   | j                             |i           }||nd}|                    |t          j                              }||hz  }|||<   || j         |<   | j                            |i           }|                    |t          i                     }||hz  }|||<   || j        |<   dS )a  
        Register an `observer` object to listen for changes in the option
        `option` on the configuration `section`.

        Parameters
        ----------
        observer: ConfigurationObserver
            Object that conforms to the `ConfigurationObserver` protocol.
        section: str
            Name of the configuration section that contains the option
            :param:`option`
        option: Optional[ConfigurationKey]
            Name of the option on the configuration section :param:`section`
            that the object is going to suscribe to. If None, the observer
            will observe any changes on any of the options of the configuration
            section.
        N	__section)r8   getr9   WeakSetr;   set)r>   rk   rc   rl   section_sets
option_setobserver_section_setssection_sets           rF   observe_configurationz*ConfigurationManager.observe_configuration   s    * **7B77!-;!%%fgo.?.?@@
xj 
)V#/  $ 7 ; ;Hb I I+//RAAx)4g&,A)))rH   c                    || j         vrdS | j         |         }|o||         }| j        |         }|9|D ]}||         }|                    |            |                    |           dS ||         }|                    |           dS |D ]9}||         }| j        |         }|D ]}||         }|                    |            :| j                             |           dS )a`  
        Remove an observer to prevent it to receive further changes
        on the values of the option `option` of the configuration section
        `section`.

        Parameters
        ----------
        observer: ConfigurationObserver
            Object that conforms to the `ConfigurationObserver` protocol.
        section: Optional[str]
            Name of the configuration section that contains the option
            :param:`option`. If None, the observer is unregistered from all
            options for all sections that it has registered to.
        option: Optional[ConfigurationKey]
            Name of the configuration option on the configuration
            :param:`section` that the observer is going to be unsubscribed
            from. If None, the observer is unregistered from all the options of
            the section `section`.
        N)r;   r8   r`   rL   )r>   rk   rc   rl   observer_sectionssection_optionssection_observersoption_observerss           rF   unobserve_configurationz,ConfigurationManager.unobserve_configuration  s2   . 4222F 3H=/8O $ 8~- 6 6F'8'@$$++H5555!%%g.....#4V#<  ''11111, 6 6"3G"<$(OG$<!- 6 6F'8'@$$++H55556 #''11111rH   c                 D    | j         D ]}|                     |           dS )zV
        Notify all the observers subscribed to all the sections and options.
        N)r8   notify_section_all_observers)r>   rc   s     rF   notify_all_observersz)ConfigurationManager.notify_all_observers1  s6      	7 	7G--g6666	7 	7rH   Trecursive_notificationc                    |r|                      |           t          |t                    r|rt          |          }|g k    rtt          |          }t	          |          dk    r|d         }|                     ||          }|                     |||           |                    d           |g k    rdS dS |dk    r|                      |           dS |                     ||          }|                     |||           dS )a  
        Notify observers of a change in the option `option` of configuration
        section `section`.

        Parameters
        ----------
        section: str
            Name of the configuration section whose option did changed.
        option: ConfigurationKey
            Name/Path to the option that did changed.
        recursive_notification: bool
            If True, all objects that observe all changes on the
            configuration section and objects that observe partial tuple paths
            are notified. For example if the option `opt` of section `sec`
            changes, then the observers for section `sec` are notified.
            Likewise, if the option `(a, b, c)` changes, then observers for
            `(a, b, c)`, `(a, b)` and a are notified as well.
           r   rn   N)_notify_section
isinstancetuplelistlenro   _notify_optionrL   )r>   rc   rl   r   option_listtuple_optionvalues          rF   notify_observersz%ConfigurationManager.notify_observers8  s)   , " 	*  )))fe$$ 	<)? 	< v,,K##$[11{##q((#/?L,77##G\5AAA### ###### $$$$W-----&11##GVU;;;;;rH   r   c                    | j                             |i           }|                    |t          i                     }||f| j        v r"t                              d| d|            d S t          |          dk    r t                              d| d|            t          |          D ]?}	 |                    |||           # t          $ r | 
                    |           Y <w xY wd S )Nz8Don't send notification to observers of disabled option z in configuration section r   z%Sending notification to observers of z! option in configuration section )r8   ro   rq   r<   loggerdebugr   r   on_configuration_changerW   r|   )r>   rc   rl   r   rz   r{   rk   s          rF   r   z#ConfigurationManager._notify_optionf  sF    O//<<,00RAAV 666LL?? ?5<? ?   F!""Q&&LL3 3 3)03 3  
 -.. 	7 	7H700%HHHH 7 7 7,,X666667	7 	7s   1C		C+*C+c                 |    t          |                     |          pg           }|                     |d|           d S )Nrn   )dictitemsr   )r>   rc   section_valuess      rF   r   z$ConfigurationManager._notify_section~  s>    djj117R88G[.AAAAArH   c                    | j         |         }t                      }t                              |d           |D ]Y}t	          |t
                    r|                    |           -	 |                     ||           E# t          j        $ r Y Vw xY w|D ].}	 |                     ||           # t          j        $ r Y +w xY wdS )z?Notify all the observers subscribed to any option of a section.rn   N)	r8   r	   CONFr   r   r   add_pathr   NoOptionError)r>   rc   r{   section_prefixrl   prefixs         rF   r~   z1ConfigurationManager.notify_section_all_observers  s   ?73&g{333& 		 		F&%(( ''////))'6::::'    D
 % 	 	F%%gv6666#   	 	s$   'A>>BBB//C Cc                 ~    t                               d| d|            | j                            ||f           dS )z0Disable notitications for `option` in `section`.z!Disable notifications for option  option in section N)r   r   r<   appendr>   rc   rl   s      rF   disable_notificationsz*ConfigurationManager.disable_notifications  sZ       	
 	
 	
 	%%w&788888rH   c                     t                               d| d|            	 | j                            ||f           dS # t          $ r Y dS w xY w)z9Restore notitications for disabled `option` in `section`.z!Restore notifications for option r   N)r   r   r<   r`   
ValueErrorr   s      rF   restore_notificationsz*ConfigurationManager.restore_notifications  s       	
 	
 	
	"))7F*;<<<<< 	 	 	DD	s   A   
AAc                 l    |                      |          r|| j        vr|| j        |<   dS dS || _        dS )z
        Register configuration with `root_path`.

        Useful for registering project configurations as they are opened.
        N)is_project_rootr7   _site_config)r>   	root_pathrd   s      rF   register_configz$ConfigurationManager.register_config  sS     	** 	' 55539%i000 65 !'DrH   c                 6    | j         }| j         r
 |            S dS )z5Return the `root_path` of the current active project.N)r1   )r>   callbacks     rF   get_active_projectz'ConfigurationManager.get_active_project  s+    0( 	8::	 	rH   c                     dS )z;Check if `root_path` corresponds to a valid spyder project.F )r>   r   s     rF   r   z$ConfigurationManager.is_project_root  s    urH   c                     t          j        |dd          }t          j        |          st          j        |           dS dS )z&Return the project configuration path.z.spyprojrd   N)r(   r-   r)   r*   r+   )r>   project_rootr    s      rF   get_project_config_pathz,ConfigurationManager.get_project_config_path  sE    xj(;;y 	K	 	rH   c                 V    |                      |          }|                    |          S )z9Return all the items option/values for the given section.)re   r   r>   rc   rd   s      rF   r   zConfigurationManager.items  s'    %%g..||G$$$rH   c                 V    |                      |          }|                    |          S )z-Return all the options for the given section.)re   optionsr   s      rF   r   zConfigurationManager.options  s'    %%g..~~g&&&rH   c                    |                      |          }t          |t                    rt          |          dk    r|d         }t          |t                    r|d         }|dd         }|d         }|                    ||i           }|}	|D ]}
|	                    |
i           }	|	                    |d          }| |}|t
          u rt          j        ||          n|                    |||          }|S )z
        Get an `option` on a given `section`.

        If section is None, the `option` is requested from default section.
        r   r   r   )rc   rl   defaultN)re   r   r   r   ro   r   r   r   )r>   rc   rl   r   rd   base_optionintermediate_optionslast_option	base_confnext_ptroptr   s               rF   ro   zConfigurationManager.get  s    %%g..fe$$ 	V)9)9AYFfe$$ 	P )K#)!B$<  *K

R # A AI H+ 1 1#<<R00LLd33E}i''*67;;;JJwvwJOOErH   Fc                    |}t          |t                    r^|d         }	|dd         }
|d         }|                     ||	i           }|}|
D ]}|                    |i           }|||<   |} |||<   |}|	}|                     |          }|                    |||||           |r|                     |||           dS dS )z
        Set an `option` on a given `section`.

        If section is None, the `option` is added to the default section.
        r   r   r   )rc   rl   r   verbosesaveN)r   r   ro   re   rq   r   )r>   rc   rl   r   r   r   r   notificationoriginal_optionr   r   r   r   conf_ptrr   r   rd   s                    rF   rq   zConfigurationManager.set  s    !fe$$ 	! )K#)!B$<  *K+r::I H+ $ $#<<R00 (#$)H[!E F%%g..

76" 	 	/ 	/ 	/ 	B!!*@B B B B B	B 	BrH   c                    |                      |          }t          |t                    rG|d         }|dd         }|d         }|                    ||          }|}|D ]
}	||	         }||         S |                    ||          S )z
        Get Default value for a given `section` and `option`.

        This is useful for type checking in `get` method.
        r   r   r   )re   r   r   get_default)
r>   rc   rl   rd   r   r   r   base_defaultr   r   s
             rF   r   z ConfigurationManager.get_default  s     %%g..fe$$ 
	) )K#)!B$<  *K!--g{CCL#H+ ) )#C=K((!!'6222rH   c                 Z    |                      |          }|                    |           dS )z+Remove `section` and all options within it.N)re   remove_sectionr   s      rF   r   z#ConfigurationManager.remove_section*  s/    %%g..g&&&&&rH   c                    |                      |          }t          |t                    r|d         }|dd         }|d         }|                     ||          }|}|D ]
}	||	         }|                    |           |                     ||           |                     ||           dS |                    ||           dS )zRemove `option` from `section`.r   r   r   N)re   r   r   ro   rL   rq   r   remove_option)
r>   rc   rl   rd   r   r   r   r   r   r   s
             rF   r   z"ConfigurationManager.remove_option/  s    %%g..fe$$ 	2 )K#)!B$<  *K+66I H+ ) )#C=LL%%%HHWk***!!';77777  &11111rH   c                     |                      |          }|                    |           |r/||                     |           dS |                                  dS dS )zReset config to Default values.rc   N)re   reset_to_defaultsr~   r   )r>   rc   r   rd   s       rF   r   z&ConfigurationManager.reset_to_defaultsA  sv    %%g..   111 	,"11':::::))+++++		, 	,rH   c                 j   |                                 }| j        }|| j        v r| j        |         \  }}|j        s| j        }no|| j        v r| j        |         \  }}|j        s| j        }nG|| j                                        t
          z   v r| j        }nt          t          d                    |S )z
        Return the shortcut configuration for global or plugin configs.

        Context must be either '_' for global or the name of a plugin.
        z=Shortcut context must match '_' or the plugin `CONF_SECTION`!)lowerr2   r6   rS   sectionsEXTRA_VALID_SHORTCUT_CONTEXTSr   r
   )r>   contextplugin_namerd   r[   s        rF   _get_shortcut_configz)ConfigurationManager._get_shortcut_configM  s     --//"$...#'#7#D L&  ) +*,,,#'#7#@ L&  ) +**335589 : :&FFQ  8 9 9 : : : rH   c                     |                      ||          }|                    d|dz   |                                z             S )z
        Get keyboard shortcut (key sequence string).

        Context must be either '_' for global or the name of a plugin.
        	shortcuts/)r   ro   r   )r>   r   namer   rd   s        rF   get_shortcutz!ConfigurationManager.get_shortcutm  s>     **7K@@zz+w}tzz||'CDDDrH   c                 l    |                      ||          }|                    d|dz   |z   |           dS )z
        Set keyboard shortcut (key sequence string).

        Context must be either '_' for global or the name of a plugin.
        r   r   N)r   rq   )r>   r   r   keystrr   rd   s         rF   set_shortcutz!ConfigurationManager.set_shortcutv  s>     **7K@@

;# 4f=====rH   c                 \    ddl m} |                     ||          } ||||||          }|S )z
        Create a Shortcut namedtuple for a widget.

        The data contained in this tuple will be registered in our shortcuts
        preferences page.
        r   )_config_shortcut)spyder.config.guir   r   )r>   actionr   r   r?   r   r   scs           rF   config_shortcutz$ConfigurationManager.config_shortcut  sH     	766666""7D11fgtVVDD	rH   c              #   b  K   | j                             d          D ]0\  }}|dk    rd|vr |                    dd          \  }}|||fV  1| j                                        D ]G\  }\  }}|                    d          }|r(|D ]%\  }}|                    dd          \  }}|||fV  &HdS )z Iterate over keyboard shortcuts.r   enableadditional_configurationr   r   N)r2   r   splitr6   )r>   context_namer   r   r   __r]   r   s           rF   iter_shortcutsz#ConfigurationManager.iter_shortcuts  s     $($5$;$;K$H$H 	, 	, L&x'')== , 2 23 : :tV++++'+';'A'A'C'C 	0 	0#B#]!''44E 0,1 0 0(L&$0$6$6sA$>$>MGT!4/////	0 	0rH   c                     | j                             d           | j                                        D ]\  }\  }}|                    d           dS )z+Reset keyboard shortcuts to default values.r   r   N)r2   r   r6   r   )r>   r   r]   s      rF   reset_shortcutsz$ConfigurationManager.reset_shortcuts  sl    ++K+@@@'+';'A'A'C'C 	A 	A#B#]++K+@@@@	A 	ArH   )NNNrJ   )NN)T)FTTT)NT)-__name__
__module____qualname____doc__rG   rO   r^   r=   re   r'   rT   r   strr   r   rv   r|   r   boolr   r   r   r   r~   r   r   r   r   r   r   r   r   r   ro   rq   r   r   r   r   r   r   r   r   r   r   r   rH   rF   r   r   &   sn         =AL2 L2 L2 L2\9 9 9
1O 1O 1Of$ $ $     
 
 
" DH#B #B(=#B'*#B '//?&@#B #B #B #BN :>EI-2 -2*?-2)1#-2 )11A(B-2 -2 -2 -2^7 7 7 9=,< ,<"%,<!1,< 26,< ,< ,< ,<\7c 73C 7!7 7 7 70Bs B B B BC    09S 9:J 9 9 9 9	S 	:J 	 	 	 	' ' '      % % %
' ' '
 ,5    < ?C6:B B B B>3 3 3*' ' '
2 2 2$, , , ,   @E E E E> > > >  0 0 0"A A A A ArH   r   )QApplicationQMessageBoxSpyderz--no-sandboxzThere was an error while loading Spyder configuration options. You need to reset them for Spyder to be able to launch.

Do you want to proceed?z$Spyder configuration files resetted!)8r   loggingr*   os.pathr    r(   typingr   r   r   r   r   r   r9   spyder.api.utilsr	   spyder.config.baser
   r   r   r   r   spyder.config.mainr   r   r   spyder.config.typesr   r   spyder.config.userr   r   r   r   spyder.utils.programsr   	getLoggerr   r   r   objectr   r   	Exceptionqtpy.QtWidgetsr   r   instanceappsetApplicationNamecriticalYesNoreset_replyinformation_exitr   rH   rF   <module>r
     s   
  				       8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8  + * * * * *H H H H H H H H H H H H H H ? ? ? ? ? ? ? ? ? ? G G G G G G G G I I I I I I I I I I I I / / / / / / 
	8	$	$! ! ! }	A }	A }	A }	A }	A6 }	A }	A }	A@!!DDD   88888888  ,

!
!C {lHn566x(((&+&h	 $ 	% 	% 	) )K ko%%(A455	7 	7 	7 BHQKKKKKK5s    
B B'D76D7