3
ûâde�  ã               @   s  d Z ddl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mZ ddlmZmZ ejeƒZdd	„ Zd
d„ Zdd„ Zdd„ Zd"dd„Zejƒ Zejddd� ejddddd� ejddddd� ejdddd� dd „ Zed!k�r eejƒ ƒ dS )#z%Build a project using PEP 517 hooks.
é    Né   )ÚBuildEnvironment)ÚPep517HookCaller)ÚtempdirÚmkdir_p)ÚFileNotFoundErrorÚ	toml_loadc             C   s4   ddh}|t | ƒks0dj|t | ƒ d�}t|ƒ‚dS )z7
    Ensure build system has the requisite fields.
    Úrequireszbuild-backendz"Missing required fields: {missing})ÚmissingN)ÚsetÚformatÚ
ValueError)ÚsystemÚrequiredÚmessage© r   ú7/tmp/pip-build-red6nood/pip/pip/_vendor/pep517/build.pyÚvalidate_system   s
    r   c          	   C   s6   t jj| dƒ}tj|dƒ�}t|ƒ}W dQ R X |d S )zC
    Load the build system from a source dir (pyproject.toml).
    zpyproject.tomlÚrbNzbuild-system)ÚosÚpathÚjoinÚioÚopenr   )Ú
source_dirZ	pyprojectÚfZpyproject_datar   r   r   Úload_system   s    r   c             C   sJ   yt | ƒ}W n ttfk
r(   i }Y nX |jddƒ |jdddgƒ |S )zÔ
    Given a source dir, attempt to get a build system backend
    and requirements from pyproject.toml. Fallback to
    setuptools but only if the file was not found or a build
    system was not indicated.
    zbuild-backendz setuptools.build_meta:__legacy__r	   Ú
setuptoolsÚwheel)r   r   ÚKeyErrorÚ
setdefault)r   r   r   r   r   Úcompat_system'   s    
r!   c             C   s²   dj f tƒ Ž}t| |ƒ}|i ƒ}tjd|ƒ |j|ƒ tjdƒ tƒ �b}tjd||ƒ dj f tƒ Ž}t| |ƒ}	|	|i ƒ}
tjj	||
ƒ}t
j|tjj	|tjj|
ƒƒƒ W d Q R X d S )Nzget_requires_for_build_{dist}zGot build requires: %sz$Installed dynamic build dependencieszTrying to build %s in %szbuild_{dist})r   ÚlocalsÚgetattrÚlogÚinfoÚpip_installr   r   r   r   ÚshutilÚmoveÚbasename)ÚhooksÚenvÚdistÚdestZget_requires_nameÚget_requiresÚreqsÚtdZ
build_nameÚbuildÚfilenameÚsourcer   r   r   Ú	_do_build:   s    




r4   c             C   sv   |p
t | ƒ}tjj| |pdƒ}t|ƒ t|ƒ t| |d |jdƒƒ}tƒ �"}|j	|d ƒ t
||||ƒ W d Q R X d S )Nr,   zbuild-backendzbackend-pathr	   )r   r   r   r   r   r   r   Úgetr   r&   r4   )r   r,   r-   r   r*   r+   r   r   r   r1   L   s    r1   r   z%A directory containing pyproject.toml)Úhelpz--binaryz-bÚ
store_trueF)ÚactionÚdefaultz--sourcez-sz	--out-dirz-oz>Destination in which to save the builds relative to source dirc             C   sb   t jdƒ ttd | js| j r"dnd | js2| j r6dnd fƒƒ}x|D ]}t| j|| jƒ qFW d S )NzQpep517.build is deprecated. Consider switching to https://pypi.org/project/build/Úsdistr   )	r$   ÚwarningÚlistÚfilterr3   Úbinaryr1   r   Zout_dir)ÚargsÚdistsr,   r   r   r   Úmainp   s    

rA   Ú__main__)NN)Ú__doc__Úargparser   Úloggingr   r'   Zenvbuildr   Zwrappersr   Zdirtoolsr   r   Úcompatr   r   Ú	getLoggerÚ__name__r$   r   r   r!   r4   r1   ÚArgumentParserÚparserÚadd_argumentrA   Ú
parse_argsr   r   r   r   Ú<module>   sB   



