U
    Eh$                     @   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$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0dej1fd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PatternTuple)
WheelCache)InstallRequirementz([a-z0-9_.]+)-([a-z0-9_.!+-]+)c                 C   s   t || S )zjDetermine whether the string looks like an egg_info.

    :param s: The string to parse. E.g. foo-2.1
    )boolsearch)sZ_egg_info_re r   A./venv/lib/python3.8/site-packages/pip/_internal/wheel_builder.py_contains_egg_info&   s    r   c                 C   sl   | j r
dS | jr&|r"td| j dS |r.dS | js>t s>dS | jsJ| jsNdS || sht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.)	Z
constraintis_wheelloggerinfoname
use_pep517r   editable
source_dir)req
need_wheelcheck_binary_allowedr   r   r   _should_build0   s,     r(   c                 C   s   t | dtdS )NTr&   r'   )r(   _always_true)r%   r   r   r   should_build_for_wheel_commandY   s
      r+   c                 C   s   t | d|dS )NFr)   )r(   )r%   r'   r   r   r    should_build_for_install_commandb   s
      r,   c                 C   s   t | tdsdS | jrb| jjrb| jr(t| js2tt| jj	}|sHt|
| jj| jr^dS dS | 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.
    )r'   FT)r,   r*   linkZis_vcsr#   AssertionErrorr$   r   Zget_backend_for_schemeZschemeZis_immutable_rev_checkoutZurlsplitextr   )r%   Zvcs_backendbaseextr   r   r   _should_cachel   s"    	 

r2   c                 C   s4   t |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_dirr2   Zget_path_for_linkr-   Zget_ephem_path_for_link)r%   wheel_cacheZcache_availabler3   r   r   r   _get_cache_dir   s
    
r5   c                 C   s   dS )NTr   )_r   r   r   r*      s    r*   c              
   C   sr   zt | W n8 tk
rD } ztd| j| W Y dS d}~X Y nX | j t| |||W  5 Q R  S Q R X 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!   Z	build_env_build_one_inside_env)r%   
output_dirbuild_optionsglobal_optionser   r   r   
_build_one   s         r?   c                 C   s  t dd}| jr0t| j| j| j||jd}nt| j| j| j	|||jd}|d k	rt
j|}t
j||}zNt|\}}	t|| td| j||	|  td| |W W  5 Q R  S  tk
r }
 ztd| j|
 W 5 d }
~
X Y nX | jst| | W 5 Q R  d S Q R X d S )NZwheel)kind)r!   Zbackendmetadata_directoryr<   tempd)r!   setup_py_pathr$   r=   r<   rB   z3Created wheel for %s: filename=%s size=%d sha256=%szStored in directory: %sr7   )r   r"   r   r!   Zpep517_backendrA   pathr   rC   Zunpacked_source_directoryosbasenamejoinr   shutilmover   r    Z	hexdigest	Exceptionr9   _clean_one_legacy)r%   r;   r<   r=   Ztemp_dirZ
wheel_pathZ
wheel_nameZ	dest_pathZ
wheel_hashlengthr>   r   r   r   r:      sP    	   
r:   c                 C   sZ   t | j|d}td| j zt|| jd W dS  tk
rT   td| j Y dS X d S )N)r=   zRunning setup.py clean for %s)cwdTz Failed cleaning build dir for %sF)	r	   rC   r   r    r!   r
   r$   rJ   error)r%   r=   Z
clean_argsr   r   r   rK      s    rK   c           	   	   C   s   | sg g fS t dddd | D  t p g g  }}| D ]Z}t||}t||||}|rtt||_|jj	|_
|jjst|| q>|| q>W 5 Q R X |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!   .0r%   r   r   r   	<genexpr>  s     zbuild.<locals>.<genexpr>zSuccessfully built %s c                 S   s   g | ]
}|j qS r   rO   rP   r   r   r   
<listcomp>)  s     zbuild.<locals>.<listcomp>zFailed to build %sc                 S   s   g | ]
}|j qS r   rO   rP   r   r   r   rT   .  s     )r   r    rG   r   r5   r?   r   r   r-   Z	file_pathZlocal_file_pathr   r.   append)	Zrequirementsr4   r<   r=   Zbuild_successesZbuild_failuresr%   r3   Z
wheel_filer   r   r   build   sB    

   
rV   )=__doc__ZloggingZos.pathrE   rerH   Zpip._internal.models.linkr   Z$pip._internal.operations.build.wheelr   Z+pip._internal.operations.build.wheel_legacyr   Zpip._internal.utils.loggingr   Zpip._internal.utils.miscr   r   r   Z$pip._internal.utils.setuptools_buildr	   Zpip._internal.utils.subprocessr
   Zpip._internal.utils.temp_dirr   Zpip._internal.utils.typingr   Zpip._internal.utils.urlsr   Zpip._internal.vcsr   typingr   r   r   r   r   r   r   Zpip._internal.cacher   Zpip._internal.req.req_installr   r   ZBinaryAllowedPredicateZBuildResultZ	getLogger__name__r   compileIr   r(   r+   r,   r2   r5   r*   r?   r:   rK   rV   r   r   r   r   <module>   sD   $


)	
#1