
    Je*S                        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                   j#                  d      Zej                   j#                  d      Z e e
j*                               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(dQdZ)d Z*d Z+dRdZ,dQdZ-d Z.d Z/ e)d      Z0dZ1dd d!d"d#d$d%d&d'd(d)d*d+d,d-Z2g d.Z3d/ Z4d0 Z5d1 Z6d2 Z7dQd3Z8 e8d4      Z9d5Z:g d6Z;dQd7Z<d8 Z=d9 Z>d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJddKdLj                  ej                        dMj                  ej                        dNdOfZAdP ZBy)Sz
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                  R    t        t        j                  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     4/usr/lib/python3/dist-packages/spyder/config/base.pyget_safe_moder   +   s    
 

1233r   c                  R    t        t        j                  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0r   c                  R    t        t        j                  j                  d            S )z*Return True if currently running under CI.CIr   r   r   r   running_in_cir   =   s    

t$%%r   c                  `    t               xr# t        j                  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#    ?Jrzz~~k4@FJJr   c                 ~    t        | t              s| j                  d      } | d   }t        j                  d|      syy)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   s9     gu%--$I99[),r   c                 f    | | j                         dv rd} | S t        xs t        t               } | S )z;Return whether the dev configuration directory should used.>   0falseF)lowerDEVr'   r   )use_dev_config_dirs    r   r-   r-   X   sC    %##%7!&  !F(9+(F$Fr   c                      t         j                  j                  dd      } | j                         st	        |       } t        |       S )NSPYDER_DEBUG )r   r   r   isdigitr   int)	debug_envs    r   get_debug_levelr4   k   s5    

~r2IO	y>r   c                      t        j                  d       t               rNt        }| D ]5  }|j                  j                  t        |      j                  d             7 t        d|       yy)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   sU    MMNO 	4AIIOOCFMM'23	4br r   c                  v    t         j                  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      sD     ||w'		 F"I
 &	r   c                       y)z0Return the default project configuration folder..spyprojectr   r   r   r   get_project_config_folderrN      s    r   c                  j   	 t        j                  t        j                  d            } t        j
                  |       r| S dD ]P  }t        j                  t        j                  j                  |d            } t        j
                  |       r| c S d} R | st        d      y# t        $ r d} Y w xY w)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>>#+>? yy 6 	G ..rzz~~gr/JKDyy	   1 2 2 #  s   (B$ $B21B2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+     xx H
 Or   c                      t         j                  j                  d      } | r*t        j                  |       } | t         j                  d<   | S y)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      sD    
  01J[[,
 (2

#$ r   c                    t               s
t               rt               }nt               rt               }nt        j
                  j                  d      rt        j                  j                  dd      }|st        j                  t               d      }t        j                  |      st        j                  |       t        j                  |t                     }n&t        j                  t               t                     }t        j                  |      sIt               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      s     %'		 '(		 	 	) **..):B?!hh|~yAOyy)KK(88O-?-AB88LN,>,@A 99X!]_8K8MKK!HHXxx(++r   c                  x   t         j                  j                  dd      } t         j                  dk(  rd}nd}| '| j	                  dd      } |dj                  |       fz  }|dj                  t        j                        fz  }t               rg }t        t        j                               }t        d	      D ]s  }t         j                  j                  |d
t        |      z         }t         j                  j                  |      st        j                   |       |j#                  |       u 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      s   ::>>.$7L	ww$


 #++D#6""<0
 	
 szz* K ++-.	q 	&A77<<	>CF+BCD77==&D!%		&
 L)r   c                     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BBr   c                    t        t        j                  |    |d      }|r|S t        |       }t	        j
                  |t        j                        }t	        j                  |      rKt	        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+HHXszz2	::i  {{388CHHY

,K,3$5 6H{{388Hg#>?Hr   c                 z   t        |       }t        j                  |t        j                        }t        j                  |      rKt        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
zz) ++chhsxx	3::'F'.0 1++chhw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%    ::chhx8#**EFFr   c            	      4   t        j                  t        j                  t                    } t        j                  t        j                  | dddd            }t
        j                  j                  d      !|t
        j                  j                  d      v S y)z8Return True if this is a pynsist installation of Spyder.z..pkgs
PYTHONPATHF)rU   rf   r   r   r^   r   r   r   )	base_path	pkgs_paths     r   
is_pynsistr   X  si    CKK12ID$f57I	zz~~l#/BJJNN<888r   
langconfigenEnglishu	   Françaisu   EspañolMagyaru
   Portuguêsu   Русскийu   简体中文u	   日本語DeutschPolskiPersianCroatianTelugu	Ukrainian)r   freshupt_BRruzh_CNjadeplfahrteuk)r   r   r   r   r   r   c            	         t        ddd      } t        j                  |       }|D cg c].  }t        j                  t        j
                  | |            s-|0 }}t        g|z   }t        t        |      t        t              z
        }g }|D ]7  }|t        vrt        sd|z   }t        |       dgc S |j                  |       9 |S c c}w )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   zoUpdate LANGUAGE_CODES (inside config/base.py) if a new translation has been added to Spyder. Currently missing r   )r   r   listdirrU   rX   r^   DEFAULT_LANGUAGElistsetDISABLED_LANGUAGESLANGUAGE_CODESr,   r?   r{   )locale_pathr   dlangsretlangslangerrors          r   get_available_translationsr     s     'x1=?Kjj%GG1399SXXk1-E#FQGEG&E Uc"4556E H 	"~%.045 evOOD!	" O) Hs   .CCc                     	 t        j                         d   } t	               rt        } t        }| Bt               }|D ]3  }| |k(  r| } |S | j                  |      s|j                  |       s0|} |S  |S # t        $ r	 t        } Y mw xY w)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13A6
 *H"57$ 	D$&* O ",,T2OOO4O	 O)  +*+s   A5 5BBc                     	 t        t        d      5 }|j                  |        ddd       y# 1 sw Y   yxY w# t        $ r Y yw xY w)z-Save language setting to language config filewN)open	LANG_FILEr<   EnvironmentError)valuefs     r   save_lang_confr     sD    
)S! 	QGGEN	 	 	 s#   9 -9 69 9 	AAc                     t        j                  t              r*t        t        d      5 } | j	                         }ddd       nt               }t        |       j                  d      t        v rt        }t        |       |S # 1 sw Y   3xY w)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     sy     zz))S! 	Q668D	 	 &'t zz$--tK	 	s   BBc           	         || }d }t        |dd      }t               }t        j                  dk(  r	 |t        j                  d<   n|t        j                  d<   |d	k(  r|S d
dl}	 |j                  | |      fd}|S # t
        $ r |cY S w xY w# t
        $ rD}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                 &    j                  |       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     s     'w1=?K
 H	ww$	"!)BJJv "*

:4$$Wk:	%    	"!!	"  .xj	}}%%&c#0	

 s/   B (B BB	C9C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                 t    | t         j                  } t               }|r| t        j                  |d      k(  ryy)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.
    zContents/MacOS/pythonTF)rG   
executableget_mac_app_bundle_pathrU   r^   )pyexecbpaths     r   running_in_mac_appr  +  s6     ~#%E388E+BCCr   c            	      
   t         j                  j                  dd      } t        j                  dk(  rP| rNt        j                  t        j                  t        j                  t        j                  |                         S y)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   @  sT     ::>>"2D9L
||xL{{3;;s{{3;;|3L'MNOOr   c            	      d   t               rCt        j                  t        j                  t        j                  t                    dd      } | S t               rVt        j                  t        j                  t        j                  t        j                  t                    dd            } | S 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
  R  s    xxCKK$9:|- K 
{{388CKKH0E$F$)+;= >
 K 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                  N   t        dt               t        D ]  } t        |       }t	        j
                  |      st	        j                  |      rt        j                  |       n,t	        j                  |      rt        j                  |       nzt        d|t                y)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  n  sp    	
5FC# 3!%(	::i CJJy$9IIi YYy!MM)$k9623r   r   )NDATAPATH)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    	  	  
     ! 	jjnn\" ZZ^^$?@  :4::< &&s+B/41&
K
" +=  
	8
2<	",J"JC
**G
 ,'	 
 










$ : B%P	*+^ H 	;*$" lF4D"I~}"$9<!=.#%8*"M*11"&&9-44RVV<%y2 3r   