
    G@d(                        d Z ddlmZ ddlm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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ZddlZddlmZmZmZ ddlmZ dd	lmZ  ej          ej!        e"                    Z# G d
 de$          Z%d.dZ&d Z'd Z(d Z)d Z*d Z+d.dZ,d Z-d Z.d Z/d Z0d Z1d Z2d Z3d Z4d Z5d Z6d Z7d/dZ8ddg g fdZ9d  Z:d! Z;	 d/d"Z<d# Z=d$ Z>d% Z?	 	 d0d&Z@d' ZAd( ZBd) ZCd* ZDd+ ZEd, ZFd- ZGdS )1zRunning programs utilities.    )literal_eval)getuser)dedentN)parse)running_under_pytestget_home_dirrunning_in_mac_app)encoding)get_python_executablec                       e Zd ZdS )ProgramErrorN)__name__
__module____qualname__     5lib/python3.11/site-packages/spyder/utils/programs.pyr   r   '   s        Dr   r   c                    t          j                    g}t          j        dk    r|                    d           n8t          j        t                                }|                    d|z              t          j	        | }t          j
        |          st          j        |           | |                    |            t          j	        | }t          j
        |          st          j        |           |S )zP
    Return temporary Spyder directory, checking previously that it exists.
    ntspyderzspyder-)tempfile
gettempdirosnameappendr
   to_unicode_from_fsr   ospjoinisdirmkdir)suffixto_joinusernametempdirs       r   get_temp_dirr%   +   s     "$$%G	w$x    .wyy99y8+,,,h G9W 
vh G9W 
Nr   c                    t                      }g }t          j        dk    r+|                     d          rt	          j        |           r| S t          j        dk    rIt	          j        |dd          t	          j        ddd          g}|t	          j        |d          d	g}g d
}nIt	          j        |ddd          g}|t	          j        |dd          dt	          j        dd          g}g d}d t          j
        ||          D             }|                    ||z              t          j        d                             t          j                  |z   D ]/}t	          j        ||           }t	          j        |          r|c S 0dS )a  
    Return program absolute path if installed in PATH.
    Otherwise, return None.

    Also searches specific platform dependent paths that are not already in
    PATH. This permits general use without assuming user profiles are
    sourced (e.g. .bash_Profile), such as when login shells are not used to
    launch Spyder.

    On macOS systems, a .app is considered installed if it exists.
    darwin.appposixz.pyenvbinz/usrlocaloptz/opt)
mambaforge
miniforge3	miniforge
miniconda3	anaconda3	minicondaanacondaz	pyenv-winAppDataLocalzC:\ProgramData)
Mambaforge
Miniforge3	Miniforge
Miniconda3	Anaconda3	MinicondaAnacondac                 4    g | ]}t          j        g |d R  S )condabin)r   r   ).0ps     r   
<listcomp>z(is_program_installed.<locals>.<listcomp>m   s-    GGG!SX%q%*%%%GGGr   PATHN)r   sysplatformendswithr   existsr   r   r   	itertoolsproductextendenvironsplitpathsepisfile)	basenamehome	req_pathspyenvabcondapathabspaths	            r   is_program_installedrX   G   s    >>DI  f%% 	!Jx   	! 	w'HT8U++HVWe,,

 38D%((&1A A A $+u==>38D)W55SXfm446A A A HGy/@A/F/FGGGEUU]###
6"((44y@  (4**:g 	NNN	 r   c                       g}t           j        dk    r)d}                     |          s fd|D              gz   }|D ]}t          |          }|r|c S dS )z
    Find program in PATH and return absolute path

    Try adding .exe or .bat to basename on Windows platforms
    (return None if not found)
    r   ).exe.bat.cmdc                     g | ]}|z   S r   r   )r@   extrO   s     r   rB   z find_program.<locals>.<listcomp>   s    :::X^:::r   N)r   r   rF   rX   )rO   names
