
    Vh5                    ,   d Z ddlmZ ddlZdZ ej
                  ej                        Zeed   fZeek  r ej                  ej                  e       e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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Z ed      Zdaej:                  Zd Zd	 Z d
 Z! G d d      Z"d Z#d Z$d Z%d Z&d Z'd Z(d Z) G d de*      Z+ G d de+      Z,d$dZ-d%dZ.d&dZ/d Z0d Z1d'dZ2d(dZ3d(dZ4d(d Z5d(d!Z6d"Z7e8d#k(  r e        yy))zJA tool for installing test requirements on the controller and target host.    )annotationsNi      zutf-8 c                    t        j                  t        t        j                  t
                          } | d   a| d   }| d   }t        j                  dd      5 }|j                  t        |             |j                          |D ]$  \  }}	  t               |   |j                  |       & 	 ddd       y# t        $ r*}t        |       t!        j"                  d       Y d}~_d}~ww xY w# 1 sw Y   yxY w)	zMain program entry point.	verbosityscriptcommandsansible-test-z-pip.pyprefixsuffixr   N)jsonloadsto_textbase64	b64decodePAYLOAD	VERBOSITYtempfileNamedTemporaryFilewriteto_bytesflushglobalsnameApplicationErrorprintsysexit)payloadr   r	   pipr   optionsexs          \/home/dcms/DCMS/lib/python3.12/site-packages/ansible_test/_util/target/setup/requirements.pymainr%   )   s     jj!1!1'!:;<G$IXFz"H		$	$OI	N 	RU		(6"#		% 	MD'	$'2			 	 $ b		 	s6   3C0B:.C0:	C- C(#C0(C--C00C9c                @   |d   }|d   }|d   }|d   }d|z  }t         j                  j                  d|j                  dd      z        }|d	z   }t         j                  j	                  |      rt        d
|d|       nmt        d|d|       t        t         j                  j                  |             	 t        ||       t        j                  ||       t        d|d|       t               }
|
j                  |       t!               }|j#                  |       |s|j%                  d       |s|j%                  d       t&        j(                  | g|z   }t+        ||
       y# t        $ r%}	t        d|	d|dj                               d}	~	ww xY w)zCBootstrap pip and related packages in an empty virtual environment.pip_versionpackages
setuptoolswheelz?https://ci-files.testing.ansible.com/ansible-test/get-pip-%s.pyz#~/.ansible/test/cache/get_pip_%s.py._z	.downloadzUsing cached pip z bootstrap script: zDownloading pip z
Download failed: z@

The bootstrap script can be manually downloaded and saved to: z

If you're behind a proxy, consider commenting on the following GitHub issue:

https://github.com/ansible/ansible/issues/77304
NzCached pip )GET_PIPz--no-setuptoolsz
--no-wheelenv)ospath
expanduserreplaceexistslog	make_dirsdirnamedownload_file	Exceptionr   stripshutilmovecommon_pip_environmentupdatecommon_pip_optionsextendappendr   
executableexecute_command)r!   r"   r'   r(   r)   r*   url
cache_path	temp_pathr#   r/   commands               r$   	bootstraprH   A   sl   -(Kz"H&JGE
Kk
YC##$IKL_L_`cehLi$ijJ[(I	ww~~j!+zRScJK"''//*-.	!#y) 	Iz*KLM
 
"CJJzJ" "GNN8()|$~~s#g-GG%;  		!" 
:% ! !		!s   <E/ /	F8 FFc                   |d   }|d   }|d   }t        j                  dd      }	 t               }|j                  |       |D ]  \  }}|j	                  t
        j                        d   dv r!t        |      D ]  }|j                  |         t        t
        j                  j                  ||      |d	       |j                  d
|g        |D ]C  \  }}t        t
        j                  j                  ||      |d	       |j                  d|g       E t        j                  | dg|z   }	t               }
t        |	|
|       t!        |       y# t!        |       w xY w)zPerform a pip install.requirementsconstraintsr(   r
   z-requirementsr   r   )testrJ   Tz-rz-cinstallr/   cwdN)r   mkdtempr?   r@   splitr0   sepparse_pre_build_instructionsexecutewrite_text_filer1   joinr   rB   r=   rC   remove_tree)r!   r"   rJ   rK   r(   tempdirr1   content	pre_buildrG   r/   s              r$   rM   rM   u   sF   >*L-(Kz"HooNG$&x ) 
	)MD'zz"&&!!$(@@
 ">g!F +I%%c*+ BGGLL$7$GNND$<(
	) ) 	)MD'BGGLL$7$GNND$<(	) >>3	2W<$&Sg6GGs   DE Ec                      e Zd ZdZd Zd Zy)PreBuildzParsed pre-build instructions.c                     || _         g | _        y )N)requirementrK   )selfr^   s     r$   __init__zPreBuild.__init__   s    &    c                   t        j                  dd      }	 t               }|j                  | j                         dj                  | j                        dz   }t        j                  j                  |d      }t        ||d       t               }|j                  |       t        j                  |dg|z   }t        |||	       t        |       y
