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 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mZ dd	lmZ dd
lmZ ej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)ÚCalledProcessError)Úmkdtempé   )Úenable_colourful_output)ÚTOMLDecodeErrorÚ	toml_load)ÚBuildEnvironment)ÚPep517HookCallerc          0   C   s   t ƒ ��Ž}y|j|ƒ tjdƒ W n tk
r@   tjdƒ dS X y| ji ƒ}tjd|ƒ W n" tk
r~   tjddd� dS X y|j|ƒ tjdƒ W n tk
r¶   tjd	ƒ dS X tƒ }tjd
|ƒ zºy| j	|i ƒ}tjd|ƒ W n$ tk
�r   tjddd� dS X |j
dƒ�s*tjd|ƒ dS t||ƒ}t|ƒ�rLtjd|ƒ ntjd|ƒ dS tj|ƒ�rttjdƒ ntjdƒ dS W d tj|ƒ 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ÚlogÚinfor   ÚerrorZget_requires_for_build_sdistÚ	Exceptionr   Zbuild_sdistÚendswithÚpjoinr   ÚtarfileÚ
is_tarfileÚshutilÚrmtree)ÚhooksÚbuild_sys_requiresÚenvÚreqsÚtdÚfilenameÚpath© r   ú7/tmp/pip-build-red6nood/pip/pip/_vendor/pep517/check.pyÚcheck_build_sdist   sV    








r!   c          0   C   s   t ƒ ��Ž}y|j|ƒ tjdƒ W n tk
r@   tjdƒ dS X y| ji ƒ}tjd|ƒ W n" tk
r~   tjddd� dS X y|j|ƒ tjdƒ W n tk
r¶   tjd	ƒ dS X tƒ }tjd
|ƒ zºy| j	|i ƒ}tjd|ƒ W n$ tk
�r   tjddd� dS X |j
dƒ�s*tjd|ƒ dS t||ƒ}t|ƒ�rLtjd|ƒ ntjd|ƒ dS tj|ƒ�rttjdƒ ntjdƒ dS W d tj|ƒ 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   Zget_requires_for_build_wheelr   r   Zbuild_wheelr   r   r   ÚzipfileÚ
is_zipfiler   r   )r   r   r   r   r   r   r   r   r   r    Úcheck_build_wheelP   sT    








r$   c             C   sä   t | dƒ}t|ƒrtjdƒ ntjdƒ dS yPtj|dƒ�}t|ƒ}W d Q R X |d }|d }|d }|jd	ƒ}tjd
ƒ W n& t	t
fk
r¢   tjddd� dS X t| ||ƒ}t||ƒ}	t||ƒ}
|	sÒtjdƒ |
sàtjdƒ |	S )Nzpyproject.tomlzFound pyproject.tomlzMissing pyproject.tomlFÚrbzbuild-systemÚrequireszbuild-backendzbackend-pathzLoaded pyproject.tomlzInvalid pyproject.tomlT)r   z%Sdist checks failed; scroll up to seezWheel checks failed)r   r   r   r   r   ÚioÚopenr	   Úgetr   ÚKeyErrorr   r!   r$   Úwarning)Ú
source_dirZ	pyprojectÚfZpyproject_dataZbuildsysr&   ÚbackendZbackend_pathr   Zsdist_okZwheel_okr   r   r    Úcheckˆ   s0    






r/   c             C   sj   t jdƒ tjƒ }|jddd� |j| ƒ}tƒ  t|jƒ}|rNt	t
ddƒƒ nt	t
ddƒƒ tjd	ƒ d S )
NzQpep517.check is deprecated. Consider switching to https://pypi.org/project/build/r,   z%A directory containing pyproject.toml)ÚhelpzChecks passedÚgreenzChecks failedÚredr   )r   r+   ÚargparseÚArgumentParserÚadd_argumentÚ
parse_argsr   r/   r,   ÚprintÚansiÚsysÚexit)ÚargvZapÚargsÚokr   r   r    Úmainª   s    


r>   z[0mz[1mz[31mz[32m)ÚresetZboldr2   r1   c             C   s8   t jdkr,tjjƒ r,t| t| ƒ td  S t| ƒS d S )NÚntr?   )ÚosÚnamer9   ÚstdoutÚisattyÚ
ansi_codesÚstr)ÚsÚattrr   r   r    r8   Ç   s    r8   Ú__main__)N)#Ú__doc__r3   r'   ÚloggingrA   Úos.pathr   r   r   r   Ú
subprocessr   r9   r   Útempfiler   r"   Zcolorlogr   Úcompatr   r	   Zenvbuildr
   Zwrappersr   Ú	getLoggerÚ__name__r   r!   r$   r/   r>   rE   r8   r   r   r   r    Ú<module>   s6   
98"
