a
    e0hq.                     @   s  d Z ddlZddlZddlZddlZddl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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 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/ e)rxddl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z: e2e:ge;f Z<e6e4e: e4e: f Z=e>e?Z@eAdejBZCdd ZDdd ZEdd ZFdd  ZGd!d" ZHd#d$ ZId%d& ZJd'd( ZKd)d* ZLd+d, ZMd-d. ZNd/d0 ZOd1d2 ZPdS )3z;Orchestrator for building wheels from InstallRequirements.
    N)canonicalize_namecanonicalize_version)InvalidVersionVersion)parse)Distribution)InvalidWheelFilenameUnsupportedWheel)Link)Wheel)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)$pkg_resources_distribution_for_wheel)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%   I/var/www/auris/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_build5   s2    r3   c                 C   s   t | dtdS )NTr1   r2   )r3   _always_true)r0   r%   r%   r&   should_build_for_wheel_commandb   s    r6   c                 C   s   t | d|dS )NFr4   )r3   )r0   r2   r%   r%   r&    should_build_for_install_commandk   s    r7   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, 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'   )r0   vcs_backendbaseextr%   r%   r&   _should_cacheu   s    	


rB   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_dirr8   rB   get_path_for_linkget_ephem_path_for_link)r0   wheel_cachecache_availablerC   r%   r%   r&   _get_cache_dir   s    

rH   c                 C   s   dS )NTr%   )_r%   r%   r&   r5      s    r5   c              	   C   st   |  | jD ]Z}| dr|ddd  }zt|W   S  tyd   d|}t	|Y q0 qt	dd S )Nzmetadata-version::   zInvalid Metadata-Version: {}zMissing Metadata-Version)
get_metadata_linesPKG_INFOlower
startswithsplitstripr   r   formatr	   )distlinevaluemsgr%   r%   r&   _get_metadata_version   s    
rX   c                 C   s   t | j}ttj|}t |j|kr:td||jtj	|dd}t
|||}W d    n1 sj0    Y  t|jt|jkrtd|j|jt|tdkrtt|jtstd|jd S )Nz7Wheel has unexpected file name: expected {!r}, got {!r}T)
allowZip64z1.2z6Metadata 1.2 mandates PEP 440 version, but {!r} is not)r   r,   r   ospathbasenamer   rS   zipfileZipFiler   r   versionrX   r   
isinstanceparse_versionr	   )r0   
wheel_pathcanonical_namewzfrT   r%   r%   r&   _verify_one   s4    
"rf   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   n1 sn0    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.
     Building wheel for %s failed: %sNz!Built wheel for %s is invalid: %s)
r   OSErrorr*   warningr,   	build_env_build_one_inside_envrf   r   r	   )r0   
output_dirverifybuild_optionsglobal_optionserb   r%   r%   r&   
_build_one   s&    "rq   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_directoryrn   tempd)r,   setup_py_pathr.   ro   rn   rv   z3Created wheel for %s: filename=%s size=%d sha256=%szStored in directory: %srg   )r   r,   r/   ru   r   pep517_backendr[   r   rw   unpacked_source_directoryrZ   r\   joinr   shutilmover*   r+   	hexdigest	Exceptionri   _clean_one_legacy)r0   rl   rn   ro   temp_dirrb   
wheel_name	dest_path
wheel_hashlengthrp   r%   r%   r&   rk      sN    

	

rk   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)ro   zRunning setup.py clean for %s)cwdTz Failed cleaning build dir for %sF)	r   rw   r*   r+   r,   r   r.   r~   error)r0   ro   
clean_argsr%   r%   r&   r   )  s    r   c           
      C   s  | sg g fS t dddd | D  t | g g  }}| D ]\}t||}t|||||}	|	rtt|	|_|jj	|_
|jjsJ || q>|| q>W d   n1 s0    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 )Nr,   .0r0   r%   r%   r&   	<genexpr>L      zbuild.<locals>.<genexpr>NzSuccessfully built %s c                 S   s   g | ]
}|j qS r%   r   r   r%   r%   r&   
<listcomp>c  r   zbuild.<locals>.<listcomp>zFailed to build %sc                 S   s   g | ]
}|j qS r%   r   r   r%   r%   r&   r   h  r   )r*   r+   rz   r   rH   rq   r
   r   r8   	file_pathlocal_file_pathr)   append)
requirementsrF   rm   rn   ro   build_successesbuild_failuresr0   rC   
wheel_filer%   r%   r&   build9  s<    



*r   )Q__doc__loggingos.pathrZ   rer{   r]   pip._vendor.packaging.utilsr   r   Zpip._vendor.packaging.versionr   r   r   ra   Zpip._vendor.pkg_resourcesr   pip._internal.exceptionsr   r	   pip._internal.models.linkr
   pip._internal.models.wheelr   $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.utils.wheelr   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'   r3   r6   r7   rB   rH   r5   rX   rf   rq   rk   r   r   r%   r%   r%   r&   <module>   sX    
	-	
!#3