# t        |       w xY w)z%Execute these pre-build instructions.r
   z
-pre-buildr   
zconstraints.txtT)PIP_CONSTRAINTr*   rN   N)r   rP   r?   rA   r^   rV   rK   r0   r1   rU   r=   r>   r   rB   rC   rW   )r_   r!   rX   r"   rK   constraints_pathr/   rG   s           r$   rT   zPreBuild.execute   s    ""/,O	!(*GNN4++,))D$4$45<K!ww||G5FG,k4@(*CJJ&6J7~~sG4w>GG': K s   B0C C"N)__name__
__module____qualname____doc__r`   rT    ra   r$   r\   r\      s    (!ra   r\   c           	        d}|dz   }|dz   }| j                         }|D cg c]  }|j                  |      s| }}g }|D ]  }|j                  |      r'|j                  t        |t	        |      d              ;|j                  |      r+|d   j
                  j                  |t	        |      d        wt        d|z          |S c c}w )zWParse the given pip requirements and return a list of extracted pre-build instructions.z# pre-build zrequirement: zconstraint: NzUnsupported pre-build comment: )
splitlines
startswithrA   r\   lenrK   RuntimeError)rJ   pre_build_prefixpre_build_requirement_prefixpre_build_constraint_prefixlineslinepre_build_linesinstructionss           r$   rS   rS      s    
 &#3o#E "2^"C##%E(-SAQ1RtSOSL I??78c2N.O.P)Q RS__89((//S9T5U5V0WX@4GHHI  Ts
   C
C
c                    |d   }|d   }t               }|j                  |       t        j                  | ddg|z   }t	               }	 t        ||d       y# t        $ r |s Y yw xY w)zPerform a pip uninstall.r(   ignore_errors	uninstallz-yTr/   captureN)r?   r@   r   rB   r=   rC   SubprocessError)r!   r"   r(   ry   rG   r/   s         r$   rz   rz      st    z"HO,M "GNN8~~sK6@G
 
"CS$7  s   A A&%A&c                v    ~t               }t        j                  | dg|z   }t               }t	        ||d       y)zReport the pip version.z-VTr{   N)r?   r   rB   r=   rC   )r!   r"   rG   r/   s       r$   versionr      s6     "G~~sD)G3G
 
"CGd3ra   c                 f    t         j                  j                         } | j                  d       | S )z4Return common environment variables used to run pip.1)PIP_BREAK_SYSTEM_PACKAGES)r0   environcopyr>   r.   s    r$   r=   r=      s'    
**//
C JJJ-Jra   c                     dgS )z$Return a list of common pip options.z--disable-pip-version-checkrj   rj   ra   r$   r?   r?     s     	& ra   c                     	 t         j                  S # t        $ r5 t        t        j                   d      t         _        Y t         j                  S w xY w)z-Return a file object that references devnull.zw+b)devnullfileAttributeErroropenr0   rj   ra   r$   r   r     s<    /|| /BJJ.<</s    ,AAc                   t        t        |      d      5 }t        j                  t        j
                  j                  |             5 }t        j                  ||       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)z2Download the given URL to the specified file path.wbN)	r   r   
contextlibclosingurllibrequesturlopenr;   copyfileobj)rD   r1   
saved_filedownloads       r$   r8   r8     sp    	htnd	# 5z 6 6s ;< 	5x4	55 5	5 	55 5s#   3A=	A1 A=1A:	6A==Bc                      e Zd ZdZy)r   z&Base class for application exceptions.N)rf   rg   rh   ri   rj   ra   r$   r   r     s    0ra   r   c                  "     e Zd ZdZ fdZ xZS )r}   z%A command returned a non-zero status.c                    d|t        j                  |      fz  }|r|d|j                         z  z  }|r|d|j                         z  z  }t        t        |   |       y )Nz#A command failed with status %d: %sz
>>> Standard Error
%sz
>>> Standard Output
%s)shlexrV   r:   superr}   r`   )r_   cmdstatusstdoutstderrmessage	__class__s         r$   r`   zSubprocessError.__init__  s[    765::c?:SS1FLLNBBG2V\\^CCGot-g6ra   )rf   rg   rh   ri   r`   __classcell__)r   s   @r$   r}   r}     s    /	7 	7ra   r}   c                b    |t         kD  ryt        | t               t        j                          y)z=Log a message to the console if the verbosity is high enough.N)r   )r   r   CONSOLEr   )r   r   s     r$   r5   r5   +  s     9	' MMOra   c                   t        dt        j                  |       z  d       | D cg c]  }t        |       }}|r!t        j
                  }t        j
                  }nd}d}t        |      }t	        j                  ||t               |||      }	|	j                         \  }
}t        |
      xs d}t        |      xs d}|	j                  dk7  rt        | |	j                  ||      yc c}w )zExecute the specified command.zExecute command: %sr   )r   N)rO   stdinr   r   r/   r   r   )r5   r   rV   r   
