o
    ©„jº#  ã                   @  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 Z4d6dd„Z5d7dd„Z6d8d"d#„Z7d9d&d'„Z8d:d,d-„Z9d;d.d/„Z:d<d4d5„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   úY/var/www/html/django_cbt/venv/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r| j ¡ rdS | jr;| jjr;| j rJ ‚| js#J ‚t | jj¡}|s.J ‚| | jj	| j¡r9dS dS | js@J ‚| j 
¡ \}}t|ƒrMd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_existing_dirÚis_vcsr   Úget_backend_for_schemeÚschemeÚis_immutable_rev_checkoutÚurlÚsplitextr    )r!   Úvcs_backendÚbaseÚextr   r   r   Ú_should_cache*   s"   


r0   Ú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%   r0   Úget_path_for_linkÚget_ephem_path_for_link)r!   r1   Úcache_availabler2   r   r   r   Ú_get_cache_dirL   s   

ÿr6   Ú
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!   r7   Úcanonical_nameÚwÚdistÚdist_verstrÚmetadata_version_valuer?   Úmsgr   r   r   Ú_verify_one\   s<   
ÿÿ
ÿÿ
þ
ÿÿrG   Ú
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#   ÚwheelzBuilding %s for %s failed: %sNzBuilt %s for %s is invalid: %s)
r   ÚOSErrorÚloggerÚwarningr:   Ú	build_envÚ_build_one_inside_envrG   r
   r   )r!   rH   rI   r#   ÚartifactÚer7   r   r   r   Ú
_build_oney   s4   
ü€ù
ÿý€þrS   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)r:   Ú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   r:   rV   Úpep517_backendr   r   r;   r<   r=   Újoinr   ÚreplacerM   ÚinfoÚ	hexdigestÚ	ExceptionrN   )
r!   rH   r#   rW   r7   Ú
wheel_nameÚ	dest_pathÚ
wheel_hashÚlengthrR   r   r   r   rP   ›   sV   


üüûÛ&ý€ÿ$ÔrP   ÚrequirementsúIterable[InstallRequirement]Úallow_editablesÚBuildResultc           	      C  s(  | sg g fS t  dd dd„ | D ƒ¡¡ tƒ �Q g g }}| D ]A}|js&J ‚t||ƒ}t||||jo3|ƒ}|r[|jdurC| 	||j¡ t
t|ƒƒ|_|jj|_|jjsUJ ‚| |¡ q| |¡ qW d  ƒ n1 skw   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©r:   ©Ú.0r!   r   r   r   Ú	<genexpr>à   s   € zbuild.<locals>.<genexpr>NzSuccessfully built %sú c                 S  ó   g | ]}|j ‘qS r   rf   rg   r   r   r   Ú
<listcomp>  ó    zbuild.<locals>.<listcomp>zFailed to build %sc                 S  rk   r   rf   rg   r   r   r   rl     rm   )rM   r[   rY   r   r:   r6   rS   r#   Údownload_infoÚrecord_download_originr   r   r%   Ú	file_pathÚlocal_file_pathÚis_wheelÚappend)	rb   r1   rI   rd   Úbuild_successesÚbuild_failuresr!   r2   Ú
wheel_filer   r   r   ÚbuildÏ   sL   þ


ü

êþþþrw   )r   r   r   r   )r!   r   r   r"   )r!   r   r1   r	   r   r   )r!   r   r7   r   r   r8   )
r!   r   rH   r   rI   r   r#   r   r   rJ   )r!   r   rH   r   r#   r   r   rJ   )
rb   rc   r1   r	   rI   r   rd   r   r   re   )<Ú__doc__Ú
__future__r   ÚloggingÚos.pathr;   ÚreÚcollections.abcr   Útempfiler   Úpip._vendor.packaging.utilsr   r   Ú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   Úpip._internal.req.req_installr   Úpip._internal.utils.loggingr   Úpip._internal.utils.miscr   r   Úpip._internal.utils.urlsr   Úpip._internal.vcsr   Ú	getLoggerÚ__name__rM   ÚcompileÚ
IGNORECASEr   ÚtupleÚlistre   r    r0   r6   rG   rS   rP   rw   r   r   r   r   Ú<module>   s>    



"


"4