
    9f                        % S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r
S SKJr  S SKJr  S SKJrJrJr  S SKJr  S SKJrJr  S SKJr  S SKJr  \R8                  " \5      rS	/S
/S.SS/0SS/S/S.S.SS/0S.r\\ \\ \4   4   \!S'   Sr"\RF                  " S5      r$S)S\ S\%4S jjr&S\ S\ S\4S jr'S\S \4S! jr(S*S"\%4S# jjr)S$\\    4S% jr*S*S"\%S$\\ \ 4   4S& jjr+S'\ 4S( jr,g)+    N)partial)Path)AnyDictList)urlopen)	constantspaths)animate)	PipxErrorz(aarch64-apple-darwin-install_only.tar.gzz'x86_64-apple-darwin-install_only.tar.gz)arm64x86_64glibcz-aarch64-unknown-linux-gnu-install_only.tar.gzz/x86_64_v3-unknown-linux-gnu-install_only.tar.gzz,x86_64-unknown-linux-gnu-install_only.tar.gzz0x86_64_v3-unknown-linux-musl-install_only.tar.gz)r   musl)aarch64r   AMD64z1x86_64-pc-windows-msvc-shared-install_only.tar.gz)DarwinLinuxWindowsMACHINE_SUFFIXzMhttps://api.github.com/repos/indygreg/python-build-standalone/releases/latestzcpython-(\d+\.\d+\.\d+)python_versionoverridec                    [         R                  " SSU 5      n [        R                  R                  U -  n[
        R                  (       a  US-  OUS-  S-  nU(       a,  UR                  5       (       a  [        R                  " U5        OdUR                  5       (       a  [        U5      $ UR                  5       (       a/  [        R                  SU  S35        [        R                  " U5        [        U 5      u  pE[        R                  " 5        n[!        U5      SU S	3-  n[!        U5      S
-  n[#        XEU5        [%        XEXx5        US-  n	[        R&                  " X5        SSS5        [        U5      $ ! , (       d  f       N= f)zWhen all other python executable resolutions have failed,
attempt to download and use an appropriate python build
from https://github.com/indygreg/python-build-standalone
and unpack it into the pipx shared directory.z
[c]?python z
python.exebinpython3z%A previous attempt to install python z failed. Retrying.zpython-z.tar.gzdownloadpythonN)resubr
   ctxstandalone_python_cachedirr	   WINDOWSexistsshutilrmtreestrloggerwarningresolve_python_versiontempfileTemporaryDirectoryr   	_download_unpackmove)
r   r   install_dirinstalled_pythonfull_versiondownload_linktempdirarchivedownload_dirextracted_dirs
             8/usr/lib/python3/dist-packages/pipx/standalone_python.py download_python_build_standaloner9   2   sD    VVM2~>N))66GK5>5F5F{\1KZ_L_bkLkMM+&""$$'((NNB>BRRdefMM+&"8"HL		$	$	&'w-GL>"AAG}z1 	,w7 	WC
 %x/M/ 
'    ! 
'	&s   AE88
Fr2   r3   r5   c           	         [        SU  S3S5          [        U5       n[        US5       n[        [	        UR
                  S5      S5       H  nUR                  U5        M     S S S 5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       N(= f! [        R                  R                   a  n[        SU  S35      UeS nAff = f! , (       d  f       g = f)	NzDownloading python  buildTwbi       zUnable to download python z build.)r   r   openiterr   readwriteurlliberrorURLErrorr   )r2   r3   r5   responsefile_handledataes          r8   r-   r-   _   s    	&|nF;T	B	W '8T'45HK !>DD%%d+ E 6I'	 
C	B 6I5H'' ||$$ 	W8gNOUVV	W 
C	Bsb   CBB9A=$B,B=
BB
B	BCBC=CCC
C#r6   c           
      4   [        SU  S3S5         [        US5       n[        R                  " UR	                  5       5      R                  5       nS S S 5        US-   n[        U5      R	                  5       R                  5       R                  S5      nWU:w  a  [        SU  SU S	U S
35      e[        R                  " USS9 nUR                  U5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       N(= f! , (       d  f       g = f)NzUnpacking python r;   Trbz.sha256
zChecksum mismatch for python z build. Expected z, got .zr:gz)mode)r   r>   hashlibsha256r@   	hexdigestr   decoderstripr   tarfile
extractall)	r2   r3   r5   r6   
python_zipchecksumchecksum_linkexpected_checksumtars	            r8   r.   r.   k   s    	$\N&94	@'4 J~~joo&78BBDH ! &	1#M2779@@BII$O((/~=NO`Naaghpgqqrs  \\'/3NN<( 0 
A	@   0/ 
A	@s;   D	3C'A3D	C8D	'
C5	1D	8
D	D		
D	use_cachec                 F   [         R                  R                  S-  nU (       a  UR                  5       (       a  [        R
                  " UR                  5       5      n[        R                  R                  US   5      n[        R                  R                  5       U-
  [        R                  " SS9:  a  0 nO0 nU(       d^  [        5       n[        R                  R                  5       R                  5       US.nUR                  [        R                  " U5      5        U$ )z_Get or update the index of available python builds from
the python-build-standalone repository.z
index.jsonfetched   )days)r\   releases)r
   r!   r"   r$   jsonloads	read_textdatetimefromtimestampnow	timedeltaget_latest_python_releases	timestamp
write_textdumps)rZ   
index_fileindexr\   r_   s        r8   get_or_update_indexrm   }   s     55DJZ&&((

://12##11%	2BC  "W,x/A/Ar/JJE-/$--113==?XVdjj/0Lr=   returnc                  0    [        [        5       n [        R                  " U 5      nSSS5        WS    Vs/ s H  o3S   PM	     sn$ ! , (       d  f       N&= f! [        R
                  R                   a  n[        S[         S35      UeSnAff = fs  snf )zIReturns the list of python download links from the latest github release.Nz;Unable to fetch python-build-standalone release data (from z).assetsbrowser_download_url)r   GITHUB_API_URLr`   loadrB   rC   rD   r   )rE   release_datarH   assets       r8   rg   rg      s    q^$99X.L % 8DH7MN7Me()7MNN %$ <<   qUVdUeeghioppq Os8   A AA B
AA A B7BBc                 
   [         R                  " 5       [         R                  " 5       p![        U   U   nUS:X  a%  [         R                  " 5       S   =(       d    SnX4   n[        U 5      S   nU VVs/ s H'  nU  H  nUR                  U5      (       d  M  UPM     M)     nnn0 n	U H-  n[        R                  U5      n
U
c   eU
S   nX;   a  M)  XyU'   M/     [        U	S SS9 Vs0 s H  nXU   _M
     sn$ s  snnf s  snf )	zLReturns available python versions for your machine and their download links.r   r   r   r_      c                 b    U R                  S5       Vs/ s H  n[        U5      PM     sn$ s  snf )NrL   )splitint)versionks     r8   <lambda>list_pythons.<locals>.<lambda>   s%    s1C D1CAQ1C D Ds   ,T)keyreverse)
platformsystemmachiner   libc_verrm   endswithPYTHON_VERSION_REGEXsearchsorted)rZ   r   r   download_link_suffixeslibc_versionpython_releasesdownload_link_suffixlinkavailable_python_linkspython_versionsmatchr   r{   s                r8   list_pythonsr      s/   oo')9)9);G+F3G<((*1-7!7!E))4Z@O
 %; %; #D==-.	 	 $ 	$:   ')O&$++D1   q,*.' ' D	

G 	))
 '&s   4 C:
C:(D requested_versionc                     [        5       nU R                  S5      nUR                  5        H,  u  p4UR                  S5      nX%S [        U5       :X  d  M)  X44s  $    [	        SU  S35      e)NrL   z5Unable to acquire a standalone python build matching )r   ry   itemslenr   )r   pythonsrequested_releaser2   r3   standalone_releases         r8   r*   r*      su    nG)//4'.}}#)//43KS9J5K LL.. (7
 KL]K^^_`
aar=   )F)T)-rc   rN   r`   loggingr   r   r%   rS   r+   urllib.errorrB   	functoolsr   pathlibr   typingr   r   r   urllib.requestr   pipxr	   r
   pipx.animater   	pipx.utilr   	getLogger__name__r(   r   r'   __annotations__rr   compiler   boolr9   r-   r.   rm   rg   r   r*    r=   r8   <module>r      sb        	       " " " !   			8	$ ==<= EF
 B> HH
 MNO%-S$sCx.() * azz"<= *!S *!D *!Z	WC 	W 	Wd 	W)$ )d )$4 (
ODI 
O'D 'DcN 'T	bc 	br=   