extensionsr   rV   s   `    r   find_programra   v   s     JE	w$-
  ,, 	H::::z:::hZGE  #D)) 	KKK	 r   c                 \    t           j        dk    r|                     d          rdd| gS | gS )aq  
    Return the list of tokens necessary to open the program
    at a given path.

    On macOS systems, this function prefixes .app paths with
    'open -a', which is necessary to run the application.

    On all other OS's, this function has no effect.

    :str path: The path of the program to run.
    :return: The list of tokens necessary to run the program.
    r'   r(   open-a)rD   rE   rF   rV   s    r   get_full_command_for_programrf      s6     |xDMM&$9$9d##6Mr   c                     |                      dt          j        dk               t          j        dk    rd}d}||z  }|                      d|           |                     d          d	D ]}|t	          t
          j        | d                                                   vr[t          j        	                                D ]<\  }}||                                k    r| d         
                    ||i            n=nH|                     d          3d
| d         vr)| d         
                    d
t                      i           | S )aR  
    Given a dict, populate kwargs to create a generally
    useful default setup for running subprocess processes
    on different platforms. For example, `close_fds` is
    set on posix and creation of a new console window is
    disabled on Windows.

    This function will alter the given kwargs and return
    the modified dict.
    	close_fdsr)   r   r   i   creationflagsenvN)
SYSTEMROOTSYSTEMDRIVEHOME)
setdefaultr   r   getmapstrupperkeysrK   itemsupdater   )kwargsCONSOLE_CREATION_FLAGSCREATE_NO_WINDOWenv_varkvs         r   #alter_subprocess_kwargs_by_platformr|      sJ    k27g#5666	w$!"%"22/+ABBB ::e(8 " "#ci1C1C1E1E"F"FFF "
 0 0 2 2 " "1"aggii//"5M00!Q888!E 0
 ::e(VE]**u$$flnn%=>>>Mr   c                    d|v r|d         st          d          d|d<   t          j        dk    sd|vrt          j        d          |d<   dD ]"}|                    |t
          j                   #t          di |}t          j        | fi |S )	aF  
    Execute the given shell command.

    Note that *args and **kwargs will be passed to the subprocess call.

    If 'shell' is given in subprocess_kwargs it must be True,
    otherwise ProgramError will be raised.
    .
    If 'executable' is not given in subprocess_kwargs, it will
    be set to the value of the SHELL environment variable.

    Note that stdin, stdout and stderr will be set by default
    to PIPE unless specified in subprocess_kwargs.

    :str cmdstr: The string run as a shell command.
    :subprocess_kwargs: These will be passed to subprocess.Popen.
    shellzBThe "shell" kwarg may be omitted, but if provided it must be True.Tr   
executableSHELLstdinstdoutstderrr   )	r   r   r   getenvrn   
subprocessPIPEr|   Popen)cmdstrsubprocess_kwargsstreams      r   run_shell_commandr      s    $ ###,=g,F# 7 8 8 	8 &*'"
 7d??000.0i.@.@l+/ > >$$VZ_====;  
 F88&7888r   c                 ,   d|v r|d         rt          d          t          |           }|st          d| z            t          |          |pg z   }dD ]"}|                    |t          j                   #t          di |}t	          j        |fi |S )a  
    Run program in a separate process.

    NOTE: returns the process object created by
    `subprocess.Popen()`. This can be used with
    `proc.communicate()` for example.

    If 'shell' appears in the kwargs, it must be False,
    otherwise ProgramError will be raised.

    If only the program name is given and not the full path,
    a lookup will be performed to find the program. If the
    lookup fails, ProgramError will be raised.

    Note that stdin, stdout and stderr will be set by default
    to PIPE unless specified in subprocess_kwargs.

    :str program: The name of the program to run.
    :list args: The program arguments.
    :subprocess_kwargs: These will be passed to subprocess.Popen.
    r~   zNThis function is only for non-shell programs, use run_shell_command() instead.zProgram %s was not foundr   r   )r   ra   rf   rn   r   r   r|   r   )programargsr   fullcmdr   s        r   run_programr      s    , ###(9'(B# > ? ? 	?7##G A5?@@@*733tzrBG/ > >$$VZ_====;  
 G99'8999r   c                 R   ddl m} 	  ||           }i }|                                |d<   |                                |d<   |                                |d<   |                                |d<   |                                |d<   | |d<   n# t          $ r d	d	d	d	d	| d
}Y nw xY w|S )z4Load data from desktop entry with xdg specification.r   )DesktopEntryr   	icon_pathexectypehiddenfpath )r   r   r   r   r   r   )xdg.DesktopEntryr   getNamegetIcongetExecgetType	getHidden	Exception)r   r   entry
entry_datas       r   parse_linux_desktop_entryr     s    ------
U##
"]]__
6"'--//
;"]]__
6"]]__
6$00
8#
7 
 
 

 




 s   BB B$#B$c                    ddl }t          j                            | d          x}}t          j                            |d          }i }t          j                            |          r'	 |                    |          }n# t          $ r Y nw xY w|                    d          }d}|r\t          j                            |d|          }|                    d          s|dz   }t          j                            |          sd}|S )z=Parse mac application bundle and return path for *.icns file.r   NContentsz
Info.plistCFBundleIconFile	Resourcesz.icns)	plistlibr   rV   r   rN   	readPlistr   ro   rF   )app_bundle_pathr   contents_path	info_pathpl	icon_filer   s          r   _get_mac_application_icon_pathr   '  s
   OOO "_j I IIMI]L99I	B	w~~i   	##I..BB 	 	 	D	 )**II GLLYGG	 !!'** 	,!G+Iw~~i(( 	Is   )A? ?
BBc                      t           j        dk    rt          j                    } n0ddl}|                    t          j                              d         } | S )z Return current session username.r   r   N)r   r   getloginpwdgetpwuidgetuid)r#   r   s     r   get_usernamer   D  sD    	w$;==


<<	,,Q/Or   c                 z   ddl }|                    d|          }g }	 |                    || d|j        |z            }|                    |          d         }t          |          D ]}	i }
	 |                    ||	          }|                    d          r|                    d          sl||
d<   |                    ||          }|D ]9}	 |	                    ||          d         }||
|<   %# t          $ r d|
|<   Y 6w xY w|                    |
           # t          $ r Y w xY wn# t          $ r Y nw xY w|S )z3
    See: https://stackoverflow.com/q/53132434
    r   N{}keyr   )winregConnectRegistryOpenKeyKEY_READQueryInfoKeyrangeEnumKey
startswithrF   QueryValueExEnvironmentErrorr   r   )key_pathhiveflagsubkeysr   regsoftware_listr   count_subkeyindexsoftwaresubkey_namesubkeypropertyvalues                  r   _get_win_reg_infor   O  s    MMM

 
 t
,
,CMnnS(Av/EFF**3//2<(( 	 	EH$nnS%88#..s33 
3'0055
3&1HUO#^^C==F$+ 4 44$*$7$7$I$I!$LE16HX../ 4 4 413HX...4!((222#   	"     s[   AD+ -AD!C/.D/D>D DDD+ 
D'$D+ &D''D+ +
D87D8c                     |                      dd                                          } | d         dk    r| d         dk    rt          |           } | S )z/Normalize windows path and remove extra quotes.\/r   ")replacelowerr   re   s    r   _clean_win_application_pathr   r  sL    <<c""((**DAw#~~$r(c//D!!Kr   c                     ddl } d| j        | j        f| j        | j        f| j        dfg}dgdi }fd|D             }t          j        | }t          |fd          D ]q}|d         rg|d                                         	                    dd	          }t          j                            |d                   }t          |          }|||<   rd
g ddi }fd|D             }t          j        | }t          |fd          D ]}|d         |d         }	|d         }
|d         }|	r`|
r]|
	                    dd	          }
