
    dho                       d Z ddlmZ ddlZddlZddl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mZmZmZmZmZmZ ddlmZ ddl m!Z!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,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z:m;Z; ddl<m=Z= ddl>m?Z?m@Z@mAZAmBZB ddlCmDZD ddlEmFZF ddlGmHZH erddlImJZJ  e5eK      ZL	 	 	 	 	 	 	 	 	 	 	 	 d*d ZMd+d!ZNe	 G d" d#             ZO	 	 d,	 	 	 	 	 	 	 	 	 d-d$ZP	 d,	 	 	 	 	 	 	 d.d%ZQ	 	 d,	 	 	 	 	 	 	 	 	 	 	 	 	 d/d&ZR	 d0	 	 	 	 	 	 	 	 	 d1d'ZS G d( d)      ZTy)2z(Prepares a distribution for installation    )annotationsN)Iterable)	dataclass)Path)TYPE_CHECKING)canonicalize_name)BuildEnvironmentInstaller))make_distribution_for_install_requirement)InstalledDistribution)DirectoryUrlHashUnsupportedHashMismatchHashUnpinnedInstallationErrorMetadataInconsistentNetworkConnectionErrorVcsHashUnsupported)PackageFinder)BaseDistributionget_metadata_distribution)ArchiveInfo)Link)Wheel)
Downloader)HTTPRangeRequestUnsupporteddist_from_wheel_url)
PipSession)BuildTracker)InstallRequirement)	getLogger)direct_url_for_editabledirect_url_from_link)HashesMissingHashes)
indent_log)display_path	hash_filehide_urlredact_auth_from_requirement)TempDirectory)unpack_file)vcs)BarTypec                   t        |       }|j                  }|>|j                  | |      5  |j                  |||       ddd       |j	                         S |j	                         S # 1 sw Y   |j	                         S xY w)z(Prepare a distribution for installation.N)r
   build_tracker_idtrackprepare_distribution_metadatar   )reqbuild_trackerbuild_env_installerbuild_isolationcheck_build_depsabstract_dist
tracker_ids          b/var/www/html/vivango/api/ia/venv/lib/python3.12/site-packages/pip/_internal/operations/prepare.py_get_prepared_distributionr9   A   s     >cBM//J  j1 	77#_6F	 2244=2244		 2244s   A((B c                    t        j                  | j                        }|J |j                  |t	        | j
                        |       y )N)url	verbosity)r+   get_backend_for_schemeschemeunpackr'   r;   )linklocationr<   vcs_backends       r8   unpack_vcs_linkrC   S   s@    ,,T[[9K"""xXdhh%79M    c                  .    e Zd ZU ded<   dZded<   ddZy)FilestrpathN
str | Nonecontent_typec                    | j                   )	 t        j                  | j                        d   | _         y y # t        $ r Y y w xY w)Nr   )rJ   	mimetypes
guess_typerH   OSError)selfs    r8   __post_init__zFile.__post_init__^   sH    $$-$8$8$CA$F!	 %
  s   '7 	AA)returnNone)__name__
