o
    h+                     @  s  d Z ddlmZ ddlZddlZddlZddl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% 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/m0Z0 ddl1m2Z2 e3e4Z5e6dej7Z8e9e:e# e:e# f Z;dAddZ<dBd d!Z=dBd"d#Z>dCd%d&Z?dDd)d*Z@dEd-d.ZAdFd6d7ZBdGd8d9ZCdHd:d;ZDdId?d@ZEdS )Jz:Orchestrator for building wheels from InstallRequirements.    )annotationsN)Iterable)canonicalize_namecanonicalize_version)InvalidVersionVersion)
WheelCache)InvalidWheelFilenameUnsupportedWheel)FilesystemWheelget_wheel_distribution)Link)Wheel)build_wheel_pep517)build_wheel_editable)build_wheel_legacy)InstallRequirement)
indent_log)
ensure_dir	hash_file)make_setuptools_clean_args)call_subprocess)TempDirectory)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!   N/var/www/html/venv/lib/python3.10/site-packages/pip/_internal/wheel_builder.py_contains_egg_info&   s   r#   reqr   c                 C  s.   | j rJ | jr
dS | jsJ | jr| jS dS )zBReturn whether an InstallRequirement should be built into a wheel.FT)
constraintis_wheel
source_direditablesupports_pyproject_editabler$   r!   r!   r"   _should_build.   s   

r+   c                 C  s   t | S N)r+   r*   r!   r!   r"    should_build_for_install_command@   s   r-   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, and _should_build()
    has determined a wheel needs to be built.
    FT)r(   r'   linkis_vcsr   get_backend_for_schemeschemeis_immutable_rev_checkouturlsplitextr#   )r$   vcs_backendbaseextr!   r!   r"   _should_cacheF   s   


r9   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/   r9   get_path_for_linkget_ephem_path_for_link)r$   r:   cache_availabler;   r!   r!   r"   _get_cache_dirf   s   

r?   
wheel_pathNonec           	      C  s   t | jpd}ttj|}t |j|kr!td|d|jtt||}t	|j
}t|t|j
krAtd|d|j
|j}|d u rLtdzt|}W n tyb   d| }t|w |tdkrwt|j
tsyt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@   canonical_namewdistdist_verstrmetadata_version_valuerH   msgr!   r!   r"   _verify_onev   s<   


rP   
output_dirverifybuild_options	list[str]global_optionsr(   
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  |ro|rozt| | W |S  tt	fyn } 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warningrC   	build_env_build_one_inside_envrP   r	   r
   )	r$   rQ   rR   rS   rU   r(   artifacter@   r!   r!   r"   
_build_one   s8   

r_   c                 C  s  t dd}| jsJ | jrF| jsJ | jsJ |r!td| j |r*td| j |r9t| j| j| j|jd}nt	| j| j| j|jd}nt
| j| j| j|||jd}|d urt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 | jst| | 	 W d    d S 1 sw   Y  d S )
NrW   )kindz7Ignoring --global-option when building %s using PEP 517z6Ignoring --build-option when building %s using PEP 517)rC   backendmetadata_directorytempd)rC   setup_py_pathr'   rU   rS   rc   z3Created wheel for %s: filename=%s size=%d sha256=%szStored in directory: %sz Building wheel for %s failed: %s)r   rC   
use_pep517rb   pep517_backendrY   rZ   r   rE   r   r   rd   unpacked_source_directoryrD   rF   joinr   shutilmoveinfo	hexdigest	Exception_clean_one_legacy)r$   rQ   rS   rU   r(   temp_dirr@   
wheel_name	dest_path
wheel_hashlengthr^   r!   r!   r"   r\      s|   


	4
$r\   c                 C  sV   t | j|d}td| j zt|d| jd W dS  ty*   td| j Y dS w )N)rU   zRunning setup.py clean for %szpython setup.py clean)command_desccwdTz Failed cleaning build dir for %sF)	r   rd   rY   rk   rC   r   r'   rm   error)r$   rU   
clean_argsr!   r!   r"   rn      s   rn   requirementsIterable[InstallRequirement]BuildResultc           
   	   C  s.  | sg g fS t dddd | D  t T g g }}| D ]D}|js&J t||}t||||||jo6|j}	|	r^|j	durF|
||j	 tt|	|_|jj|_|jjsXJ || q|| qW d   n1 snw   Y  |rt dddd	 |D  |rt 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 r,   rC   .0r$   r!   r!   r"   	<genexpr>#  s    zbuild.<locals>.<genexpr>NzSuccessfully built %s c                 S     g | ]}|j qS r!   r{   r|   r!   r!   r"   
<listcomp>F      zbuild.<locals>.<listcomp>zFailed to build %sc                 S  r   r!   r{   r|   r!   r!   r"   r   K  r   )rY   rk   rh   r   rC   r?   r_   r(   permit_editable_wheelsdownload_inforecord_download_originr   r   r/   	file_pathlocal_file_pathr&   append)
rx   r:   rR   rS   rU   build_successesbuild_failuresr$   r;   
wheel_filer!   r!   r"   build  sP   





r   )r   r   r   r   )r$   r   r   r   )r$   r   r   r.   )r$   r   r:   r   r   r   )r$   r   r@   r   r   rA   )r$   r   rQ   r   rR   r   rS   rT   rU   rT   r(   r   r   rV   )r$   r   rQ   r   rS   rT   rU   rT   r(   r   r   rV   )r$   r   rU   rT   r   r   )rx   ry   r:   r   rR   r   rS   rT   rU   rT   r   rz   )F__doc__
__future__r   loggingos.pathrD   reri   collections.abcr   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.operations.build.wheel_legacyr   pip._internal.req.req_installr   pip._internal.utils.loggingr   pip._internal.utils.miscr   r   $pip._internal.utils.setuptools_buildr   pip._internal.utils.subprocessr   pip._internal.utils.temp_dirr   pip._internal.utils.urlsr   pip._internal.vcsr   	getLogger__name__rY   compile
IGNORECASEr   tuplelistrz   r#   r+   r-   r9   r?   rP   r_   r\   rn   r   r!   r!   r!   r"   <module>   sL    





 


&
G