
    G@dFR                         d Z ddlZddlZddlmZ ddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZ ddlmZ ej                            d          Zej                            d          Z e e
j                                                  d          d         Zd	 Zd
 Zd Zd Zd ZefdZej        Zej         Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(dOdZ)d Z*d Z+dPdZ,dOdZ-d Z.d Z/ e)d          Z0dZ1d d!d"d#d$d%d&d'd(d)d*
Z2d+d,gZ3d- Z4d. Z5d/ Z6d0 Z7dOd1Z8 e8d2          Z9d3Z:g d4Z;dOd5Z<d6 Z=d7 Z>d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHddIdJ?                    ej@                  dK?                    ej@                  dLdMfZAdN ZBdS )Qz
Spyder base configuration management

This file only deals with non-GUI configuration features
(in other words, we won't import any PyQt object here, avoiding any
sip API incompatibility issue in spyder's non-gui modules)
    N)__version__)encoding
SPYDER_DEVSPYDER_USE_DEV_CONFIG_DIR-c                  Z    t          t          j                            d                    S )z
    Make Spyder use a temp clean configuration directory for testing
    purposes SPYDER_SAFE_MODE can be set using the --safe-mode option.
    SPYDER_SAFE_MODEboolosenvironget     2lib/python3.11/site-packages/spyder/config/base.pyget_safe_moder   +   s!    
 
122333r   c                  Z    t          t          j                            d                    S )z
    Return True if currently running under pytest.

    This function is used to do some adjustment for testing. The environment
    variable SPYDER_PYTEST is defined in conftest.py.
    SPYDER_PYTESTr   r   r   r   running_under_pytestr   3   s      
//000r   c                  Z    t          t          j                            d                    S )z*Return True if currently running under CI.CIr   r   r   r   running_in_cir   =   s    
t$$%%%r   c                  f    t                      o#t          j                            dd          dk    S )z>Return True if currently running under CI with conda packages.	USE_CONDANtrue)r   r   r   r   r   r   r   running_in_ci_with_condar   B   s&    ??Jrz~~k4@@FJJr   c                     t          | t                    s|                     d          } | d         }t          j        d|          sdS dS )z
    Return true if version is stable, i.e. with letters in the final component.

    Stable version examples: ``1.2``, ``1.3.4``, ``1.0.5``.
    Non-stable version examples: ``1.3.4beta``, ``0.1.0rc1``, ``3.0.0dev0``.
    .r   z[a-zA-Z]TF)
isinstancetuplesplitresearch)version	last_parts     r   is_stable_versionr'   G   sN     gu%% %--$$I9[),, tur   c                 t    | |                                  dv rd} nt          pt          t                     } | S )z;Return whether the dev configuration directory should used.N>   0falseF)lowerDEVr'   r   )use_dev_config_dirs    r   r-   r-   X   sC    %##%%77!& F(9+(F(F$Fr   c                      t           j                            dd          } |                                 st	          |           } t          |           S )NSPYDER_DEBUG )r   r   r   isdigitr   int)	debug_envs    r   get_debug_levelr4   k   sB    
~r22I $OO	y>>r   c                      t          j        d           t                      rYt          }| D ]<}|j                            t          |                              d                     =t          d|           dS dS )zOutput debug messages to stdoutz:debug_print is deprecated; use the logging module instead.zutf-8r0   fileN)	warningswarnr4   STDOUTbufferwritestrencodeprint)messagessms      r   debug_printrC   r   s    MNOOO  	4 	4AIOOCFFMM'223333br r   c                  ~    t           j                            d          rd} nd} | dz   } t                      r| dz   } | S )zDReturn the configuration subfolder for different ooperating systems.linuxspyderz.spyderz-py3z-dev)sysplatform
startswithr-   )	SUBFOLDERs    r   get_conf_subfolderrK      sT     |w'' 			 F"I
  '&	r   c                      dS )z0Return the default project configuration folder..spyprojectr   r   r   r   get_project_config_folderrN      s    =r   c                  j   	 t          j        t          j        d                    } n# t          $ r d} Y nw xY wt          j        |           r| S dD ]N}t          j        t          j                            |d                    } t          j        |           r| c S d} O| st          d          dS )zReturn user home directory.~r0   )HOMEUSERPROFILETMPzgPlease set the environment variable HOME to your user/home directory path so Spyder can start properly.N)