__module____qualname____annotations__rJ   rP    rD   r8   rF   rF   Y   s    
I#L*#rD   rF   c                    t        dd      }d }|rt        | ||      }|r|}d }n) || |j                        \  }}|r|j                  |       t	        ||      S )Nr?   Tkindglobally_managed)r)   _check_download_dirrH   check_against_pathrF   )r@   downloaddownload_dirhashestemp_diralready_downloaded_path	from_pathrJ   s           r8   get_http_urlrd   h   sj     (TBH""5dL&"Q+	 #+4"?	<%%i0	<((rD   c                    d}|rt        | ||      }|r|}n| j                  }|r|j                  |       t        |d      S )z'Get file and optionally check its hash.N)r\   	file_pathr]   rF   )r@   r_   r`   rb   rc   s        r8   get_file_urlrg      sM    
 #"5dL&"Q+	NN	 !!),	4  rD   c                   | j                   rt        | ||       y| j                         rJ | j                  rt	        | ||      }nt        | |||      }| j                  s!t        |j                  ||j                         |S )a_  Unpack link into location, downloading if required.

    :param hashes: A Hashes object, one of whose embedded hashes must match,
        or HashMismatch will be raised. If the Hashes is empty, no matches are
        required, and unhashable types of requirements (like VCS ones, which
        would ordinarily raise HashUnsupported) are allowed.
    )r<   Nr`   )
is_vcsrC   is_existing_diris_filerg   rd   is_wheelr*   rH   rJ   )r@   rA   r^   r<   r_   r`   files          r8   
unpack_urlro      s      {{h)<##%%% ||D,v> 	
 ==DIIx):):;KrD   c                j   t         j                  j                  || j                        }t         j                  j	                  |      syt
        j                  d|       |r	 |j                  |       |S |S # t        $ r0 |rt
        j                  d|       t        j                  |       Y yw xY w)zCheck download_dir for previously downloaded file with correct hash
    If a correct file is found return its path else None
    NzFile was already downloaded %sz;Previously-downloaded file %s has bad hash. Re-downloading.)osrH   joinfilenameexistsloggerinfor]   r   warningunlink)r@   r_   r`   warn_on_hash_mismatchdownload_paths        r8   r\   r\      s     GGLLt}}=M77>>-( KK0-@		%%m4 =  	$Q! IIm$	s   $A9 96B21B2c                  >    e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZddZ	 	 	 	 	 	 ddZddZ	 	 	 	 ddZ	 	 	 	 ddZ		 	 	 	 ddZ
	 d	 	 	 	 	 dd	Z	 d	 	 	 	 	 dd
Z	 d	 	 	 	 	 ddZ	 	 	 	 	 	 ddZddZ	 	 	 	 ddZ	 	 	 	 	 	 ddZ xZS )RequirementPreparerzPrepares a Requirementc               &   t         |           || _        || _        || _        || _        t        ||	|      | _        |
| _        || _	        || _
        || _        || _        || _        || _        || _        || _        || _        i | _        d| _        y )N) r~   )super__init__src_dir	build_dirr2   _sessionr   	_downloadfinderr_   r4   r3   r5   require_hashesuse_user_siteuse_lazy_wheelr<   legacy_resolver_downloaded_previous_requirement_header)rO   r   r_   r   r4   build_isolation_installerr5   r2   sessionprogress_barr   r   r   
lazy_wheelr<   r   resume_retries	__class__s                    r8   r   zRequirementPreparer.__init__   s    ( 	"*#G\>J )  /#<  !1 - + ) #  / ,. -5)rD   c                   |j                   j                  r7|j                  s+d}t        t	        |j                   j
                              }n.d}|j                  rt        |j                        n
t        |      }|j                  rX|j                  rLt        |j                  t              r|j                  }n|j                  j                         }|r	|d| dz  }||f| j                  k7  r||f| _        t        j                  ||       |j                  r>t               5  t        j                  d|j                   j                         ddd       yy# 1 sw Y   yxY w)z3Provide context for the requirement being prepared.zProcessing %szCollecting %sz (from )zUsing cached %sN)r@   rl   is_wheel_from_cacherG   r%   rf   r1   r(   
comes_from
isinstancerc   r   ru   rv   r$   rs   )rO   r1   messageinformationr   s        r8   _log_preparing_linkz'RequirementPreparer._log_preparing_link!  s   88C$;$;%Gl388+=+=>?K%GCF776sww?PSTWPXK 77s~~#..#.),
 ^^557
A66[!T%F%FF18+0FD-KK-"" B-sxx/@/@AB B #B Bs   &+EE$c                   |j                   j                  ry|j                  J |j                   j                         r|j                   j                  |_        y|j                  | j                  d|       |j                          y)z1Ensure source_dir of a linked InstallRequirement.NT)
autodeleteparallel_builds)r@   rm   
source_dirrk   rf   ensure_has_source_dirr   ensure_pristine_source_checkout)rO   r1   r   s      r8   _ensure_link_req_src_dirz,RequirementPreparer._ensure_link_req_src_dir<  sz    
 88 ~~%%%88##% XX//CN 	!!NN+ 	" 	

 	++-rD   c                F   | j                   s|j                  d      S |j                  j                  r
t	               |j                  j                         r
t               |j                  s|j                  s
t               |j                  d      xs
 t               S )NT)trust_internetF)r   r`   r@   rj   r   rk   r   	is_direct	is_pinnedr   r#   rO   r1   s     r8   _get_linked_req_hashesz*RequirementPreparer._get_linked_req_hashesS  s~     ""::T:22 88??$&&88##%-// }}S]].  zzz/B=?BrD   c                    | j                   rt        j                  d       y | j                  rt        j                  d       y | j	                  |      xs | j                  |j                        S )Nz9Metadata-only fetching is not used in the legacy resolverz?Metadata-only fetching is not used as hash checking is required)r   ru   debugr   $_fetch_metadata_using_link_data_attr _fetch_metadata_using_lazy_wheelr@   r   s     r8   _fetch_metadata_onlyz(RequirementPreparer._fetch_metadata_onlys  sk     LLK LLQ 88
 =22388<	=rD   c                   |j                   j                         }|y|j                  J t        j	                  d|j                  |       t        || j                  |j                               }t        |j                  d      5 }|j                         }ddd       t        |j                   j                  |j                  j                        }t        |j                        t        |j                  j                        k7  r,t!        |d|j                  j                  |j                        |S # 1 sw Y   xY w)zGFetch metadata from the data-dist-info-metadata attribute, if possible.Nz/Obtaining dependency information for %s from %sri   rbName)r@   metadata_linkr1   ru   verboserd   r   	as_hashesopenrH   readr   rs   namer   raw_namer   )rO   r1   r   metadata_filefmetadata_contentsmetadata_dists          r8   r   z8RequirementPreparer._fetch_metadata_using_link_data_attr  s    ..0 ww"""=GG	
 %NN **,

 -$$d+ 	)q !	) 2HHGGLL
 ]3348I#'',,8WW&VSWW\\=+A+A  %	) 	)s   	D::Ec                   | j                   sy|j                  s|j                  st        j	                  d|       yt        |j                        }t        |j                        }t        j                  d||j                         |j                  j                  dd      d   }	 t        ||| j                        S # t        $ r t        j	                  d|       Y yw xY w)z-Fetch metadata using lazy wheel, if possible.Nz=Lazy wheel is not used as %r does not point to a remote wheelz+Obtaining dependency information from %s %s#   r   z"%s does not support range requests)r   rl   rm   ru   r   r   rs   r   r   rv   versionr;   splitr   r   r   )rO   r@   wheelr   r;   s        r8   r   z4RequirementPreparer._fetch_metadata_using_lazy_wheel  s     ""<<t}}LLO dmm$ ,9MM	

 hhnnS!$Q'	&tS$--@@* 	LL=sC	s   (B? ?C! C!c                   t        dd      j                  }i }|D ]  }|j                  sJ |||j                  <   ! | j                  j	                  |j                         |      }|D ]u  \  }\  }}	t        j                  d||       ||   }||_        || j                  |j                  j                  <   |j                  r\|j                  t        |             w |D ]  }| j                  ||        y)z>Download any requirements which were only fetched by metadata.r?   TrY   zDownloading link %s to %sN)r)   rH   r@   r   batchkeysru   r   local_file_pathr   r;   rm   needs_unpacked_archiver   _prepare_linked_requirement)