|
                    d          d         }
d	k    r!|
rt          j                            |
          t          j                            |
          sd	}
rt          j                                      rÈfdt          j                  D             }|r|D ]}|                                }|                    d          }|rq|                    d          s\t          j                            |          }t          j                            |          }t          |          }|||	dz   |z   dz   <   t/          t1          |                                           d         }|                                D ]\  }	}||vr|||	<   |S )z1Return all system installed windows applications.r   Nz3SOFTWARE\Microsoft\Windows\CurrentVersion\App Pathsr   c                 L    g | ] }t          |d          |d                   !S r      r   r@   hfr   r   s     r   rB   z)_get_win_applications.<locals>.<listcomp>  0    NNNBxA1w??NNNr   c                     |          S Nr   xsort_keys    r   <lambda>z'_get_win_applications.<locals>.<lambda>      ( r   r   rZ   r   z3SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall)DisplayNameInstallLocationDisplayIconr   c                 L    g | ] }t          |d          |d                   !S r   r   r   s     r   rB   z)_get_win_applications.<locals>.<listcomp>  r   r   c                     |          S r   r   r   s    r   r   z'_get_win_applications.<locals>.<lambda>  r   r   r   r   r   ,c                     g | ]A}t           j                            t           j                            |                    ?|BS r   )r   rV   rN   r   )r@   flocations     r   rB   z)_get_win_applications.<locals>.<listcomp>  sR     G G GqGNN27<<!+D+DEEG G G Gr   )rZ   .comr[   uninsz ()r   )r   HKEY_LOCAL_MACHINEKEY_WOW64_32KEYKEY_WOW64_64KEYHKEY_CURRENT_USERrH   chainsorted
capitalizer   r   rV   
expandvarsr   rL   dirnamerN   r   listdirr   rF   r   r   listzipvaluesrt   )r   hfs	app_paths_appsr   r   r   expanded_fpathappsr   iconfilesfnamefn_low
valid_filer   r  r   r   r   r   s                    @@@@r   _get_win_applicationsr  {  sl   MMM IH 
	"F$:;		"F$:;		!1%C
 fGHINNNNN#NNNEOU+M=.C.C.C.CDDD , ,D> 	,5/,,..66vrBBCW//??N8HHN+IcN
 IH???GHDNNNNN#NNNEOU+M=.C.C.C.CDDD M M-.&&uo 	MD 	M<<R((D::c??1%D2~~$~7??4007>>$''  MBGMM(33 MG G G GBJx$8$8 G G G 	M!& M M!&%+__5M%N%N
% Mf.?.?.H.H M$&GLL5$A$AE-/W-?-?-F-FN-H ..0 .0N>LDu!4s!:;#t{{}}%&&r*F ((  eDJKr   c                     i } ddg}g }|D ]?}t          j         |          }|D ]&}t          |          }|                    |           '@t          |d           D ]'}|d         s|d         dk    r|d         | |d	         <   (| S )
z/Return all system installed linux applications.z/usr/share/**/*.desktopz~/.local/share/**/*.desktopc                     | d         S )Nr   r   )r   s    r   r   z)_get_linux_applications.<locals>.<lambda>  s
    QvY r   r   r   r   Applicationr   r   )globr   r   r   )r  desktop_app_pathsall_entries_datarV   fpathsr   r   s          r   _get_linux_applicationsr    s    
 D!% ! 0 04 	0 	0E2599J##J////	0 -3F3FGGG ; ;