subprocessPIPEto_optional_bytesPopenr   communicateto_optional_text
returncoder}   )r   rO   r|   r/   c	cmd_bytesr   r   	cwd_bytesprocessstdout_bytesstderr_bytesstdout_textstderr_texts                 r$   rC   rC   4  s    

3/1=&)*!*I*!#&IyiwyQW`flopG!(!4!4!6L,"<07CK"<07CKQc7#5#5{KPP  +s   C*c                    |r(t        t        j                  j                  |              t	        | d      5 }|j                  t        |             ddd       y# 1 sw Y   yxY w)z\Write the given text content to the specified path, optionally creating missing directories.r   N)r6   r0   r1   r7   open_binary_filer   r   )r1   rY   create_directoriesfile_objs       r$   rU   rU   K  sL    "''//$'(	$	% *x()* * *s   AA$c                    	 t        j                  t        |              y# t        $ r(}|j                  t        j
                  k7  r Y d}~yd}~ww xY w)z$Remove the specified directory tree.N)r;   rmtreer   OSErrorerrnoENOENTr1   r#   s     r$   rW   rW   T  s?    htn% 88u||# $   ! 	AAAc                    	 t        j                  t        |              y# t        $ r(}|j                  t        j
                  k7  r Y d}~yd}~ww xY w)zGCreate a directory at path, including any necessary parent directories.N)r0   makedirsr   r   r   EEXISTr   s     r$   r6   r6   ]  s?    
HTN# 88u||# $r   c                d    d|vrt        d|z        t        j                  t        |       |      S )z&Open the given path for binary access.bz*mode must include "b" for binary files: %s)r9   ior   r   )r1   modes     r$   r   r   f  s/    
$DtKLL778D>4((ra   c                "    | dS t        | |      S )zgReturn the given value as bytes encoded using UTF-8 if not already bytes, or None if the value is None.N)r   valueerrorss     r$   r   r   n  s    =4=huf&==ra   c                "    | dS t        | |      S )zeReturn the given value as text decoded using UTF-8 if not already text, or None if the value is None.N)r   r   s     r$   r   r   s  s    =4<geV&<<ra   c                    t        | t              r| S t        | t              r| j                  t        |      S t        dt        |       z        )zIReturn the given value as bytes encoded using UTF-8 if not already bytes.value is not bytes or text: %s)
isinstancebytesTextencodeENCODINGr9   typer   s     r$   r   r   x  sA    %%||Hf--
4tE{B
CCra   c                    t        | t              r| j                  t        |      S t        | t              r| S t        dt        |       z        )zGReturn the given value as text decoded using UTF-8 if not already text.r   )r   r   decoder   r   r9   r   r   s     r$   r   r     sA    %||Hf--%
4tE{B
CCra   s	   {payload}__main__)r   )NFN)F)rb)strict)9ri   
__future__r   resourceSOFT_RLIMIT_NOFILE	getrlimitRLIMIT_NOFILECURRENT_RLIMIT_NOFILEDESIRED_RLIMIT_NOFILE	setrlimitr   r   r   r   r   r0   r   r;   r   r   r   typingturllib.requestr   r   r   r   r   r   r   r%   rH   rM   r\   rS   rz   r   r=   r?   r   r8   r9   r   r}   r5   rC   rU   rW   r6   r   r   r   r   r   r   rf   rj   ra   r$   <module>r      sR   P "   ***8+A+AB +-B1-EF 00Hx--/DE1    	  	    
   Cy	
**01&h"J! !<2(
451y 17& 7Q.*)>
=
DD zF ra   