
    N                         S 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SKJ
r
  SS	KJr  SS
KJr  \R                   " S S\R                  5      5       rg)z)Command to create virtualenv environment.    N)base)
exceptions)util)config)execution_utils)log)
properties)filesc                   4    \ rS rSrSr\S 5       rS rS rSr	g)Create   a\  Create a virtualenv environment.

Create a virtual env context for gcloud to run in. Installs several
python modules into the virtual environment. The virtual env environment
can be inspected via the `{parent_command} describe` command. Note this
command does not enable the virtualenv environment, you must run
`{parent_command} enable` to do so.
c                 h    U R                  SSS9  U R                  SSSS9  U R                  SSS	S9  g
)zAdds args for this command.z--python-to-usez5Absolute path to python to use to create virtual env.)helpz--enable-virtualenv
store_truez(Enable gcloud virtualenv after creation.)actionr   z--force-createz6Force creating gcloud virtualenv if it already exists.N)add_argument)parsers    'lib/surface/config/virtualenv/create.pyArgsCreate.Args)   s[     D  F 7  9 E  G    c                 
   [         R                  R                  U5      (       d^  [        R                  " SU S35        [
        R                  " 5       (       a  [        R                  " S5        [        R                  " SS9eU$ )NzProvided python path `z2` does not exist. Stop creating gcloud virtualenv.zUYou may need Santa exception to install python. See go/gcloud-python-santa-exception.   	exit_code)	ospathexistsr   errorr	   IsInternalUserCheckr   ExitCodeNoError)selfpythons     r   _GetAndValidatePythonToUse!Create._GetAndValidatePythonToUse8   sl    77>>&!!	ii"6( +- - 
	'	'	)	)		4	
 &&33Mr   c                    [         R                  " 5       (       a@  UR                  S5      (       d*  [        R                  " S5        [
        R                  " SS9e[         R                  " 5       (       a*  [        R                  " S5        [
        R                  " SS9eUR                  S5      (       a  U R                  UR                  5      nO [        R                  " 5       n[        R                  " 5       R                  n[         R                   " U5      (       a  [        R                  " S	R#                  U5      5        UR$                  (       d  [
        R                  " SS9e[        R&                  R)                  S
5        [*        R,                  " U5        Sn [        R&                  R)                  S5        [        R.                  " USSU/S[        R0                  R2                  [        R0                  R2                  S9nUS:w  aI  [        R.                  " SSSX#/SS9nUS:w  a*  [        R                  " S5        [
        R                  " US9e[        R&                  R)                  S5        SR#                  U5      SSSR#                  U5      S/nUR5                  [         R6                  5        [        R.                  " USS9nUS:X  a  SnOp[        R                  " S5        [8        R:                  " 5       (       a  [        R                  " S5        [        R                  " S5        [
        R                  " US9eUR<                  (       a5  [        R&                  R)                  S5        [         R>                  " U5        U(       d3  [         R                   " U5      (       a  [*        R,                  " U5        g g g ! [         a+    [        R                  " S5        [
        R                  " SS9ef = f! U(       d3  [         R                   " U5      (       a  [*        R,                  " U5        f f f = f) Npython_to_usez&Virtual env support requires Python 3.   r   z+Virtual env support not enabled on Windows.   z0Failed to resolve python to use for virtual env.r   z$Virtual env setup {} already exists.zRemoving existing virtualenv...FzCreating virtualenv...z-mvenvT)no_exiterr_funcout_funcr   
virtualenvz-qz-p)r+   zVirtual env setup failed.zInstalling modules...z{}/bin/pip3installz--logz{}/install_module.logz--disable-pip-version-checkzKYou might need further authentication. See more at go/gcloud-internal-auth.zCertain gcloud commands require extension binary modules. To install the modules manually, run: 
  $ gcloud config virtualenv create --enable-virtualenvzEnabling virtualenv...) r   IsPy2IsSpecifiedr   r   r   r!   	IsWindowsr$   r'   r   GetPythonExecutable
ValueErrorr   Pathsvirtualenv_dirVirtualEnvExistsformatforce_createstatusPrintr
   RmTreeExecfile_only_loggerdebugextendMODULESr	   r    enable_virtualenvEnableVirtualEnv)r"   argsr#   ve_dirsucceeded_making_venvecinstall_moduless          r   Run
Create.RunF   s8   zz||D,,_==	ii89&&33~~	ii=>&&33((..t/A/ABf6 446 \\^**FV$$	ii6==fEF((155

:;V!2	jj/0 vv >(,),)=)=)C)C),)=)=)C)CEb 
q
 !!<tV"L*.07
))/
0**R8
8	jj./


v
&	7
!
(
(
0
'o
 T\\*>b	q $		-.))++
)))
 			F	

 ((266			

12f% #  ((
,,v
 ) #{  6		DE((1556z #  ((
,,v
 ) #s   O #G0P 5P<Q N)
__name__
__module____qualname____firstlineno____doc__staticmethodr   r$   rI   __static_attributes__rK   r   r   r   r      s(     G GKr   r   )rP   r   googlecloudsdk.callioper   r   ,googlecloudsdk.command_lib.config.virtualenvr   googlecloudsdk.corer   r   r   r	   googlecloudsdk.core.utilr
   HiddenCommandr   rK   r   r   <module>rY      sM    0 
 ( . = & / # * * rT\\ r rr   