B
    ãUvg  ã               @   sì   d 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ZddlmZ ddlZddlZddlmZ ddlZddlmZ dd	lmZ dd
lmZ e e¡Zdd„ Zdd„ Zdd„ Zddd„Z dddddœZ!dd„ Z"edkrèe ƒ  dS )zHCheck a project and backend by attempting to build using PEP 517 hooks.
é    N)ÚisfileÚjoin)Ú	TomlErrorÚload)ÚCalledProcessError)Úmkdtempé   )Úenable_colourful_output)ÚBuildEnvironment)ÚPep517HookCallerc          
   C   sŒ  t ƒ z}y| | j¡ t d¡ W n tk
rB   t d¡ dS X y|  i ¡}t d|¡ W n   tjddd dS y| |¡ t d¡ W n tk
r®   t d	¡ dS X tƒ }t d
|¡ z®y|  	|i ¡}t d|¡ W n   tjddd dS | 
d¡st d|¡ dS t||ƒ}t|ƒr8t d|¡ nt d|¡ dS t |¡r`t d¡ nt d¡ dS W d t |¡ X dS Q R X d S )Nz#Installed static build dependenciesz+Failed to install static build dependenciesFzGot build requires: %sz'Failure in get_requires_for_build_sdistT)Úexc_infoz$Installed dynamic build dependenciesz,Failed to install dynamic build dependencieszTrying to build sdist in %szbuild_sdist returned %rzFailure in build_sdistz.tar.gzz*Filename %s doesn't have .tar.gz extensionzOutput file %s existszOutput file %s does not existzOutput file is a tar filezOutput file is not a tar file)r
   Úpip_installÚbuild_sys_requiresÚlogÚinfor   ÚerrorÚget_requires_for_build_sdistr   Úbuild_sdistÚendswithÚpjoinr   ÚtarfileÚ
is_tarfileÚshutilÚrmtree)ÚhooksÚenvÚreqsÚtdÚfilenameÚpath© r    ú9/tmp/pip-install-r_9ig3yj/pip/pip/_vendor/pep517/check.pyÚcheck_build_sdist   sT    







r"   c          
   C   sŒ  t ƒ z}y| | j¡ t d¡ W n tk
rB   t d¡ dS X y|  i ¡}t d|¡ W n   tjddd dS y| |¡ t d¡ W n tk
r®   t d	¡ dS X tƒ }t d
|¡ z®y|  	|i ¡}t d|¡ W n   tjddd dS | 
d¡st d|¡ dS t||ƒ}t|ƒr8t d|¡ nt d|¡ dS t |¡r`t d¡ nt d¡ dS W d t |¡ X dS Q R X d S )Nz#Installed static build dependenciesz+Failed to install static build dependenciesFzGot build requires: %sz'Failure in get_requires_for_build_sdistT)r   z$Installed dynamic build dependenciesz,Failed to install dynamic build dependencieszTrying to build wheel in %szbuild_wheel returned %rzFailure in build_wheelz.whlz'Filename %s doesn't have .whl extensionzOutput file %s existszOutput file %s does not existzOutput file is a zip filezOutput file is not a zip file)r
   r   r   r   r   r   r   Úget_requires_for_build_wheelr   Úbuild_wheelr   r   r   ÚzipfileÚ
is_zipfiler   r   )r   r   r   r   r   r   r    r    r!   Úcheck_build_wheelL   sT    







r'   c       
   	   C   sÐ   t | dƒ}t|ƒrt d¡ nt d¡ dS yBt|ƒ}t|ƒ}W d Q R X |d }|d }|d }t d¡ W n& ttfk
r”   tjd	d
d dS X t	| |ƒ}t
|ƒ}t|ƒ}	|s¾t d¡ |	sÌt d¡ |S )Nzpyproject.tomlzFound pyproject.tomlzMissing pyproject.tomlFzbuild-systemÚrequireszbuild-backendzLoaded pyproject.tomlzInvalid pyproject.tomlT)r   z%Sdist checks failed; scroll up to seezWheel checks failed)r   r   r   r   r   ÚopenÚ	toml_loadr   ÚKeyErrorr   r"   r'   Úwarning)
Ú
source_dirÚ	pyprojectÚfZpyproject_dataZbuildsysr(   Úbackendr   Zsdist_okZwheel_okr    r    r!   Úcheck„   s.    





r1   c             C   s`   t  ¡ }|jddd | | ¡}tƒ  t|jƒ}|rDttddƒƒ nttddƒƒ t	 
d¡ d S )	Nr-   z%A directory containing pyproject.toml)ÚhelpzChecks passedÚgreenzChecks failedÚredr   )ÚargparseÚArgumentParserÚadd_argumentÚ
parse_argsr	   r1   r-   ÚprintÚansiÚsysÚexit)ÚargvZapÚargsÚokr    r    r!   Úmain¥   s    

r@   z[0mz[1mz[31mz[32m)ÚresetZboldr4   r3   c             C   s8   t jdkr,tj ¡ r,t| t| ƒ td  S t| ƒS d S )NÚntrA   )ÚosÚnamer;   ÚstdoutÚisattyÚ
ansi_codesÚstr)ÚsÚattrr    r    r!   r:   »   s    r:   Ú__main__)N)#Ú__doc__r5   ÚloggingrC   Úos.pathr   r   r   Zpip._vendor.pytomlr   r   r*   r   Ú
subprocessr   r;   r   Útempfiler   r%   Zcolorlogr	   Zenvbuildr
   Úwrappersr   Ú	getLoggerÚ__name__r   r"   r'   r1   r@   rG   r:   r    r    r    r!   Ú<module>   s4   
78!