(# 	;
6(:m(K(K'1'':DF#$Kr   c                  N   i } dd                     t                                g}g }|D ]}|t          j        |          z  }|D ]^}t          j                            |          r=t          j                            |                              d          d         }|| |<   _| S )z-Return all system installed osx applications.z	/**/*.appz/Users/{}/**/*.appr(   r   )formatr   r  r   rV   r   rO   rL   )r  app_foldersr  rV   r   r   s         r   _get_mac_applicationsr    s    D##LNN33K
 F " "$)D//!  7== 	7##E**0088;DDJKr   c                 \   ddl m} ddlm} t          j                            |           st          j                            |           r|                    d          }t          j
        dk    r<t          |           }|r*t          j                            |          r ||          }nt          j        dk    rnot          |           }|d         }|r@t          j                            |          r ||          }n+|                    |          }n|                    d          }|S )	z5Return application icon or default icon if not found.r   )QIcon)imano_matchr'   r   r   help)
qtpy.QtGuir  spyder.utils.icon_managerr  r   rV   rN   r   r  rD   rE   r   r   r   	fromTheme)r   r  r  r  r   r   s         r   get_application_iconr"    s%         ------	w~~e  e 4 4  xx
##<8##6u==I (RW^^I66 (uY''W__2599J";/I 67>>),, 6 5++DD ??955DxxKr   c                  <   i } t           j        dk    rt                      } n-t          j        dk    rt                      } nt                      } t           j        dk    rd |                                 D             } nd |                                 D             } | S )z
    Return all system installed applications.

    The return value is a list of tuples where the first item is the icon path
    and the second item is the program executable path.
    r'   r   c                 B    i | ]\  }}t          j        |          ||S r   )r   r   r@   r   vals      r   
<dictcomp>z.get_installed_applications.<locals>.<dictcomp>  s+    JJJZc339S>>JSJJJr   c                 B    i | ]\  }}t          j        |          ||S r   )r   rN   r%  s      r   r'  z.get_installed_applications.<locals>.<dictcomp>  s+    KKKZc33:c??KSKKKr   )rD   rE   r  r   r   r  r  rt   )r  s    r   get_installed_applicationsr)  
  s     D
