a
    û"©b2%  ã                   @   s„  d 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	 ddl
mZ ddlmZ ddlmZ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 e�rddlmZm Z m!Z!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z( e e(ge)f Z*e$e"e( e"e( f Z+e ,e-¡Z.e /dej0¡Z1dd„ Z2dd„ Z3dd„ Z4dd„ Z5dd„ Z6dd„ Z7dd„ Z8d d!„ Z9d"d#„ Z:d$d%„ Z;d&d'„ Z<dS )(z;Orchestrator for building wheels from InstallRequirements.
é    N)ÚLink)Úbuild_wheel_pep517)Úbuild_wheel_legacy)Ú
indent_log)Ú
ensure_dirÚ	hash_fileÚis_wheel_installed)Úmake_setuptools_clean_args)Úcall_subprocess)ÚTempDirectory)ÚMYPY_CHECK_RUNNING)Úpath_to_url)Úvcs)ÚAnyÚCallableÚIterableÚListÚOptionalÚTuple)Ú
WheelCache)ÚInstallRequirementz([a-z0-9_.]+)-([a-z0-9_.!+-]+)c                 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)Ús© r   úd/home/yuhw/wc/wire-cell-python-pr-11/pr11/lib/python3.9/site-packages/pip/_internal/wheel_builder.pyÚ_contains_egg_info%   s    r   c                 C   sz   | j r
dS | jr&|r"t d| j¡ dS |r.dS | js:| js>dS || ƒsXt d| j¡ dS | jsvtƒ svt d| j¡ dS dS )zBReturn whether an InstallRequirement should be built into a wheel.Fz(Skipping %s, due to already being wheel.TzCSkipping wheel build for %s, due to binaries being disabled for it.zOUsing legacy 'setup.py install' for %s, since package 'wheel' is not installed.)	Ú
constraintÚis_wheelÚloggerÚinfoÚnameÚeditableÚ
source_dirÚ
use_pep517r   )ÚreqÚ
need_wheelÚcheck_binary_allowedr   r   r   Ú_should_build.   s2    ÿþþr)   c                 C   s   t | dtd�S )NT©r'   r(   )r)   Ú_always_true)r&   r   r   r   Úshould_build_for_wheel_command[   s    ÿr,   c                 C   s   t | d|d�S )NFr*   )r)   )r&   r(   r   r   r   Ú should_build_for_install_commandd   s    ÿr-   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_cachen   s    	


r8   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.   r8   Úget_path_for_linkÚget_ephem_path_for_link)r&   Úwheel_cacheÚcache_availabler9   r   r   r   Ú_get_cache_dir�   s    

r>   c                 C   s   dS )NTr   )Ú_r   r   r   r+       s    r+   c              
   C   s|   zt |ƒ W n6 tyB } zt d| j|¡ W Y d}~dS d}~0 0 | j� t| |||ƒW  d  ƒ S 1 sn0    Y  dS )zaBuild one wheel.

    :return: The filename of the built wheel, or None if the build failed.
    ú Building wheel for %s failed: %sN)r   ÚOSErrorr    Úwarningr"   Ú	build_envÚ_build_one_inside_env)r&   Ú
output_dirÚbuild_optionsÚglobal_optionsÚer   r   r   Ú
_build_one¥   s    þÿrI   c                 C   sD  t dd���"}| jsJ ‚| jrD| js(J ‚t| j| j| j||jd�}nt| j| 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 | j�st| |ƒ W d   ƒ d S 1 �s60    Y  d S )NÚwheel)Úkind)r"   ÚbackendÚmetadata_directoryrF   Útempd)r"   Úsetup_py_pathr$   rG   rF   rN   z3Created wheel for %s: filename=%s size=%d sha256=%szStored in directory: %sr@   )r   r"   r%   rM   r   Úpep517_backendÚpathr   rO   Úunpacked_source_directoryÚosÚbasenameÚjoinr   ÚshutilÚmover    r!   Ú	hexdigestÚ	ExceptionrB   Ú_clean_one_legacy)r&   rE   rF   rG   Útemp_dirÚ
wheel_pathÚ
wheel_nameÚ	dest_pathÚ
wheel_hashÚlengthrH   r   r   r   rD   À   sN    

ûú	
ýþ
rD   c                 C   sX   t | j|d�}t d| j¡ zt|| jd� W dS  tyR   t d| j¡ Y dS 0 d S )N)rG   zRunning setup.py clean for %s)ÚcwdTz Failed cleaning build dir for %sF)	r	   rO   r    r!   r"   r
   r$   rY   Úerror)r&   rG   Ú
clean_argsr   r   r   rZ   ó   s    þrZ   c           	      C   s   | sg g fS t  dd dd„ | D ƒ¡¡ tƒ �z g g  }}| D ]Z}t||ƒ}t||||ƒ}|rŽ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>  ó    zbuild.<locals>.<genexpr>NzSuccessfully built %sú c                 S   s   g | ]
}|j ‘qS r   rd   re   r   r   r   Ú
<listcomp>,  rh   zbuild.<locals>.<listcomp>zFailed to build %sc                 S   s   g | ]
}|j ‘qS r   rd   re   r   r   r   rj   1  rh   )r    r!   rU   r   r>   rI   r   r   r.   Ú	file_pathÚlocal_file_pathr   Úappend)	Úrequirementsr<   rF   rG   Úbuild_successesÚbuild_failuresr&   r9   Ú
wheel_filer   r   r   Úbuild  s<    þ

ÿ
*þþrr   )=Ú__doc__ÚloggingÚos.pathrS   ÚrerV   Úpip._internal.models.linkr   Ú$pip._internal.operations.build.wheelr   Ú+pip._internal.operations.build.wheel_legacyr   Úpip._internal.utils.loggingr   Úpip._internal.utils.miscr   r   r   Ú$pip._internal.utils.setuptools_buildr	   Úpip._internal.utils.subprocessr
   Úpip._internal.utils.temp_dirr   Úpip._internal.utils.typingr   Úpip._internal.utils.urlsr   Úpip._internal.vcsr   Útypingr   r   r   r   r   r   Úpip._internal.cacher   Zpip._internal.req.req_installr   r   ZBinaryAllowedPredicateZBuildResultÚ	getLoggerÚ__name__r    ÚcompileÚ
IGNORECASEr   r   r)   r,   r-   r8   r>   r+   rI   rD   rZ   rr   r   r   r   r   Ú<module>   sD    
	-	
!3