o
    ¾Ôi2#  ã                   @  sr  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mZ ddlmZmZ ddlmZ dd	lmZ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" ddl#m$Z$ ddl%m&Z&m'Z' ddl(m)Z) ddl*m+Z+ e ,e-¡Z.e /dej0¡Z1e2e3e" e3e" f Z4d5dd„Z5d6dd„Z6d7d"d#„Z7d8d&d'„Z8d9d,d-„Z9d:d.d/„Z:d;d3d4„Z;dS )<z:Orchestrator for building wheels from InstallRequirements.é    )ÚannotationsN)ÚIterable)ÚTemporaryDirectory)Úcanonicalize_nameÚcanonicalize_version)ÚInvalidVersionÚVersion)Ú
WheelCache)ÚInvalidWheelFilenameÚUnsupportedWheel)ÚFilesystemWheelÚget_wheel_distribution)ÚLink)ÚWheel)Úbuild_wheel_pep517)Úbuild_wheel_editable)ÚInstallRequirement)Ú
indent_log)Ú
ensure_dirÚ	hash_file)Úpath_to_url)Úvcsz([a-z0-9_.]+)-([a-z0-9_.!+-]+)ÚsÚstrÚreturnÚboolc                 C  s   t t | ¡ƒS )zjDetermine whether the string looks like an egg_info.

    :param s: The string to parse. E.g. foo-2.1
    )r   Ú_egg_info_reÚsearch)r   © r   ú;lib/python3.10/site-packages/pip/_internal/wheel_builder.pyÚ_contains_egg_info"   s   r    Úreqr   úbool | Nonec                 C  sŠ   | j s| jsdS | jr1| jjr1| j rJ ‚| jsJ ‚t | jj¡}|s$J ‚| | jj| j¡r/dS dS | js6J ‚| j 	¡ \}}t
|ƒrCdS dS )z‹
    Return whether a built InstallRequirement can be stored in the persistent
    wheel cache, assuming the wheel cache is available.
    FT)ÚeditableZ
source_dirÚlinkZis_vcsr   Zget_backend_for_schemeÚschemeZis_immutable_rev_checkoutÚurlÚsplitextr    )r!   Zvcs_backendÚbaseÚextr   r   r   Ú_should_cache*   s   


r*   Úwheel_cacher	   c                 C  s@   t |jƒ}| js
J ‚|rt| ƒr| | j¡}|S | | j¡}|S )zdReturn the persistent or temporary cache directory where the built
    wheel need to be stored.
    )r   Ú	cache_dirr$   r*   Zget_path_for_linkZget_ephem_path_for_link)r!   r+   Zcache_availabler,   r   r   r   Ú_get_cache_dirI   s   