|x$&&	D$&&&((
|xJJ4::<<JJJKK4::<<KKKKr   c                    i }t           j        dk    rd |D             }t          j        dk    r|                     d          rt           j                            |           st          d          dd| g|z   }	 t          j	        |          }n# t          $ r d}Y nw xY w||d	                    |          <   nt           j        dk    r|                     d
          rt           j                            |           st          d          | g|z   }	 t          j	        |          }n# t          $ r d}Y nw xY w||d	                    |          <   n/|                     d          rt           j                            |           st          d          t          |           }|d         } g }g }t          |          dk    r{|d         }d| v r|                     d|          }n/d| v r|                     d|          }nd| v r|                     d|          }nd| v r|                     d|          }n| }|}nt          |          dk    rd| v r*|                     dd	                    |                    }n-d| v r)|                     dd	                    |                    }d| v r/|D ]+}|                    |                     d|                     ,n7d| v r/|D ]+}|                    |                     d|                     ,n| }|}|r6|D ]2}	 t          j	        |gd          }n# t          $ r d}Y nw xY w|||<   3n3	 t          j	        |g|z   d          }n# t          $ r d}Y nw xY w|||<   |S )z
    Generalized method for opening files with a specific application.

    Returns a dictionary of the command used and the return code.
    A code equal to 0 means the application executed successfully.
    r   c                 :    g | ]}|                     d d          S )r   r   )r   )r@   r
  s     r   rB   z/open_files_with_application.<locals>.<listcomp>+  s&    ???u%--c**???r   r'   r(   z2`app_path`  must point to a valid OSX application!rc   rd   r    )rZ   r[   r   r\   z5`app_path`  must point to a valid Windows executable!z.desktopz3`app_path` must point to a valid Linux application!r   r   z%uz%fz%Uz%FT)r~   )r   r   rD   rE   rF   rV   r   
ValueErrorr   callr   r   rN   OSErrorr   lenr   r   )	app_pathfnamesreturn_codescmdreturn_coder   multiextrar
  s	            r   open_files_with_applicationr8  !  sX    L	w$?????
|x!!&)) 	-bgmmH.E.E 	- , - - -tX&/	$/#..KK 	 	 	KKK	&1SXXc]]##	D!!"BCC 	,GNN8,,	, + , , ,j6!	$/#..KK 	 	 	KKK	&1SXXc]]##!!*-- 	-"'..2J2J 	- , - - - *(33=v;;!1IEx&&tU33!!&&tU33!!&&tU33!!&&tU33[[1__x&&tSXXf-=-=>>!!&&tSXXf-=-=>>x# @ @ELL!1!1$!>!>????@!!# @ @ELL!1!1$!>!>????@  	, 0 0$",/3%t"D"D"DKK  $ $ $"#KKK$$/S!!0 (oseem4HHH        +LsH   ;B BBD+ +D:9D:"L::M	M	M/ /M>=M>c                 R   |J | ,t           j                            |          }|r|j        }nDd}nAt           j                            |           }|rt	          j        |j        |          dz   }nd}|r/t	          j        |          s|dz  }t	          j        |          r|S dS dS )z
    Return absolute path if Python script exists (otherwise, return None)
    package=None -> module is in sys.path (standard library modules)
    Nz.pyw)	importlibutil	find_specoriginr   r   rN   )packagemodulespecrV   s       r   python_script_existsrB  x  s    
 ~''// 	;DDDD~''00 	8DK0058DDD z$ 	CKD:d 	K	 	 	r   c                     |J t          |t          t          f          rt          |t          t          f          sJ t          | |          }t	          t
          j        ||gz   |z              dS )zv
    Run Python script in a separate process
    package=None -> module is in sys.path (standard library modules)
    N)
isinstancetupler   rB  r   rD   r   )r?  r@  r   p_argsrV   s        r   run_python_scriptrG    so    
 dUDM**Pz&5$-/P/PPPP00D$$ 677777r   c                 
   t          | t                    sJ d}g }t          j        ||           D ]Q}|                                r;|                    |                    d                              d                     R|S )ac  
    Split the string `text` using shell-like syntax

    This avoids breaking single/double-quoted strings (e.g. containing
    strings with spaces). This function is almost equivalent to the shlex.split
    function (see standard library `shlex`) except that it is supporting
    unicode strings (shlex does not support unicode until Python 2.7.3).
    z/(\s+|(?<!\\)".*?(?<!\\)"|(?<!\\)\'.*?(?<!\\)\')r   ')rD  rq   rerL   stripr   )textpatternouttokens       r   shell_splitrP    s     dC     @G
