3
ûâde×/  ã               @   s„  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
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+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ej7e8ƒZ9ej:dej;ƒZ<ee&ge=f Z>ee
e& e
e& f Z?e@e=dœdd„ZAe&e=e>e=dœdd„ZBe&e=dœdd„ZCe&e>e=d œd!d"„ZDe&ee= dœd#d$„ZEe&ee@d%œd&d'„ZFee=d(œd)d*„ZGe&e@dd+œd,d-„ZHe&e@e=e
e@ e
e@ e=ee@ d.œd/d0„ZIe&e@e
e@ e
e@ e=ee@ d1œd2d3„ZJe&e
e@ e=d4œd5d6„ZKe	e& ee=e
e@ e
e@ e?d7œd8d9„ZLdS ):z;Orchestrator for building wheels from InstallRequirements.
é    N)ÚAnyÚCallableÚ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Úis_wheel_installed)Úmake_setuptools_clean_args)Úcall_subprocess)ÚTempDirectory)Úpath_to_url)Úvcsz([a-z0-9_.]+)-([a-z0-9_.!+-]+))ÚsÚreturnc             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)r    © r%   ú:/tmp/pip-build-red6nood/pip/pip/_internal/wheel_builder.pyÚ_contains_egg_info&   s    r'   )ÚreqÚ
need_wheelÚcheck_binary_allowedr!   c             C   s†   | j r
dS | jr&|r"tjd| jƒ dS |r.dS | js8dS | jrF| jƒ S | jrPdS || ƒsjtjd| jƒ dS t	ƒ s‚tj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Ú
source_dirÚeditableZsupports_pyproject_editableÚ
use_pep517r   )r(   r)   r*   r%   r%   r&   Ú_should_build.   s6    r3   )r(   r!   c             C   s   t | dtd�S )NT)r)   r*   )r3   Ú_always_true)r(   r%   r%   r&   Úshould_build_for_wheel_commandc   s    r5   )r(   r*   r!   c             C   s   t | d|d�S )NF)r)   r*   )r3   )r(   r*   r%   r%   r&   Ú should_build_for_install_commandi   s    r6   c             C   sŽ   | j s| j rdS | jrf| jjrf| j  s,t‚| js6t‚tj| jjƒ}|sLt‚|j| jj	| jƒrbdS dS | jspt‚| j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)r1   r0   ÚlinkZis_vcsÚAssertionErrorr   Zget_backend_for_schemeÚschemeZis_immutable_rev_checkoutÚurlÚsplitextr'   )r(   Úvcs_backendÚbaseÚextr%   r%   r&   Ú_should_cacher   s    

r?   )r(   Úwheel_cacher!   c             C   s>   t |jƒ}| jst‚|r.t| ƒr.|j| jƒ}n|j| jƒ}|S )zdReturn the persistent or temporary cache directory where the built
    wheel need to be stored.
    )r"   Ú	cache_dirr7   r8   r?   Zget_path_for_linkZget_ephem_path_for_link)r(   r@   Zcache_availablerA   r%   r%   r&   Ú_get_cache_dir’   s    

rB   )Ú_r!   c             C   s   dS )NTr%   )rC   r%   r%   r&   r4   ¢   s    r4   )r(   Ú
wheel_pathr!   c       	      C   sð   t | jp
dƒ}ttjj|ƒƒ}t |jƒ|kr>tdj||jƒƒ‚tt	|ƒ|ƒ}t
|jƒ}t|ƒt|jƒkrztdj||jƒƒ‚|j}|d kr�tdƒ‚yt|ƒ}W n& tk
rÂ   d|› �}t|ƒ‚Y nX |tdƒkrìt|jtƒ rìtdj|ƒƒ‚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(   rD   Úcanonical_nameÚwÚdistZdist_verstrZmetadata_version_valuerL   Úmsgr%   r%   r&   Ú_verify_one¦   s0    

rR   )r(   Ú
output_dirÚverifyÚbuild_optionsÚglobal_optionsr1   r!   c       	   &   C   sÀ   |rdnd}yt |ƒ W n2 tk
rJ } ztjd|| j|ƒ dS d}~X nX | j� t| ||||ƒ}W dQ R X |r¼|r¼yt| |ƒ W n6 tt	fk
rº } ztjd|| j|ƒ dS d}~X nX |S )zaBuild one wheel.

    :return: The filename of the built wheel, or None if the build failed.
    r1   ÚwheelzBuilding %s for %s failed: %sNzBuilt %s for %s is invalid: %s)
