a
    Ç&(aÐ  ã                   @   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 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              
   C   sH  t ƒ *}z| |¡ t d¡ W n* tyL   t d¡ Y W d   ƒ dS 0 z|  i ¡}t d|¡ W n. ty–   tjddd Y W d   ƒ dS 0 z| |¡ t d¡ W n* tyÚ   t d	¡ Y W d   ƒ dS 0 tƒ }t d
|¡ z$z|  	|i ¡}t d|¡ W n< tyJ   tjddd Y W t
 |¡ W d   ƒ dS 0 | d¡s€t d|¡ W t
 |¡ W d   ƒ dS t||ƒ}t|ƒr¢t d|¡ n(t d|¡ W t
 |¡ W d   ƒ dS t |¡rât d¡ n&t d¡ W t
 |¡ W d   ƒ dS W t
 |¡ nt
 |¡ 0 W d   ƒ dS 1 s:0    Y  d S )Nú#Installed static build dependenciesú+Failed to install static build dependenciesFúGot build requires: %sú'Failure in get_requires_for_build_sdistT©Úexc_infoú$Installed dynamic build dependenciesú,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 extensionúOutput file %s existsúOutput file %s does not existzOutput file is a tar filezOutput file is not a tar file)r
   Úpip_installÚlogÚinfor   ÚerrorÚget_requires_for_build_sdistÚ	Exceptionr   Úbuild_sdistÚshutilÚrmtreeÚendswithÚpjoinr   ÚtarfileÚ
is_tarfile©ÚhooksZbuild_sys_requiresÚenvÚreqsÚtdÚfilenameÚpath© r*   úp/private/var/folders/m4/wm8f9dms7t78045sws6ggdl80000gn/T/pip-unpacked-wheel-vn48x2xj/pip/_vendor/pep517/check.pyÚcheck_build_sdist   sh    






ëÿ
ð

	
÷

ýr,   c              
   C   sH  t ƒ *}z| |¡ t d¡ W n* tyL   t d¡ Y W d   ƒ dS 0 z|  i ¡}t d|¡ W n. ty–   tjddd Y W d   ƒ dS 0 z| |¡ t d¡ W n* tyÚ   t d	¡ Y W d   ƒ dS 0 tƒ }t d
|¡ z$z|  	|i ¡}t d|¡ W n< tyJ   tjddd Y W t
 |¡ W d   ƒ dS 0 | d¡s€t d|¡ W t
 |¡ W d   ƒ dS t||ƒ}t|ƒr¢t d|¡ n(t d|¡ W t
 |¡ W d   ƒ dS t |¡rât d¡ n&t d¡ W t
 |¡ W d   ƒ dS W t
 |¡ nt
 |¡ 0 W d   ƒ dS 1 s:0    Y  d S )Nr   r   Fr   r   Tr   r   r   zTrying to build wheel in %szbuild_wheel returned %rzFailure in build_wheelz.whlz'Filename %s doesn't have .whl extensionr   r   zOutput file is a zip filezOutput file is not a zip file)r
   r   r   r   r   r   Úget_requires_for_build_wheelr   r   Úbuild_wheelr   r   r   r    r   ÚzipfileÚ
is_zipfiler#   r*   r*   r+   Úcheck_build_wheelP   sd    






ì
ð

	
÷

ýr1   c              	   C   sú   t | dƒ}t|ƒrt d¡ nt d¡ dS zftj|dd}t|ƒ}W d   ƒ n1 sZ0    Y  |d }|d }|d	 }| d
¡}t d¡ W n& t	t
fy¸   tjddd Y dS 0 t| ||ƒ}t||ƒ}	t||ƒ}
|	sèt d¡ |
söt d¡ |	S )Nzpyproject.tomlzFound pyproject.tomlzMissing pyproject.tomlFzutf-8)Úencodingzbuild-systemÚrequireszbuild-backendzbackend-pathzLoaded pyproject.tomlzInvalid pyproject.tomlTr   z%Sdist checks failed; scroll up to seezWheel checks failed)r    r   r   r   r   ÚioÚopenr	   Úgetr   ÚKeyErrorr   r,   r1   Úwarning)Ú
source_dirÚ	pyprojectÚfZpyproject_dataZbuildsysr3   ÚbackendÚbackend_pathr$   Zsdist_okZwheel_okr*   r*   r+   Úcheckˆ   s0    

&




r>   c                 C   sj   t  d¡ t ¡ }|jddd | | ¡}tƒ  t|jƒ}|rNt	t
ddƒƒ nt	t
ddƒƒ t d	¡ d S )
NzQpep517.check is deprecated. Consider switching to https://pypi.org/project/build/r9   z%A directory containing pyproject.toml)ÚhelpzChecks passedÚgreenzChecks failedÚredr   )r   r8   ÚargparseÚArgumentParserÚadd_argumentÚ
parse_argsr   r>   r9   ÚprintÚansiÚsysÚexit)ÚargvZapÚargsÚokr*   r*   r+   Úmainª   s    
þ

rM   z[0mz[1mz[31mz[32m)ÚresetZboldrA   r@   c                 C   s8   t jdkr,tj ¡ r,t| t| ƒ td  S t| ƒS d S )NÚntrN   )ÚosÚnamerH   ÚstdoutÚisattyÚ
ansi_codesÚstr)ÚsÚattrr*   r*   r+   rG   Ç   s    rG   Ú__main__)N)#Ú__doc__rB   r4   ÚloggingrP   Úos.pathr   r   r    r   Ú
subprocessr   rH   r!   Útempfiler   r/   Zcolorlogr   Úcompatr   r	   Zenvbuildr
   Úwrappersr   Ú	getLoggerÚ__name__r   r,   r1   r>   rM   rT   rG   r*   r*   r*   r+   Ú<module>   s8   
98"
ü