C'4(( 4 4;;== 	4JJu{{3''--c22333Jr   c                    g }|||                                 z  }|r|                    d           |r|                    ddg           | mt          j        dk    rH|rF|                    t          j        |                               t          j        d                     n|                    |            |r"|                    t          |                     |S )z&Construct Python interpreter argumentsNz-iz-mpdbr   r   )
rL   r   rJ   r   r   r   normpathr   seprP  )r
  python_argsinteractdebugend_argsrF  s         r   get_python_argsrY    s    F+##%%% d %tUm$$$7d??u? MM#,u--55bfcBBCCCCMM%    -k(++,,,Mr   c                    |t                      }i t          j        }|                    dd           |$t          j                            |          }||d<   d|  d} |sdn|}t          | ||||          }	t          j        dk    r||                    dd          }t          j
        |          d                             d          r=dd	lm}
 dd
lm} |
                    d |d           |d          |
j                   dS d| d}|d                    |	          dz   dz   z  }	 t%          |||           dS # t&          $ r? dd	lm}
 dd
lm} |
                    d |d           |d          |
j                   Y dS w xY wt(          j                            d          r|ddddddddddddg}|D ]e}t-          |d                   rN|d         |d         |g}|                    |	           t%          d                    |          ||            dS fdS t(          j        dk    r,t1          j        ddd t5                      d!"          |r(                    d#                    |                     t;          |          r)                    d$t          j        d%          d&           |                    d'| d&                               d                    |g|	z                                                         t          j        j        d(           fd)}tA          j!        |*          }|"                                 dS tF          )+zl
    Run Python script in an external system terminal.

    :str wdir: working directory, may be empty.
    N
PYTHONPATHr   r   r   r   r   z\\)QMessageBox)_RunzMExternal terminals does not support a UNC file path as the working directory.zstart cmd.exe /K ""z" r,  z
 ^&^& exit)cwdrj   z<It was not possible to run this file in an external terminallinuxzgnome-terminalz-x)r4  execute-optionkonsolez-ezxfce4-terminalxtermr4  ra  r'   wtrun_spyder_z.shF)prefixr!   dirdeletezcd "{}"
zexport PYTHONHOME=
PYTHONHOME
zexport PYTHONPATH=i  c                      t          dj                   } t          j        d           |                                  t          j        j                   d S )Nzopen -a Terminal.app    )r   r   timesleepwaitr   remove)procr   s    r   run_terminal_threadz:run_python_script_in_terminal.<locals>.run_terminal_thread  sM    $%EQV%E%EFFDJqMMMIIKKKIafr   )target)$r   r   rK   poprM   r   rY  r   r   r   
splitdriver   qtpy.QtWidgetsr\  spyder.config.baser]  criticalOkr   WindowsErrorrD   rE   rX   rJ   r   NamedTemporaryFiler%   writer  r	   closechmod	threadingThreadstartNotImplementedError)r
  wdirr   rV  rW  rU  r   pypathrj   rF  r\  r]  r4  programsr   rr  threadr   s                    @r   run_python_script_in_terminalr    s3    *,,

RZ.CGGL$(("L LLLE%44DUK5$GGF	w$<<T**D ~d##A&11&99 
666666000000$$AeHHA / 0 0N    3J222sxx#%44	ct555555 		 		 		222222,,,,,,  %        		 
	 	 	)	) #",EE%>>,EE#t<<>   	 	G#GEN33 u~w/?'@*M