rO   partially_downloaded_reqsr   ra   links_to_fully_downloadr1   batch_downloadr@   filepath_s
             r8   _complete_partial_requirementsz2RequirementPreparer._complete_partial_requirements  s     !hFKK
 CE, 	4C88O803#CHH-	4 --.E.J.J.LhW#1 	;D-8QLL4dHE)$/C #+C .6DSXX\\* <<**4>:	;& - 	CC,,S/B	CrD   c                    |j                   sJ | j                  |       t               5  d}| j                  U|j                   j                  r?| j                  |      }t        |j                   | j                  ||j                         }|$|| j                  |j                   j                  <   n%| j                  |      }|d|_        |cddd       S | j                  ||      cddd       S # 1 sw Y   yxY w)z3Prepare a requirement to be obtained from req.link.N)ry   T)r@   r   r$   r_   rm   r   r\   r   r   r;   r   needs_more_preparationr   )rO   r1   r   rf   r`   r   s         r8   prepare_linked_requirementz.RequirementPreparer.prepare_linked_requirement  s     xxx  %\ 	J I  ,1B1B44S9/HH%% /2.E.E*E	 $1:  . !% 9 9# > ,15C.(7	J 	J< 33CI=	J 	J 	Js   B%C4C44C=c                   |D cg c]  }|j                   s| }}|D ]  }| j                  |j                  j                  s'| j	                  |      }t        |j                  | j                  |      }|\|| j                  |j                  j                  <   d|_          g }|D ]2  }|j                   r|j                  |       !| j                  ||       4 | j                  ||       yc c}w )z,Prepare linked requirements more, if needed.NF)r   )r   r_   r@   rm   r   r\   r   r;   appendr   r   )rO   reqsr   r1   r`   rf   r   s          r8    prepare_linked_requirements_morez4RequirementPreparer.prepare_linked_requirements_more  s      $Bs'A'ABB 	7C  ,1B1B44S9/$:K:KVT	(5>D$$SXX\\216C.	7 ?A! 	GC)))00500oF		G 	++%+ 	, 	
