
    N                         S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SrS	rS
rSrS\ S3rS\-   rS rS rS rS rS rS rS rS rS rS rS rS rS\4S jrS rg)zPython installers for gcloud.    N)config)execution_utils)
console_io)files)	platformsz3.13)      zpython-3.13.7-macos11.tar.gzz/opt/homebrew/binz./Library/Frameworks/Python.framework/Versions//z1https://dl.google.com/dl/cloudsdk/channels/rapid/c                      [         R                  " 5       R                  n [        R                  R                  U 5      (       a  U $ g )N)r   Pathsvirtualenv_dirospathisdir)env_dirs    1lib/googlecloudsdk/core/updater/python_manager.py_VirtualEnvPathr   (   s.    LLN))'WW]]7N    c                 0    U R                  SSSSU/5        g )Nr   
virtualenvcreatez--python-to-useExecute)clipython_to_uses     r   _CreateVirtualEnvr   0   s    ++xx1B r   c                 ^    [        SU S35        U R                  / SQ5        [        X5        g )NzVirtual env already exists at z$. Deleting so we can create new one.)r   r   delete)printr   r   )r   r   existing_env_dirs      r   _RecreateVirtualEnvr!   5   s2    
()9(: ;- 	- .++01C'r   c                 *    U R                  / SQ5        g )N)r   r   updater   r   s    r   _UpdateVirtualEnvr%   <       ++01r   c                 *    U R                  / SQ5        g )N)r   r   enabler   r$   s    r   _EnableVirtualEnvr)   @   r&   r   c                 .    SSK Jn  UR                  / 5      n[        5       nU(       a(  [        R
                  SS [        :w  a  [        X U5        OU(       a  [        U5        O[        X 5        [        U5        g! [         a    [        S5         gf = f)zEEnables virtual environment with new python version and dependencies.r   )gcloud_mainN   z$Failed to enable virtual environment)googlecloudsdkr+   	CreateCLIr   sysversion_infoPYTHON_VERSION_INFOr!   r%   r   r)   ImportErrorr   )r   r+   r   r   s       r   UpdatePythonDependenciesr3   D   sy    2*



#C G3##BQ'+>>#g6	+c	 2	
012s   A9A< <BBc                      [         R                  R                  [        5      =(       a    S[        R
                  " 5       ;   $ )Nhomebrew)r   r   r   HOMEBREW_BINr   
GcloudPath r   r   _IsHomebrewInstalledr9   X   s(    	|	$	Jv7H7H7J)JJr   c                     S[          SU  S3$ )Nz(Recommended) Python z installation detected in z!, install required modules (Y/n)?)PYTHON_VERSION)python_install_paths    r   _PromptPythonUpdater=   \   s"    n--G	>@Ar   c                  H    [        5       (       a
  S[         S3$ S[         S3$ )NzHomebrew install Python ?zDownload and run Python z installer?)r9   r;   r8   r   r   _PromptPythonInstallr@   b   s+    %n%5Q77%n%5[AAr   c                      [          S[         3n [        SU  S35        [        R                  " U R                  S5      SS9nUS:w  a  SU  S	[         S
3$ g)zHMake sure python version is correct for user using gcloud with homebrew.z/brew install python@z	Running "z". Tno_exitr   "z%" failed. Please brew install python@z
 manually.N)r6   r;   r   r   Execsplit)brew_install	exit_codes     r   _BrewInstallPythonrJ   i   sl     >!6~6FG,)L>$%""<#5#5c#:DI)!^
L>  !	-. 
r   c                  2   [        S[         S35        [        5         [        R                  " 5        n [        R
                  " U 5         SSS[        /n[        R                  " USS9nUS:w  a   S	S	S	5        S	S	S	5        g
[        R                  " SS[        /SS9nUS:w  a   S	S	S	5        S	S	S	5        g[        R                  " / SQSS9nUS:w  a   S	S	S	5        S	S	S	5        g S	S	S	5        S	S	S	5        g	! , (       d  f       N= f! , (       d  f       g	= f)*Optionally install Python on Mac machines.zRunning Python z4 installer, you may be prompted for sudo password...curlz--silentz-OTrC   r   Nz#Failed to download Python installertarz-xfz"Failed to extract Python installer)sudo	installerz-targetr
   z-pkgz./python-3.13.7-macos11.pkgzInstaller failed.)
r   r;   %PromptAndInstallXcodeCommandLineToolsr   TemporaryDirectoryChDirMACOS_PYTHON_URLr   rF   MACOS_PYTHON)tempdir	curl_argsrI   s      r   _MacInstallPythonrX   v   s    /.) * 	  ()!W	W	:t-=>i!&&y$?i	a4	 
 "! "&&%
&6i	a3 
 "! "&& ( i 
a"! 
 "!  
 
 "& 
% 
	 "!& 
sA   D
'C71D#C7%D6C7D&D7
D	D
Dc                  j   [         R                  R                  5       [         R                  R                  :w  a  g[	        S[
         S35        [        5       n U (       a  [         S[
         3nO	[         S3n[        R                  R                  U5      nU(       a  [        U5      nO
[        5       n[        R                  " USS9(       d  gU(       d  U (       a
  [!        5       O	[#        5       nOSnU(       d*  U[        R$                  S'   [	        S	5        ['        U5        g[	        S
U 35        g)rL   Nz)
Google Cloud CLI works best with Python z and certain modules.
z/pythonzbin/python3Tprompt_stringdefaultCLOUDSDK_PYTHONzSetting up virtual environmentz!Failed to install Python. Error: )r   OperatingSystemCurrentMACOSXr   r;   r9   r6   MACOS_PYTHON_INSTALL_PATHr   r   isfiler=   r@   r   PromptContinuerJ   rX   environr3   )homebrew_installedr   already_installedpromptinstall_errorss        r   PromptAndInstallPythonOnMacri      s   &&(I,E,E,L,LL
2>2B C  
 ,-#nGN+;<M01=Mggnn]3  /F!#F		"	"	F
 
+ )*1B1D  N 
$1BJJ !	
*+]+	-n-=
>?r   returnc                  :    [         R                  " SS/SS9n U S:H  $ )z0Checks if Xcode Command Line Tools is installed.xcode-selectz-pTrC   r   )r   rF   )rI   s    r   #CheckXcodeCommandLineToolsInstalledrm      s#    ""ND#94H)	ar   c                  p   [         R                  R                  5       [         R                  R                  :w  a  g[	        5       (       a  [        S5        gSn [        R                  " U SS9nU(       aB  [        S5        SS/n[        R                  " USS	9nUS
:w  a  [        S5        g[        S5        gg)z<Optionally install Xcode Command Line Tools on Mac machines.Nz.Xcode Command Line Tools is already installed.zRXcode Command Line Tools is required to install Python. Continue to install (Y/n)?TrZ   z&Installing Xcode Command Line Tools...rl   z	--installrC   r   z}Failed to install Xcode Command Line Tools. Please run `xcode-select --install` manually to install Xcode Command Line Tools.z&Xcode Command Line Tools is installed.)
r   r^   r_   r`   rm   r   r   rc   r   rF   )rg   setup_xcodexcode_commandrI   s       r   rQ   rQ      s    &&(I,E,E,L,LL
(**	
:;
 	 ))M+	
23#[1M$$]DAIA~ ( ) 45 r   ) __doc__r   r/   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   googlecloudsdk.core.utilr   r   r;   r1   rU   r6   ra   rT   r   r   r!   r%   r)   r3   r9   r=   r@   rJ   rX   ri   boolrm   rQ   r8   r   r   <module>rv      s     $ 	 
 & / 2 * .  -"4^4DAF  8,F 

(222(KAB
>'@TT 6r   