6"""!#((3--TsCCCC		 	 
	!	!']/4,../46 6 6  	.GGK&&t,,---j)) 	GGGEL)AEEEFFFGG3333444	*.//000				
	 	 	 	 	 !)<===!!s   3E AFFc                 Z   t          | t                    rd                    d | D                       } 	 |dk    r t          |           t          |          k    S |dk    r t          |           t          |          k    S |dk    r t          |           t          |          k    S |dk    r t          |           t          |          k     S |dk    r t          |           t          |          k    S |dk    r t          |           t          |          k    S d	S # t          $ r Y d
S w xY w)a  
    Check version string of an active module against a required version.

    If dev/prerelease tags result in TypeError for string-number comparison,
    it is assumed that the dependency is satisfied.
    Users on dev branches are responsible for keeping their own packages up to
    date.

    Copyright (C) 2013  The IPython Development Team

    Distributed under the terms of the BSD License.
    .c                 ,    g | ]}t          |          S r   )rq   )r@   is     r   rB   z!check_version.<locals>.<listcomp>0  s    222a3q66222r   >>==<<=!=FT)rD  rE  r   r   	TypeError)actverversioncmp_ops      r   check_versionr  "  s"    &%   422622233S====5>>11t^^==E'NN22s]]==E'NN22s]]==5>>11t^^==E'NN22t^^==E'NN225   tts/   %D %D %D (%D %D 4%D 
D*)D*c           	          t          |           }t          |dt          |dd                    }|st          |           }|S )z<Return module version or None if version can't be retrieved.__version__VERSIONN)
__import__getattrget_package_version)module_namemodvers      r   get_module_versionr  E  sF    
[
!
!C
#}gc9d&C&C
D
DC /!+..Jr   c                 f    	 t          j        |           j        }|S # t           j        $ r Y dS w xY w)z=Return package version or None if version can't be retrieved.N)pkg_resourcesget_distributionr  DistributionNotFound)package_namer  s     r   r  r  N  sD    
,\::B
-   tts    00c                    |t          |          rt          d                              |           }	 t          |d|gi           }|                                \  }}|                                                                }n# t          $ r Y dS w xY wd|v rdS |dk    r|}nnd}nkdS 	 t          |           }n# t          $ r Y dS w xY w	 t          |           }	t          |	d	d          sdS n# t          $ r Y nw xY w|s|rt          |          }|dS d
|v r|                    d
          }
n|g}
d}|
D ]}t          j        d|          }|
J d            |d|                                         }|sd}|dvrt!          d| d          ||                                d         }|ot#          |||          }|S )a  
    Return True if module ``module_name`` is installed

    If ``version`` is not None, checks that the module's installed version is
    consistent with ``version``. The module must have an attribute named
    '__version__' or 'VERSION'.

    version may start with =, >=, > or < to specify the exact requirement ;
    multiple conditions may be separated by ';' (e.g. '>=0.13;<1.0')

    If ``interpreter`` is not None, checks if a module is installed with a
    given ``version`` in the ``interpreter``'s environment. Otherwise checks
    in Spyder's environment.

    ``distribution_name`` is the distribution name of a package. For instance,
    for pylsp_black that name is python_lsp_black.
    Na  
                try:
                    import {} as mod
                except Exception:
                    print('No Module')  # spyder: test-skip
                print(getattr(mod, '__version__', getattr(mod, 'VERSION', None)))  # spyder: test-skip
                -crj   Fz	No ModuleNoneT__file__r   z[0-9]zInvalid version numberr  )r  r  r  r  r  r  zInvalid version condition 'rI  )is_python_interpreterr   r  r   communicatedecoderK  r   r  r  r  r  rL   rJ  searchr  RuntimeErrorr  )r  r  interpreterdistribution_namer4  rq  r   r   module_versionr  versionsoutput_vermatchsymbr  s                   r   is_module_installedr  Z  sn   &  -- 	    VK(( ";sDDD!%!1!1!3!3..00   uu f$$u6!!!'!% 4	/<<NN 	 	 	55		[))C3
D11 u 	 	 	D	  	D"3 	D01BCCNt'>>}}S))HHyH 	I 	IDIh--E$$&>$$$'D <<<"#H#H#H#HIIIu{{}}~~&CHnc4 H HFFs6   AB 
BB-B= =
C
C C2 2
C?>C?c                 P    d}t          j        || t           j                  dS dS )z8Check that the python interpreter file has a valid name.z.*python(\d\.?\d*)?(w)?(.exe)?$flagsNFTrJ  r  IfilenamerM  s     r    is_python_interpreter_valid_namer    s*    0G	x...6utr   c                 ~   ddl m} t          j                            |           }t          j        |          rt          |          sdS t          j	        |          }t          |          r>t          j        dk    r|sdS dS t          j        dk    r ||          r|rdS |sdS dS dS |rdS t          |          S )z7Evaluate whether a file is a python interpreter or not.r   )is_conda_envFr   Tr'   )pyexec)spyder.utils.condar  r   rV   realpathr   rN   r  r
   is_text_file
is_pythonwr   rD   rE   check_python_help)r  r  real_filenamer  s       r   r  r    s     0/////G$$X..MJ}%% 0??u (77L-   07d?? tu\X%% |=111 l t! tu 5	 0u ///r   c                 P    d}t          j        || t           j                  dS dS )z0Check that the python interpreter has 'pythonw'.z.*python(\d\.?\d*)?w(.exe)?$r  NFTr  r  s     r   r  r    s*    -G	x...6utr   c                     	 t          | ddgi           }|                                \  }t                    g d}t          fd|D                       rdS dS # t          $ r Y dS w xY w)zBCheck that the python interpreter can compile and provide the zen.r  zimport thisr  )zBeautiful is better than ugly.z!Explicit is better than implicit.zSimple is better than complex.z#Complex is better than complicated.c              3       K   | ]}|v V  	d S r   r   )r@   liner   s     r   	<genexpr>z$check_python_help.<locals>.<genexpr>  s'      66$tv~666666r   TF)r   r  rq   allr   )r  rq  r]  valid_linesr   s       @r   r  r    s    8dM%:CCC$$&&	V
 
 
 6666+66666 	45   uus   AA   
A.-A.c                    	 t          j        t          |                     }t          g d          }t	                      r|                    d           t          d |                                dd         D                       }||z  g}t          |          S # t           j        t           j	        f$ r Y dS w xY w)aT  
    Test whether given PID belongs to a Spyder process.

    This is checked by testing the first three command line arguments. This
    function returns a bool. If there is no process with this PID or its
    command line cannot be accessed (perhaps because the process is owned by
    another user), then the function returns False.
    )r   spyder3z
spyder.exezspyder3.exezbootstrap.pyzspyder-script.pyzSpyder.launch.pywzruntests.pyc              3   T   K   | ]#}t           j                            |          V  $d S r   )r   rV   rO   )r@   args     r   r  z$is_spyder_process.<locals>.<genexpr>  s2      II#((--IIIIIIr   Nrl  F)
psutilProcessintsetr   addcmdlineanyNoSuchProcessAccessDenied)pidrA   r_   	arguments
conditionss        r   is_spyder_processr    s    N3s88$$  N N N O O!! 	%IIm$$$ IIRaRIIIII	i'(
: &"56   uus   BB B>=B>c                    	 t          | dg                                          \  }}|                                                                }t	          j        d|          sd}n# t          $ r d}Y nw xY w|                                S )z>Return version information of the selected Python interpreter.z-Vz^Python \d+\.\d+\.\d+$r   )r   r  r  rK  rJ  r  r   )rV   rN  __s      r   get_interpreter_infor     s    	dTF++7799Rjjll  "" y2C88 	C   99;;s   A#A& &A54A5c                      t           j        dk    rJt          j        t	          j        t          d          d          } | j        dk    rdS t          d          S t          d          S )z"Find git executable in the system.r'   zcheck-git.shT)capture_outputr   Ngit)	rD   rE   r   runr   r   HERE
returncodera   )rq  s    r   find_gitr  /  sg    
|x~HT>**4A A A?a4E"""E"""r   r   )NN)NNN)H__doc__astr   getpassr   textwrapr   r  r;  rH   r   os.pathrV   r   rJ  r   rD   r   r  rm  packaging.versionr   r  r  rw  r   r   r	   spyder.utilsr
   spyder.utils.miscr   rW   r   r  r  r   r   r%   rX   ra   rf   r|   r   r   r   r   r   r   r   r  r  r  r"  r)  r8  rB  rG  rP  rY  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   <module>r     s   " !                            				       				     



       $ # # # # #     4 4 4 4 4 4 4 4 4 4 ! ! ! ! ! ! 3 3 3 3 3 3s{;3;x(())	 	 	 	 	9 	 	 	   8, , ,^  &  $$ $ $N#9 #9 #9L": ": ": ":J  4  :       F  E E EP  0  (  6  .T T Tn   2 #4b 8 8 8 8  $  . HL[" [" [" ["|     F  	 	 	 @D*.[ [ [ [|  %0 %0 %0P    (  4  	# 	# 	# 	# 	#r   