+ Cs
   C4C4c           	        |j                   sJ |j                   }| j                  |      }|r|j                  r|j                  J |j                  sJ |j
                  sJ t        |j                  j                  t              rR|j                  j                  j                  r2|j                  |j                  j                  j                        rd }n2t        j                  d       |j                  |_         |j                   }| j                  ||       |j                         rd }n|j                   | j"                  vr:	 t%        ||j&                  | j(                  | j*                  | j,                  |      }n9| j"                  |j                      }|r|j3                  |       t5        |d       }|j                  |j6                  rJ t9        ||j&                        |_        t        |j                  j                  t              rf|j                  j                  j                  sF|rDt;        |j<                        d   j?                         }d| |j                  j                  _         |r|j<                  |_!        tE        || jF                  | jH                  | jJ                  | jL                        }	|	S # t.        $ r}t1        d| d| d|       d }~ww xY w)NzyThe hashes of the source archive found in cache entry don't match, ignoring cached built wheel and re-downloading source.zCould not install requirement z because of HTTP error z	 for URL )rJ   r   zsha256=)'r@   r   r   download_inform   rl   r   rv   r   r`   
has_one_ofru   rw   cached_wheel_source_linkr   rk   r;   r   ro   r   r   r<   r_   r   r   r]   rF   editabler!   r&   rH   	hexdigesthashr   r9   r2   r3   r4   r5   )
rO   r1   r   r@   r`   
local_fileexcrf   r   dists
             r8   r   z/RequirementPreparer._prepare_linked_requirement9  s    xxxxx,,S1c--$$000== =<<< 3,,11;?%%**11%%c&7&7&<&<&C&CD 1
 77xx%%c?;!JXXT---'NNNNNN%%
 ((2I)))4id;J $ ||## 4T3>> JC 3,,11;?))..55 1!4>>@ 18v.>!!&&+ ",//C)$$  !!
 W * '4SE : E4&2 s   
8K 	K)K$$K)c                n   | j                   J |j                  J |j                  }|j                  s|j                         r(|j                  r|j                  | j                          y |j                         rt        j                  d|       y |j                  y t        j                  j                  | j                   |j                        }t        j                  j                  |      sBt        j                  |j                  |       t!        |      }t        j#                  d|       y y )NzENot copying link to destination directory since it is a directory: %szSaved %s)r_   r@   rj   rk   r   archiveru   r   r   rq   rH   rr   rs   rt   shutilcopyr%   rv   )rO   r1   r@   download_locationrz   s        r8   save_linked_requirementz+RequirementPreparer.save_linked_requirement  s      ,,,xx###xx;;4//1cllKK))*!LL.
 &GGLL):):DMMJww~~/0KK++->?():;MKK
M2 1rD   c                   |j                   sJ d       t        j                  d|       t               5  | j                  rt        d| d      |j                  | j                         |j                          |j                  sJ t        |j                        |_        t        || j                  | j                  | j                   | j"                        }|j%                  | j&                         ddd       |S # 1 sw Y   S xY w)z Prepare an editable requirement.z-cannot prepare a non-editable req as editablezObtaining %szThe editable requirement zT cannot be installed when requiring hashes, because there is no single file to hash.N)r   ru   rv   r$   r   r   r   r   update_editabler   r    unpacked_source_directoryr   r9   r2   r3   r4   r5   check_if_existsr   )rO   r1   r   s      r8   prepare_editable_requirementz0RequirementPreparer.prepare_editable_requirement  s    
 ||LLL|NC(\ 	4""'/u 5  
 %%dll3!>>!> 78U8U VC-""(($$%%D  2 23)	4, -	4, s   CC??D	c                `   |j                   sJ d       |J d|j                           t        j                  d|||j                   j                         t	               5  | j
                  rt        j                  d       t        |      j                         cddd       S # 1 sw Y   yxY w)z)Prepare an already-installed requirement.z(req should have been satisfied but isn'tNz?did not get skip reason skipped but req.satisfied_by is set to zRequirement %s: %s (%s)zSince it is already installed, we are trusting this package without checking its hash. To ensure a completely repeatable environment, install into an empty virtualenv.)	satisfied_byru   rv   r   r$   r   r   r   r   )rO   r1   skip_reasons      r8   prepare_installed_requirementz1RequirementPreparer.prepare_installed_requirement  s     K!KK& 	
))*,	
& 	%{C9I9I9Q9Q	
 \ 	J""( )-GGI	J 	J 	Js    :B$$B-)"r   rG   r_   rI   r   rG   r4   boolr   r	   r5   r   r2   r   r   r   r   r,   r   r   r   r   r   r   r   r   r<   intr   r   r   r   rQ   rR   )r1   r   rQ   rR   )r1   r   r   r   rQ   rR   )r1   r   rQ   r"   )r1   r   rQ   BaseDistribution | None)r@   r   rQ   r   )F)r   Iterable[InstallRequirement]r   r   rQ   rR   )r1   r   r   r   rQ   r   )r   r   r   r   rQ   rR   )r1   r   rQ   r   )r1   r   r   rG   rQ   r   )rS   rT   rU   __doc__r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r   s   @r8   r|   r|      s    ;5 ;5 !	;5
 ;5 ;5 $=;5 ;5 $;5 ;5 ;5 ;5 ;5 ;5 ;5  !;5" #;5$ %;5& 
