
    Vh                       d 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
ZddlmZ ddlmZmZmZmZmZmZmZmZ ddlmZmZ ddlmZmZ dd	lmZmZ 	 	 	 	 	 	 dd
Z 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZ!ddZ"ddZ#	 	 	 	 	 	 	 	 	 	 	 	 ddZ$y)zVirtual environment management.    )annotationsN   )EnvironmentConfig)find_pythonSubprocessErrorANSIBLE_TEST_TARGET_TOOLS_ROOTdisplayremove_treeApplicationErrorstr_to_versionraw_command)run_command
ResultType)VirtualPythonConfigPythonConfig)collect_bootstraprun_pipc                   |j                   rd}nd}t        j                  j                  t        j
                  j                  dd|j                   |       }t        j                  j                  |d      }t        |j                  t        j                  j                  |dd      |j                         }t        j                  j                  |      r(t        j                  d|j                  d	|d
       nUt        |       t        | |||j                         st        d|j                   d      t        |      }t        | ||d       t!        j"                  |      j%                          |S )zRCreate a virtual environment for the given Python and return the path to its root.z-ssp 
delegationpythonz
marker.txtbin)versionpathsystem_site_packageszUsing existing Python z virtual environment: r   	verbosityzPython z. does not provide virtual environment support.N)r   osr   joinr   TMPr   r   existsr	   infor
   create_virtual_environmentr   r   r   pathlibPathtouch)argsr   suffixvirtual_environment_pathvirtual_environment_markervirtual_environment_pythoncommandss          K/home/dcms/DCMS/lib/python3.12/site-packages/ansible_test/_internal/venv.pyget_virtual_pythonr.   *   s:   
 ""!ww||JNN,?,?QWX^XfXfWghngoOpq!#.F!U!4WW\\2E8D#88" 
ww~~016>>[st  AB  	C 	,-)$8PRXRmRmn"WV^^,<<j#kll$%?@0(DA LL+,224%%    c                    t         j                  j                  |j                        syt        |j                        D ]:  }t        | ||||      st        j                  d|j                  d|d        y y)zICreate a virtual environment using venv for the requested Python version.FzCreated Python z# virtual environment using "venv": r   r   T)r   r   r!   iterate_real_pythonsr   run_venvr	   r"   )r'   r   r   r   pipreal_pythons         r-   r#   r#   P   sj     77>>&++&
 ,FNN; D+';S$GLLU[UcUceijvwx r/   c              #    K   t        |       }d}|t        j                  dt        |       k(  rMt        j                  }t        |      }|r*t        | t        j                  j                  |d            }|r| t        j                  j                  dt        j                  j                        }|syt        | |      }|sy||k(  ryt        |      }|r*t        | t        j                  j                  |d            }|r| yyw)z
    Iterate through available real python interpreters of the requested version.
    The current interpreter will be checked and then the path will be searched.
    Nr   PATH)r   sysversion_infolen
executableget_python_real_prefixr   r   r   r   environgetdefpath)r   r8   current_pythonreal_prefixr   found_pythons         r-   r1   r1   i   s     
 "'*LNs''(:\):;;,^<("'',,{E2RSN  ::>>&"''//2Dw-L~%(6K"7BGGLLe,LM s   D	Dc                    | t         j                  j                  t         j                  j                  t        d            g}t	        j
                  t        |d      d         }|d   }|S )z
    Return the real prefix of the specified interpreter or None if the interpreter is not a virtual environment created by 'virtualenv'.
    zvirtualenvcheck.pyTcapturer   r@   )r   r   r   r   jsonloadsr   )python_pathcmdcheck_resultr@   s       r-   r;   r;      sV     RWW\\2PRf%gh
iC::k#t<Q?@L}-Kr/   c                8   |ddg}|r|j                  d       |s|j                  d       |j                  |       	 t        | |d       y# t        $ rC}t        |       | j                  dkD  rt        j                  |j                         Y d}~y	d}~ww xY w)
z5Create a virtual environment using the 'venv' module.z-mvenvz--system-site-packagesz--without-pipTrC   r   NF)appendr   r   r
   r   r	   errormessage)r'   
run_pythonr   r3   r   rH   exs          r-   r2   r2      s     tV
$C

+,

?#JJtD#t,   D>>AMM"**%s   A 	B9BB)r'   r   r   r   returnr   )FF)r'   r   r   r   r   strr   boolr3   rS   rQ   rS   )r   rR   rQ   zc.Iterable[str])rG   rR   rQ   zt.Optional[str])r'   r   rO   rR   r   rS   r3   rS   r   rR   rQ   rS   )%__doc__
__future__r   collections.abcabccrE   r   r$   r7   typingtconfigr   utilr   r   r   r	   r
   r   r   r   util_commonr   r   host_configsr   r   python_requirementsr   r   r.   r#   r1   r;   r2    r/   r-   <module>ra      s    % "   	  
 	 	 	

#&
#&#& #&T "'
  	
 
 
2%P
  
	
  
r/   