r   ÚOSErrorr-   Úwarningr/   Z	build_envÚ_build_one_inside_envrR   r   r   )	r(   rS   rT   rU   rV   r1   ZartifactÚerD   r%   r%   r&   Ú
_build_oneÄ   s(    r\   )r(   rS   rU   rV   r1   r!   c             C   sd  t dd���N}| jst‚| jrŽ| js(t‚| js2t‚|rDtjd| jƒ |rVtjd| jƒ |rtt| j| j| j|j	d�}qªt
| j| j| j|j	d�}nt| j| j| j|||j	d�}|d k	�rDtj	j|ƒ}tj	j||ƒ}y@t|ƒ\}	}
tj||ƒ tjd| j||
|	jƒ ƒ tjd|ƒ |S  tk
�rB } ztjd	| j|ƒ W Y d d }~X nX | j�sVt| |ƒ d S Q R X d S )
NrW   )Ú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_pathr0   rV   rU   r`   z3Created wheel for %s: filename=%s size=%d sha256=%szStored in directory: %sz Building wheel for %s failed: %s)r   r/   r8   r2   r_   Zpep517_backendr-   rY   r   rG   r   r   ra   Zunpacked_source_directoryrF   rH   Újoinr   ÚshutilÚmover.   Ú	hexdigestÚ	ExceptionÚ_clean_one_legacy)r(   rS   rU   rV   r1   Útemp_dirrD   Ú
wheel_nameZ	dest_pathZ
wheel_hashÚlengthr[   r%   r%   r&   rZ   ê   sf    








rZ   )r(   rV   r!   c             C   sV   t | j|d�}tjd| jƒ yt|| jd� dS  tk
rP   tjd| jƒ dS X d S )N)rV   zRunning setup.py clean for %s)ÚcwdTz Failed cleaning build dir for %sF)	r   ra   r-   r.   r/   r   r0   rf   Úerror)r(   rV   Ú
clean_argsr%   r%   r&   rg   1  s    rg   )Úrequirementsr@   rT   rU   rV   r!   c       
      C   s  | sg g fS t jddjdd„ | D ƒƒƒ tƒ �Š g g  }}xx| D ]p}|jsNt‚t||ƒ}t||||||jon|j	ƒ}	|	r¦t
t|	ƒƒ|_|jj|_|jjsšt‚|j|ƒ q@|j|ƒ q@W W dQ R X |rÞt jddjdd	„ |D ƒƒƒ |�r t jd
dj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>R  s    zbuild.<locals>.<genexpr>NzSuccessfully built %sú c             S   s   g | ]
}|j ‘qS r%   )r/   )ro   r(   r%   r%   r&   ú
<listcomp>o  s    zbuild.<locals>.<listcomp>zFailed to build %sc             S   s   g | ]
}|j ‘qS r%   )r/   )ro   r(   r%   r%   r&   rr   t  s    )r-   r.   rb   r   r/   r8   rB   r\   r1   Zpermit_editable_wheelsr   r   r7   Ú	file_pathZlocal_file_pathr,   Úappend)
rn   r@   rT   rU   rV   Zbuild_successesZbuild_failuresr(   rA   Ú
wheel_filer%   r%   r&   Úbuild@  s@    




rv   )MÚ__doc__ÚloggingÚos.pathrF   Úrerc   Útypingr   r   r   r   r   r   Úpip._vendor.packaging.utilsr   r	   Zpip._vendor.packaging.versionr
   r   Zpip._internal.cacher   Zpip._internal.exceptionsr   r   Zpip._internal.metadatar   r   Zpip._internal.models.linkr   Zpip._internal.models.wheelr   Z$pip._internal.operations.build.wheelr   Z-pip._internal.operations.build.wheel_editabler   Z+pip._internal.operations.build.wheel_legacyr   Zpip._internal.req.req_installr   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.urlsr   Zpip._internal.vcsr   Ú	getLoggerÚ__name__r-   ÚcompileÚ
IGNORECASEr#   r"   ZBinaryAllowedPredicateZBuildResultrJ   r'   r3   r5   r6   r?   rB   r4   rR   r\   rZ   rg   rv   r%   r%   r%   r&   Ú<module>   s€    
	2 A