
0c@_2%                 @   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 rq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 j, e-  Z. e j/ d e j0  Z1 d d   Z2 d d   Z3 d d   Z4 d d   Z5 d d   Z6 d d   Z7 d d   Z8 d  d!   Z9 d" 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 j |    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   :/tmp/pip-build-jynh7p1z/pip/pip/_internal/wheel_builder.py_contains_egg_info%   s    r   c             C   s   |  j  r d S|  j r3 | r/ t j d |  j  d S| r= d S|  j sP |  j rT d S| |   sw t j d |  j  d S|  j r t   r t j d |  j  d Sd 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.   s,    		

r)   c             C   s   t  |  d d d t S)Nr'   Tr(   )r)   _always_true)r&   r   r   r   should_build_for_wheel_command[   s    r+   c             C   s   t  |  d d d | S)Nr'   Fr(   )r)   )r&   r(   r   r   r    should_build_for_install_commandd   s    r,   c             C   s   |  j  s |  j r d S|  j r |  j j r |  j  s< t  |  j sK t  t j |  j j  } | sl t  | j |  j j	 |  j  r d Sd S|  j s t  |  j j
   \ } } t |  r d Sd 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$   linkZis_vcsAssertionErrorr   Zget_backend_for_schemeschemeZis_immutable_rev_checkouturlsplitextr   )r&   vcs_backendbaseextr   r   r   _should_cachen   s    	r5   c             C   s[   t  | j  } |  j s t  | rE t |   rE | j |  j  } n | j |  j  } | S)zdReturn the persistent or temporary cache directory where the built
    wheel need to be stored.
    )r   	cache_dirr-   r.   r5   Zget_path_for_linkZget_ephem_path_for_link)r&   wheel_cacheZcache_availabler6   r   r   r   _get_cache_dir   s    r8   c             C   s   d S)NTr   )_r   r   r   r*      s    r*   c             C   sx   y t  |  Wn? t k
 rO } z t j d |  j |  d SWYd d } ~ Xn X|  j  t |  | | |  SWd QRXd S)zaBuild one wheel.

    :return: The filename of the built wheel, or None if the build failed.
    z 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    
rA   c             C   s  t  d d  } |  j s! t  |  j ro |  j s9 t  t d |  j d |  j d |  j d | d | j  } n9 t d |  j d |  j	 d	 |  j
 d
 | d | d | j  } | d  k	 rut j j |  } t j j | |  } y\ t |  \ } }	 t j | |  t j d |  j | |	 | j    t j d |  | SWn; t k
 rt}
 z t j d |  j |
  WYd  d  }
 ~
 Xn X|  j st |  |  d  SWd  QRXd  S)Nkindwheelr"   backendmetadata_directoryr>   tempdsetup_py_pathr$   r?   z3Created wheel for %s: filename=%s size=%d sha256=%szStored in directory: %sz Building wheel for %s failed: %s)r   r"   r.   r%   rE   r   Zpep517_backendpathr   rG   Zunpacked_source_directoryosbasenamejoinr   shutilmover    r!   	hexdigest	Exceptionr;   _clean_one_legacy)r&   r=   r>   r?   temp_dir
wheel_path
wheel_nameZ	dest_pathZ
wheel_hashlengthr@   r   r   r   r<      sF    								 	r<   c             C   ss   t  |  j d | } t j d |  j  y t | d |  j d SWn) t k
 rn t j d |  j  d SYn Xd  S)Nr?   zRunning setup.py clean for %scwdTz Failed cleaning build dir for %sF)	r	   rG   r    r!   r"   r
   r$   rO   error)r&   r?   
clean_argsr   r   r   rP      s    		rP   c       	      C   sD  |  s g  g  f St  j d d j d d   |  D   t    g  g  } } x |  D] } t | |  } t | | | |  } | r t t |   | _ | j j	 | _
 | j j s t  | j |  qT | j |  qT WWd QRX| rt  j d d j d d	   | D   | r:t  j d
 d j 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>NzSuccessfully built %s c             S   s   g  |  ] } | j   q Sr   )r"   )rX   r&   r   r   r   
<listcomp>,  s   	 zbuild.<locals>.<listcomp>zFailed to build %sc             S   s   g  |  ] } | j   q Sr   )r"   )rX   r&   r   r   r   r[   1  s   	 )r    r!   rK   r   r8   rA   r   r   r-   	file_pathZlocal_file_pathr   r.   append)	requirementsr7   r>   r?   Zbuild_successesZbuild_failuresr&   r6   
wheel_filer   r   r   build  s4    

r`   )=__doc__loggingos.pathrI   rerL   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   Ztypingr   r   r   r   r   r   Zpip._internal.cacher   Zpip._internal.req.req_installr   r   ZBinaryAllowedPredicateZBuildResult	getLogger__name__r    compile
IGNORECASEr   r   r)   r+   r,   r5   r8   r*   rA   r<   rP   r`   r   r   r   r   <module>   sD   .	-	
!3