ÿr-   Ú
wheel_pathÚNonec           	      C  sò   t | jpdƒ}ttj |¡ƒ}|j|krtd|›d|j›ƒ‚tt|ƒ|ƒ}t	|j
ƒ}t|ƒt|j
ƒkr?td|›d|j
›ƒ‚|j}|d u rJtdƒ‚zt|ƒ}W n ty`   d|› }t|ƒ‚w |tdƒkrut|j
tƒswtd|›dƒ‚d S d S )	NÚ z)Wheel has unexpected file name: expected z, got zMissing Metadata-VersionzInvalid Metadata-Version: z1.2z+Metadata 1.2 mandates PEP 440 version, but z is not)r   Únamer   ÚosÚpathÚbasenamer
   r   r   r   Úversionr   Úmetadata_versionr   r   r   Ú
isinstance)	r!   r.   Zcanonical_nameÚwZdistZdist_verstrZmetadata_version_valuer6   Úmsgr   r   r   Ú_verify_oneY   s<   
ÿÿ
ÿÿ
þ
ÿÿr:   Ú
output_dirÚverifyr#   ú
str | Nonec              
   C  sÞ   |rdnd}zt |ƒ W n ty( } zt d|| j|¡ W Y d}~dS d}~ww | j t| ||ƒ}W d  ƒ n1 s=w   Y  |rm|rmzt| |ƒ W |S  tt	fyl } zt d|| j|¡ W Y d}~dS d}~ww |S )zaBuild one wheel.

    :return: The filename of the built wheel, or None if the build failed.
    r#   ZwheelzBuilding %s for %s failed: %sNzBuilt %s for %s is invalid: %s)
r   ÚOSErrorÚloggerÚwarningr1   Z	build_envÚ_build_one_inside_envr:   r
   r   )r!   r;   r<   r#   ZartifactÚer.   r   r   r   Ú
_build_onev   s4   
ü€ù
ÿý€þrC   c           
      C  s*  t |d†}| jsJ ‚| jsJ ‚| jsJ ‚|r#t| j| j| j|d}nt| j| j| j|d}|d ur‚tj |¡}tj 	||¡}z(t
|ƒ\}}t ||¡ t d| j||| ¡ ¡ t d|¡ |W W  d   ƒ S  ty }	 zt d| j|	¡ W Y d }	~	nd }	~	ww 	 W d   ƒ d S 1 sŽw   Y  d S )N)Údir)r1   ZbackendÚmetadata_directoryÚwheel_directoryz3Created wheel for %s: filename=%s size=%d sha256=%szStored in directory: %sz Building wheel for %s failed: %s)r   r1   rE   Zpep517_backendr   r   r2   r3   r4   Újoinr   Úreplacer?   ÚinfoZ	hexdigestÚ	Exceptionr@   )
r!   r;   r#   rF   r.   Z
wheel_nameZ	dest_pathZ
wheel_hashÚlengthrB   r   r   r   rA   ˜   sV   


üüûÛ&ý€ÿ$ÔrA   ÚrequirementsúIterable[InstallRequirement]ÚBuildResultc                 C  s*  | sg g fS t  dd dd„ | D ƒ¡¡ tƒ R g g }}| D ]B}|js&J ‚t||ƒ}t||||jo4|jƒ}|r\|j	durD| 
||j	¡ tt|ƒƒ|_|jj|_|jjsVJ ‚| |¡ q| |¡ qW d  ƒ n1 slw   Y  |rt  dd dd	„ |D ƒ¡¡ |r‘t  d
d dd	„ |D ƒ¡¡ ||fS )z˜Build wheels.

    :return: The list of InstallRequirement that succeeded to build and
        the list of InstallRequirement that failed to build.
    z*Building wheels for collected packages: %sz, c                 s  s    | ]}|j V  qd S )N©r1   ©Ú.0r!   r   r   r   Ú	<genexpr>Ü   s   € zbuild.<locals>.<genexpr>NzSuccessfully built %sú c                 S  ó   g | ]}|j ‘qS r   rO   rP   r   r   r   Ú
<listcomp>ý   ó    zbuild.<locals>.<listcomp>zFailed to build %sc                 S  rT   r   rO   rP   r   r   r   rU     rV   )r?   rI   rG   r   r1   r-   rC   r#   Zpermit_editable_wheelsZdownload_infoZrecord_download_originr   r   r$   Z	file_pathZlocal_file_pathZis_wheelÚappend)rL   r+   r<   Zbuild_successesZbuild_failuresr!   r,   Z
wheel_filer   r   r   ÚbuildÌ   sL   
þ



ü

êþþþrX   )r   r   r   r   )r!   r   r   r"   )r!   r   r+   r	   r   r   )r!   r   r.   r   r   r/   )
r!   r   r;   r   r<   r   r#   r   r   r=   )r!   r   r;   r   r#   r   r   r=   )rL   rM   r+   r	   r<   r   r   rN   )<Ú__doc__Z
__future__r   ZloggingZos.pathr2   ÚreZcollections.abcr   Ztempfiler   Zpip._vendor.packaging.utilsr   r   Zpip._vendor.packaging.versionr   r   Zpip._internal.cacher	   Zpip._internal.exceptionsr
   r   Zpip._internal.metadatar   r   Zpip._internal.models.linkr   Zpip._internal.models.wheelr   Z$pip._internal.operations.build.wheelr   Z-pip._internal.operations.build.wheel_editabler   Zpip._internal.req.req_installr   Zpip._internal.utils.loggingr   Zpip._internal.utils.miscr   r   Zpip._internal.utils.urlsr   Zpip._internal.vcsr   Z	getLoggerÚ__name__r?   ÚcompileÚ
IGNORECASEr   ÚtupleÚlistrN   r    r*   r-   r:   rC   rA   rX   r   r   r   r   Ú<module>   s>    






"4