
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	l
mZ dd
l
mZ ddlmZ ej                    G d dej"                               Zy)z)Command to create virtualenv environment.    )absolute_import)division)unicode_literals)base)
exceptions)util)config)execution_utils)log)filesc                   &    e Zd ZdZed        Zd Zy)Createah  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                 *    | j                  dd       y)zAdds args for this command.z--python-to-usez5Absolute path to python to use to create virtual env.)helpN)add_argument)parsers    'lib/surface/config/virtualenv/create.pyArgszCreate.Args)   s     D  F    c                 r   t        j                         r<|j                  d      s+t        j                  d       t        j                  d      t        j                         r+t        j                  d       t        j                  d      |j                  d      r|j                  }n	 t        j                         }t        j                         j                  }t        j                  |      r:t        j                  d	j!                  |             t        j                  d      d
}	 t        j"                  j%                  d       t        j&                  |dd|gdt        j(                  j*                  t        j(                  j*                        }|dk7  rLt        j&                  ddd||gd      }|dk7  r+t        j                  d       t        j                  |      t        j"                  j%                  d       dj!                  |      dddj!                  |      ddg}|j-                  t         j.                         t        j&                  |d      }|dk(  rd}n+t        j                  d       t        j                  |      	 |s,t        j                  |      rt1        j2                  |       y y y # t        $ r, t        j                  d       t        j                  d      w xY w# |s,t        j                  |      rt1        j2                  |       w w w xY w)Npython_to_usez&Virtual env support requires Python 3.   )	exit_codez+Virtual env support not enabled on Windows.   z0Failed to resolve python to use for virtual env.   z$Virtual env setup {} already exists.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-check)r   IsPy2IsSpecifiedr   errorr   ExitCodeNoError	IsWindowsr   r
   GetPythonExecutable
ValueErrorr	   Pathsvirtualenv_dirVirtualEnvExistsformatstatusPrintExecfile_only_loggerdebugextendMODULESr   RmTree)selfargspythonve_dirsucceeded_making_venvecinstall_moduless          r   Runz
Create.Run0   s   zz|D,,_=	ii89&&33~~	ii=>&&33(!!f6 446
 \\^**FV$	ii6==fEF&&33!$	jj/0 vv >(,),)=)=)C)C),)=)=)C)CEb 
q
 !!<tVV"L*.07
))/
0**R8
8	jj./


v
&	7
!
(
(
0$
'o
 T\\*>b	q $		-.((266 	 #  (
,,v
 ) #Y  6		DE((1556X #  (
,,v
 ) #s   /K 3E+L 5L0L6N)__name__
__module____qualname____doc__staticmethodr   r<    r   r   r   r      s"     F F:r   r   N)r@   
__future__r   r   r   googlecloudsdk.callioper   r   ,googlecloudsdk.command_lib.config.virtualenvr   googlecloudsdk.corer	   r
   r   googlecloudsdk.core.utilr   HiddenCommandr   rB   r   r   <module>rJ      sN    0 &  ' ( . = & / # * KT\\ K Kr   