a
    &(a                     @   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eZdd	 Zd
d Zdd Zdd Zd"ddZe 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  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.
    requiresbuild-backendz"Missing required fields: {missing})missingN)setformat
ValueError)systemrequiredmessage r   p/private/var/folders/m4/wm8f9dms7t78045sws6ggdl80000gn/T/pip-unpacked-wheel-vn48x2xj/pip/_vendor/pep517/build.pyvalidate_system   s    
r   c                 C   sL   t j| d}tj|dd}t|}W d   n1 s:0    Y  |d S )zC
    Load the build system from a source dir (pyproject.toml).
    zpyproject.tomlzutf-8)encodingNzbuild-system)ospathjoinioopenr   )
source_dir	pyprojectfZpyproject_datar   r   r   load_system   s    &r   c              	   C   sH   zt | }W n ttfy&   i }Y n0 |dd |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.
    r
   z 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 i t }t| |}|i }td| || td t p}td|| dj f i t }t| |}	|	|i }
tj	||
}t
|tj	|tj|
 W d    n1 s0    Y  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    




r6   c                 C   s   |p
t | }tj| |pd}t| t| t| |d |d}t ,}|	|d  t
|||| W d    n1 s|0    Y  d S )Nr.   r
   zbackend-pathr	   )r   r   r   r   r   r   r   getr   r(   r6   )r   r.   r/   r   r,   r-   r   r   r   r3   L   s    r3   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   sZ   t d ttd | js| js dnd | js.| js2dnd f}|D ]}t| j|| j q@d S )NzQpep517.build is deprecated. Consider switching to https://pypi.org/project/build/sdistr    )	r&   warninglistfilterr5   binaryr3   r   Zout_dir)argsdistsr.   r   r   r   mainp   s    
rC   __main__)NN)__doc__argparser   loggingr   r)   Zenvbuildr   wrappersr   Zdirtoolsr   r   compatr   r   	getLogger__name__r&   r   r   r#   r6   r3   ArgumentParserparseradd_argumentrC   
parse_argsr   r   r   r   <module>   sJ   