';5zB6.%.8<.	..C@== 
!=&'' 
!'R 
!@ !&'C#?'C 'C 
	'CT @E$J%$J8<$J	$JN KP
0
CG
	
<Z%Z8<Z	Zx34 
BJJ J 
	JrD   r|   )r1   r   r2   r   r3   r	   r4   r   r5   r   rQ   r   )r@   r   rA   rG   r<   r   rQ   rR   )NN)
r@   r   r^   r   r_   rI   r`   Hashes | NonerQ   rF   )r@   r   r_   rI   r`   r   rQ   rF   )r@   r   rA   rG   r^   r   r<   r   r_   rI   r`   r   rQ   zFile | None)T)
r@   r   r_   rG   r`   r   ry   r   rQ   rI   )Ur   
__future__r   rL   rq   r   collections.abcr   dataclassesr   pathlibr   typingr   pip._vendor.packaging.utilsr   pip._internal.build_envr	   pip._internal.distributionsr
   %pip._internal.distributions.installedr   pip._internal.exceptionsr   r   r   r   r   r   r   "pip._internal.index.package_finderr   pip._internal.metadatar   r   pip._internal.models.direct_urlr   pip._internal.models.linkr   pip._internal.models.wheelr   pip._internal.network.downloadr    pip._internal.network.lazy_wheelr   r   pip._internal.network.sessionr   ,pip._internal.operations.build.build_trackerr   pip._internal.req.req_installr   pip._internal.utils._logr   &pip._internal.utils.direct_url_helpersr    r!   pip._internal.utils.hashesr"   r#   pip._internal.utils.loggingr$   pip._internal.utils.miscr%   r&   r'   r(   pip._internal.utils.temp_dirr)   pip._internal.utils.unpackingr*   pip._internal.vcsr+   pip._internal.cli.progress_barsr,   rS   ru   r9   rC   rF   rd   rg   ro   r\   r|   rW   rD   r8   <module>r     s   . #  	  $ !    9 = Q G   = N 7 * , 5 5 E < . = 2  7 5 !7	8	5	55 35 	5
 5 5$N   "  $ 	)
)) ) 	)
 
)2 JN!
!(!9F!	!:  $ (
(( ( 	(
 ( ( (^ #'	
   	
 <EJ EJrD   