r   to_unicode_from_fsosp
expanduser	Exceptionisdirr   r   r   RuntimeError)pathenv_vars     r   get_home_dirr\      s     *3>#+>+>??    y 2 6 	 	G .rz~~gr/J/JKKDy  	2  1 2 2 2	2 	2s   &) 88c                  ^    t          j        t          j                    dt                    } | S )zU
    Return the path to a temp clean configuration dir, for tests and safe mode.
    zspyder-clean-conf-dirs)rU   jointempfile
gettempdirCLEAN_DIR_ID)conf_dirs    r   get_clean_conf_dirrc      s.     x  H
 Or   c                      t           j                            d          } | r%t          j        |           } | t           j        d<   | S dS )z|
    Use a custom configuration directory, passed through our command
    line options or by setting the env var below.
    SPYDER_CONFDIRN)r   r   r   rU   abspath)
custom_dirs    r   get_custom_conf_dirrh      sN    
  011J [,,
 (2
#$ r   c                 D   t                      st                      rt                      }nt                      rt                      }nt          j                            d          rt          j        	                    dd          }|s!t          j        t                      d          }t          j        |          st          j        |           t          j        |t                                }n-t          j        t                      t                                }t          j        |          sSt                      st                      st                      rt          j        |           nt          j        |           | |S t          j        ||           S )zDReturn absolute path to the config file with the specified filename.rE   XDG_CONFIG_HOMEr0   z.config)r   r   rc   rh   rG   rH   rI   r   r   r   rU   r^   r\   rX   makedirsrK   mkdir)filenamerb   xdg_config_homes      r   get_conf_pathro      sl     B B%''			 B '((		 	 	)	) B *..):B?? 	B!h|~~yAAOy)) 	)K(((8O-?-A-ABB8LNN,>,@,@AA 9X !! 	]__ 	8K8M8M 	K!!!!HXx(+++r   c                     t           j                            dd          } t           j        dk    rd}nd}| /|                     dd          } |d                    |           fz  }|d                    t          j                  fz  }t                      rg }t          t          j                              }t          d	          D ]z}t           j                            |d
t          |          z             }t           j                            |          st          j        |           |                    |           {t%          |          }|S )z?Return the files that can update system configuration defaults.CONDA_PREFIXNnt)zC:/ProgramData/spyder)z/etc/spyderz/usr/local/etc/spyder\/z{}/etc/spyder   zsite-config-)r   r   r   namereplaceformatrG   prefixr   r=   r_   r`   rangerZ   r^   rX   rk   appendr!   )rq   SEARCH_PATHsearch_paths	tmpfolderirZ   s         r   get_conf_pathsr      sC   :>>.$77L	w$


 #++D#66""<00
 	
 sz** K  *+--..	q 	& 	&A7<<	>CFF+BCCD7==&& "D!!!%%%%L))r   c                 x    t          j        t          j        t          j        |          j                            S )z!Return module *modname* base path)rU   rf   dirnamerG   modules__file__)modnames    r   get_module_pathr   $  s&    ;s{3;w#7#@AABBBr   DATAPATHc                    t          t          j        |          |d          }|r|S t          |           }t	          j        |t          j                  }t	          j        |          rDt	          j        t	          j        t	          j        |t          j                  |                     }|'t	          j        t	          j        ||                    }|S )zReturn module *modname* data path
    Note: relpath is ignored if module has an attribute named *attr_name*

    Handles py2exe/cx_Freeze distributionsr0   )	getattrrG   r   r   rU   r^   pardirisfilerf   )r   relpath	attr_namedatapath	parentdirs        r   get_module_data_pathr   )  s    
 s{7+Y;;H "7++HXsz22	:i   	6 {38CHY
,K,K,3$5 $5 6 6H{38Hg#>#>??Hr   c                 d   t          |           }t          j        |t          j                  }t          j        |          rDt          j        t          j        t          j        |t          j                  |                     }|'t          j        t          j        ||                    }|S )a:  Return module *modname* source path
    If *basename* is specified, return *modname.basename* path where
    *modname* is a package containing the module *basename*

    *basename* is a filename (not a module name), so it must include the
    file extension: .py or .pyw

    Handles py2exe/cx_Freeze distributions)r   rU   r^   r   r   rf   )r   basenamesrcpathr   s       r   get_module_source_pathr   >  s     g&&G#*--I
z) 1 +chsx	3:'F'F'.0 0 1 1+chw99::Nr   c                  ~    t          j        t          j        t          d          t           j                            S )z@Return True if this is a py2exe/cx_Freeze distribution of SpyderrF   )rU   r   r^   r   r   r   r   r   is_py2exe_or_cx_Freezer   S  s(    :chx88#*EEFFFr   c            	      0   t          j        t          j        t                              } t          j        t          j        | dddd                    }t
          j                            d          !|t
          j                            d          v S dS )z8Return True if this is a pynsist installation of Spyder.z..pkgs
PYTHONPATHNF)rU   rf   r   r   r^   r   r   r   )	base_path	pkgs_paths     r   
is_pynsistr   X  ss    CK1122ID$f557 7I	z~~l##/BJNN<88885r   
langconfigenEnglishu	   Françaisu   EspañolMagyaru
   Portuguêsu   Русскийu   简体中文u	   日本語DeutschPolski)
r   freshupt_BRruzh_CNjadeplr   r   c                  >   t          ddd          t          j                  } fd| D             }t          g|z   }t	          t          |          t          t                    z
            }|D ](}|t          vrt          rd}t          |           dgc S )|S )a  
    List available translations for spyder based on the folders found in the
    locale folder. This function checks if LANGUAGE_CODES contain the same
    information that is found in the 'locale' folder to ensure that when a new
    language is added, LANGUAGE_CODES is updated.
    rF   locale
LOCALEPATHr   r   c                 b    g | ]+}t          j        t          j        |                    )|,S r   )rU   rX   r^   ).0dlocale_paths     r   
<listcomp>z.get_available_translations.<locals>.<listcomp>  s4    GGG139SXk1-E-E#F#FGQGGGr   z[Update LANGUAGE_CODES (inside config/base.py) if a new translation has been added to Spyderr   )
r   r   listdirDEFAULT_LANGUAGElistsetDISABLED_LANGUAGESLANGUAGE_CODESr,   r?   )r   langslangerrorr   s       @r   get_available_translationsr   {  s     'x1=? ? ?Kj%%GGGGGGGGE&E Uc"455566E   ~%% De6MMM & Lr   c                  <   	 t          j                    d         } n# t          $ r
 t          } Y nw xY wt	                      rt          } t          }| Kt                      }|D ]:}| |k    r| } n/|                     |          s|                    |           r|} n;|S )a  
    If Spyder has a translation available for the locale language, it will
    return the version provided by Spyder adjusted for language subdifferences,
    otherwise it will return DEFAULT_LANGUAGE.

    Example:
    1.) Spyder provides ('en',  'de', 'fr', 'es' 'hu' and 'pt_BR'), if the
    locale is either 'en_US' or 'en' or 'en_UK', this function will return 'en'

    2.) Spyder provides ('en',  'de', 'fr', 'es' 'hu' and 'pt_BR'), if the
    locale is either 'pt' or 'pt_BR', this function will return 'pt_BR'
    r   )r   getdefaultlocale
ValueErrorr   r   r   rI   )locale_languagelanguagespyder_languagesr   s       r   get_interface_languager     s    + 133A6 + + +*+  +*H"577$ 	 	D$&&*!,,T22 OOO44
 Os    00c                     	 t          t          d          5 }|                    |            ddd           dS # 1 swxY w Y   dS # t          $ r Y dS w xY w)z-Save language setting to language config filewN)open	LANG_FILEr<   EnvironmentError)valuefs     r   save_lang_confr     s    
)S!! 	QGGENNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   s.   A :A >A >A 
AAc                  Z   t          j        t                    rBt          t          d          5 } |                                 }ddd           n# 1 swxY w Y   nt                      }t          |           |                    d          t          v rt          }t          |           |S )z
    Load language setting from language config file if it exists, otherwise
    try to use the local settings if Spyder provides a translation, or
    return the default if no translation provided.
    rN
)
rU   r   r   r   readr   r   stripr   r   )r   r   s     r   load_lang_confr     s     z) )S!! 	Q6688D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 &''t zz$---tKs   AAAc           	         || }d }t          |dd          }t                      }t          j        dk    r#	 |t          j        d<   n!# t
          $ r |cY S w xY w|t          j        d<   |d	k    r|S d
dl}	 |                    | |          fd}|S # t
          $ r:}t          d| d|j	        j
         d| t          j                   |cY d}~S d}~ww xY w)z0Return translation callback for module *modname*Nc                     | S )z&Dumb function to not use translations.r   )xs    r   translate_dumbz'get_translation.<locals>.translate_dumb  s    r   r   r   r   rr   LANGLANGUAGEr   r   c                 .                         |           S N)gettext)r   _transs    r   translate_gettextz*get_translation.<locals>.translate_gettext  s    >>!$$$r   z Could not load translations for z	 due to: z - r6   )r   r   r   rv   r   rW   r   translationr?   	__class____name__rG   stderr)	r   r   r   r   r   r   r   excr   s	           @r   get_translationr     so      'w1=? ? ?K
 H	w$	"!)BJv 	" 	" 	"!!!!	" "*
:4NNN$$Wk::	% 	% 	% 	% 	%     0x 0 0}%0 0*-0 0	
 	
 	
 	

 s/   A
 
AA8B 
C/CCCrF   F)naninfinftylittle_endiancolorbar_doc	typecodes__builtins____main____doc__NaNInfInfinitysctypesrcParamsrcParamsDefaultsctypeNAtypeNAFalse_True_c                 x    | t           j        } t                      }|r| t          j        |d          k    rdS dS )aI  
    Check if Python executable is located inside a standalone Mac app.

    If no executable is provided, the default will check `sys.executable`, i.e.
    whether Spyder is running from a standalone Mac app.

    This is important for example for the single_instance option and the
    interpreter status in the statusbar.
    NzContents/MacOS/pythonTF)rG   
executableget_mac_app_bundle_pathrU   r^   )pyexecbpaths     r   running_in_mac_appr   "  sD     ~#%%E 38E+BCCCCtur   c            	          t           j                            dd          } t          j        dk    rL| rJt          j        t          j        t          j        t          j        |                                         S dS )z
    Return the full path to the macOS app bundle. Otherwise return None.

    EXECUTABLEPATH environment variable only exists if Spyder is a macOS app
    bundle. In which case it will always end with
    "/<app name>.app/Conents/MacOS/Spyder".
    EXECUTABLEPATHNdarwin)r   r   r   rG   rH   rU   r   rf   )app_exe_paths    r   r   r   7  s_     :>>"2D99L
|xL{3;s{3;|3L3L'M'MNNOOOtr   c            	      f   t                      r@t          j        t          j        t          j        t                              dd          } nbt                      rRt          j        t          j        t          j        t          j        t                              dd                    } nd} | S )zAReturn the path to the Micromamba executable bundled with Spyder.bin
micromambazmicromamba.exeN)r   rU   r^   r   r   r   rf   )rZ   s    r   get_spyder_umamba_pathr  I  s     xCK$9$9::|- -	 {38CKH0E0E$F$F$)+;= = > > Kr   help
onlinehelprZ   zpylint.resultsz
spyder.iniztemp.pyztemp.spydataztemplate.pyz
history.pyzhistory_internal.py
workingdirz	.projectsrM   z.ropeprojectzmonitor.logzmonitor_debug.logzrope.logzspyder.lockzconfig{}spyder.inizconfig{}transient.inilsp_root_pathpluginsc                  `   t          dt                     t          D ]} t          |           }t	          j        |          st	          j        |          rt          j        |           n*t	          j	        |          rt          j        |           nxt          d|t                     dS )zRemove all config filesz)*** Reset Spyder settings to defaults ***r6   z	removing:N)r?   STDERRSAVED_CONFIG_FILESro   rU   r   islinkr   removerX   shutilrmtree)fname	cfg_fnames     r   reset_config_filesr  e  s    	
5FCCCC# 3 3!%((	:i   	CJy$9$9 	Ii    Yy!! 	M)$$$$k96222223 3r   r   )Nr   )Cr   r   r   os.pathrZ   rU   r#   r  rG   r_   uuidr8   rF   r   spyder.utilsr   r   r   r,   USE_DEV_CONFIG_DIRr=   uuid4r"   ra   r   r   r   r   r'   r-   stdoutr:   r   r  r4   rC   rK   rN   r\   rc   rh   ro   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _	CHECK_ALLEXCLUDED_NAMESr   r   r  rx   sepr  r  r   r   r   <module>r     s     				       				  



          ! ! ! ! ! ! 	jnn\"" Z^^$?@@  s:4:<<  &&s++B/4 4 41 1 1& & &
K K K
  " +=     
	      8  
2 2 2<	 	 	  ", ", ", ",J" " "JC C C
   *   *G G G
   M,''	 
 






  D\   8% % %P	 	 	  *+ + + +^ OH 	; ; ;   *  $  " lF4D"I~}"$9<!=.#%8*"M*11"&99-44RV<<%y2 3 3 3 3 3r   