a
    ñ»j2#  ã                   @  s®  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 Z4dddœdd„Z5dddœdd„Z6dddd œd!d"„Z7ddd#d$œd%d&„Z8ddddd'd(œd)d*„Z9dddd'd+œd,d-„Z:d.ddd/d0œd1d2„Z;dS )3z: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_.!+-]+)ÚstrÚbool)ÚsÚreturnc                 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   úAE:\soccer\ml_env\Lib\site-packages\pip/_internal/wheel_builder.pyÚ_contains_egg_info"   s    r    r   zbool | None)Úreqr   c                 C  sŠ   | j s| jsdS | jrb| jjrb| j r(J ‚| js2J ‚t | jj¡}|sHJ ‚| | jj| j¡r^dS dS | jslJ ‚| j 	¡ \}}t
|ƒr†dS dS )z‹
    Return whether a built InstallRequirement can be stored in the persistent
    wheel cache, assuming the wheel cache is available.
    FT)ÚeditableÚ
source_dirÚlinkÚis_vcsr   Úget_backend_for_schemeÚschemeÚis_immutable_rev_checkoutÚurlÚsplitextr    )r!   Úvcs_backendÚbaseÚextr   r   r   Ú_should_cache*   s    


r.   r	   )r!   Úwheel_cacher   c                 C  s>   t |jƒ}| jsJ ‚|r.t| ƒr.| | j¡}n| | j¡}|S )zdReturn the persistent or temporary cache directory where the built
    wheel need to be stored.
    )r   Ú	cache_dirr$   r.   Úget_path_for_linkÚget_ephem_path_for_link)r!   r/   Úcache_availabler0   r   r   r   Ú_get_cache_dirI   s    

r4   ÚNone)r!   Ú
wheel_pathr   c           	      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 r”tdƒ‚zt|ƒ}W n$ tyÄ   d|› �}t|ƒ‚Y n0 |tdƒkrît|j
tƒsîtd|›d�ƒ‚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!   r6   Úcanonical_nameÚwÚdistÚdist_verstrÚmetadata_version_valuer=   Úmsgr   r   r   Ú_verify_oneY   s8    
ÿÿ
ÿÿ

ÿrE   z
str | None)r!   Ú
output_dirÚverifyr"   r   c              
   C  sÜ   |rdnd}zt |ƒ W n8 tyP } z t d|| j|¡ W Y d}~dS d}~0 0 | j� t| ||ƒ}W d  ƒ n1 sz0    Y  |rØ|rØzt| |ƒ W n< tt	fyÖ } z t d|| j|¡ W Y d}~dS d}~0 0 |S )zaBuild one wheel.

    :return: The filename of the built wheel, or None if the build failed.
    r"   ÚwheelzBuilding %s for %s failed: %sNzBuilt %s for %s is invalid: %s)
r   ÚOSErrorÚloggerÚwarningr8   Ú	build_envÚ_build_one_inside_envrE   r
   r   )r!   rF   rG   r"   ÚartifactÚer6   r   r   r   Ú
_build_onev   s(    
ü*rP   )r!   rF   r"   r   c           
      C  s0  t |d���}| jsJ ‚| js"J ‚| js,J ‚|rHt| j| j| j|d�}nt| j| j| j|d�}|d u�r
tj |¡}tj 	||¡}zPt
|ƒ\}}t ||¡ t d| j||| ¡ ¡ t d|¡ |W W  d   ƒ S  t�y }	 zt d| j|	¡ W Y d }	~	n
d }	~	0 0 W d   ƒ d S 1 �s"0    Y  d S )N)Údir)r8   Ú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   r8   rS   Úpep517_backendr   r   r9   r:   r;   Újoinr   ÚreplacerJ   ÚinfoÚ	hexdigestÚ	ExceptionrK   )
r!   rF   r"   rT   r6   Ú
wheel_nameÚ	dest_pathÚ
wheel_hashÚlengthrO   r   r   r   rM   ˜   sN    


üü
ûýrM   zIterable[InstallRequirement]ÚBuildResult)Úrequirementsr/   rG   r   c                 C  s.  | sg g fS t  dd dd„ | D ƒ¡¡ tƒ �¤ g g  }}| D ]„}|jsLJ ‚t||ƒ}t||||joh|jƒ}|r¸|j	durˆ| 
||j	¡ tt|ƒƒ|_|jj|_|jjs¬J ‚| |¡ q>| |¡ q>W d  ƒ n1 sØ0    Y  |�rt  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©r8   ©Ú.0r!   r   r   r   Ú	<genexpr>Ü   ó    zbuild.<locals>.<genexpr>NzSuccessfully built %sú c                 S  s   g | ]
}|j ‘qS r   ra   rb   r   r   r   Ú
<listcomp>ý   re   zbuild.<locals>.<listcomp>zFailed to build %sc                 S  s   g | ]
}|j ‘qS r   ra   rb   r   r   r   rg     re   )rJ   rX   rV   r   r8   r4   rP   r"   Úpermit_editable_wheelsZdownload_infoZrecord_download_originr   r   r$   Ú	file_pathÚlocal_file_pathÚis_wheelÚappend)r`   r/   rG   Úbuild_successesÚbuild_failuresr!   r0   Ú
wheel_filer   r   r   ÚbuildÌ   sH    
þ



ü

*þþrp   )<Ú__doc__Ú
__future__r   ÚloggingÚos.pathr9   ÚreÚcollections.abcr   Útempfiler   Úpip._vendor.packaging.utilsr   r   Zpip._vendor.packaging.versionr   r   Úpip._internal.cacher	   Úpip._internal.exceptionsr
   r   Úpip._internal.metadatar   r   Úpip._internal.models.linkr   Úpip._internal.models.wheelr   Ú$pip._internal.operations.build.wheelr   Ú-pip._internal.operations.build.wheel_editabler   Zpip._internal.req.req_installr   Úpip._internal.utils.loggingr   Úpip._internal.utils.miscr   r   Úpip._internal.utils.urlsr   Úpip._internal.vcsr   Ú	getLoggerÚ__name__rJ   ÚcompileÚ
IGNORECASEr   ÚtupleÚlistr_   r    r.   r4   rE   rP   rM   rp   r   r   r   r   Ú<module>   s<   
"4