a
    bai2#                     @  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   U/var/www/html/SiteWeb/venv/lib/python3.9/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
|rd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 rtdzt|}W n$ ty   d| }t|Y n0 |tdkrt|j
tst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distZdist_verstrZmetadata_version_valuer=   msgr   r   r   _verify_oneY   s8    



rC   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|rz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_envrC   r
   r   )r!   rD   rE   r"   Zartifacter6   r   r   r   
_build_onev   s(    
*rM   )r!   rD   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   rP   pep517_backendr   r   r9   r:   r;   joinr   replacerH   info	hexdigest	ExceptionrI   )
r!   rD   r"   rQ   r6   
wheel_name	dest_path
wheel_hashlengthrL   r   r   r   rK      sN    



rK   zIterable[InstallRequirement]BuildResult)requirementsr/   rE   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sJ || q>|| q>W d   n1 s0    Y  |rt dddd	 |D  |r&t d
ddd	 |D  ||fS )zBuild 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   r^   r_   r   r   r   
<listcomp>   rb   zbuild.<locals>.<listcomp>zFailed to build %sc                 S  s   g | ]
}|j qS r   r^   r_   r   r   r   rd     rb   )rH   rU   rS   r   r8   r4   rM   r"   Zpermit_editable_wheelsZdownload_infoZrecord_download_originr   r   r$   	file_pathlocal_file_pathis_wheelappend)r]   r/   rE   build_successesbuild_failuresr!   r0   
wheel_filer   r   r   build   sH    






*rl   )<__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   Zpip._internal.metadatar   r   pip._internal.models.linkr   pip._internal.models.wheelr   $pip._internal.operations.build.wheelr   Z-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__rH   compile
IGNORECASEr   tuplelistr\   r    r.   r4   rC   rM   rK   rl   r   r   r   r   <module>   s<   
"4