a
    w–BeB.  ã                   @   sV  d Z ddlZddlZddlZddlZddlmZmZm	Z	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l0m1Z1 ddl2m3Z3 e 4e5¡Z6e 7dej8¡Z9e
ee$ ee$ f Z:e;e<dœdd„Z=e$e<e<dœdd„Z>e$e<dœdd„Z?e$e<dœd d!„Z@e$e	e< dœd"d#„ZAe$ee;d$œd%d&„ZBe$e;dd'œd(d)„ZCe$e;e<ee; ee; e<e	e; d*œd+d,„ZDe$e;ee; ee; e<e	e; d-œd.d/„ZEe$ee; e<d0œd1d2„ZFee$ ee<ee; ee; e:d3œd4d5„ZGdS )6z;Orchestrator for building wheels from InstallRequirements.
é    N)ÚIterableÚListÚOptionalÚTuple)Ú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Ú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
    )ÚboolÚ_egg_info_reÚsearch)r   © r"   ú^/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pip/_internal/wheel_builder.pyÚ_contains_egg_info%   s    r$   )ÚreqÚ
need_wheelr   c                 C   sJ   | j r
dS | jr&|r"t d| j¡ dS |r.dS | js8dS | jrF|  ¡ S dS )zBReturn whether an InstallRequirement should be built into a wheel.Fz(Skipping %s, due to already being wheel.T)Ú
constraintÚis_wheelÚloggerÚinfoÚnameÚ
source_dirÚeditableZsupports_pyproject_editable)r%   r&   r"   r"   r#   Ú_should_build-   s     þr.   )r%   r   c                 C   s   t | dd�S )NT©r&   ©r.   ©r%   r"   r"   r#   Úshould_build_for_wheel_commandN   s    r2   c                 C   s   t | dd�S )NFr/   r0   r1   r"   r"   r#   Ú should_build_for_install_commandT   s    r3   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, 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_cacheZ   s    


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_dirr4   r>   Úget_path_for_linkÚget_ephem_path_for_link)r%   r?   Úcache_availabler@   r"   r"   r#   Ú_get_cache_dirz   s    

rD   )r%   Ú
wheel_pathr   c           	      C   sì   t | jp
dƒ}ttj |¡ƒ}t |jƒ|kr>td ||j¡ƒ‚tt	|ƒ|ƒ}t
|jƒ}t|ƒt|jƒkrzt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 S )NÚ z7Wheel has unexpected file name: expected {!r}, got {!r}zMissing Metadata-VersionzInvalid Metadata-Version: z1.2z6Metadata 1.2 mandates PEP 440 version, but {!r} is not)r   r+   r   ÚosÚpathÚbasenamer   Úformatr   r   ÚstrÚversionr   Úmetadata_versionr   r	   r   Ú
isinstance)	r%   rE   Úcanonical_nameÚwÚdistZdist_verstrZmetadata_version_valuerM   Úmsgr"   r"   r#   Ú_verify_oneŠ   s<    ÿÿ
ÿÿ
ÿÿrS   )r%   Ú
output_dirÚverifyÚbuild_optionsÚglobal_optionsr-   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 s~0    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   ÚOSErrorr)   Úwarningr+   Ú	build_envÚ_build_one_inside_envrS   r   r   )	r%   rT   rU   rV   rW   r-   ZartifactÚerE   r"   r"   r#   Ú
_build_one¨   s,    ü
ÿ"r^   )r%   rT   rV   rW   r-   r   c                 C   sŽ  t dd���l}| jsJ ‚| jrŽ| js(J ‚| js2J ‚|rDt d| j¡ |rVt d| j¡ |rtt| j| j| j|jd�}qªt	| j| j| j|jd�}nt
| j| j| j|||jd�}|d u�rVtj |¡}tj ||¡}zPt|ƒ\}	}
t ||¡ t d| j||
|	 ¡ ¡ t d|¡ |W W  d   ƒ S  t�yT } zt d	| j|¡ W Y d }~n
d }~0 0 | j�sht| |ƒ W d   ƒ d S 1 �s€0    Y  d S )
NrX   )Úkindz7Ignoring --global-option when building %s using PEP 517z6Ignoring --build-option when building %s using PEP 517)r+   ÚbackendÚmetadata_directoryÚtempd)r+   Úsetup_py_pathr,   rW   rV   rb   z3Created wheel for %s: filename=%s size=%d sha256=%szStored in directory: %sz Building wheel for %s failed: %s)r   r+   Ú
use_pep517ra   Úpep517_backendr)   rZ   r   rH   r   r   rc   Úunpacked_source_directoryrG   rI   Újoinr   ÚshutilÚmover*   Ú	hexdigestÚ	ExceptionÚ_clean_one_legacy)r%   rT   rV   rW   r-   Útemp_dirrE   Ú
wheel_nameÚ	dest_pathÚ
wheel_hashÚlengthr]   r"   r"   r#   r\   Î   st    


ÿÿüüú	
ûý
r\   )r%   rW   r   c                 C   sZ   t | j|d�}t d| j¡ zt|d| jd� W dS  tyT   t d| j¡ Y dS 0 d S )N)rW   zRunning setup.py clean for %szpython setup.py clean)Úcommand_descÚcwdTz Failed cleaning build dir for %sF)	r   rc   r)   r*   r+   r   r,   rk   Úerror)r%   rW   Ú
clean_argsr"   r"   r#   rl     s    þÿrl   )Úrequirementsr?   rU   rV   rW   r   c           
   	   C   s2  | sg g fS t  dd dd„ | D ƒ¡¡ tƒ �¨ g g  }}| D ]ˆ}|jsLJ ‚t||ƒ}t||||||jol|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©r+   ©Ú.0r%   r"   r"   r#   Ú	<genexpr>8  ó    zbuild.<locals>.<genexpr>NzSuccessfully built %sú c                 S   s   g | ]
}|j ‘qS r"   rw   rx   r"   r"   r#   Ú
<listcomp>[  r{   zbuild.<locals>.<listcomp>zFailed to build %sc                 S   s   g | ]
}|j ‘qS r"   rw   rx   r"   r"   r#   r}   `  r{   )r)   r*   rg   r   r+   rD   r^   r-   Zpermit_editable_wheelsZdownload_infoZrecord_download_originr   r   r4   Ú	file_pathÚlocal_file_pathr(   Úappend)
rv   r?   rU   rV   rW   Úbuild_successesÚbuild_failuresr%   r@   Ú
wheel_filer"   r"   r#   Úbuild&  sL    þ



ú

*þþr„   )HÚ__doc__ÚloggingÚos.pathrG   Úrerh   Útypingr   r   r   r   Zpip._vendor.packaging.utilsr   r   Ú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   Ú+pip._internal.operations.build.wheel_legacyr   Z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__r)   ÚcompileÚ
IGNORECASEr    ZBuildResultrK   r   r$   r.   r2   r3   r>   rD   rS   r^   r\   rl   r„   r"   r"   r"   r#   Ú<module>   sˆ   
	ý"þþþ!ýù'úGú