B
    ãUvgš  ã               @   sž   d dl mZ d dlZd dlmZmZmZ d dlZd dl	m
Z
 d dlZd dlmZ ddlmZ eeeeƒƒdƒZed	d
„ ƒZG dd„ deƒZG dd„ deƒZdS )é    )ÚcontextmanagerN)ÚdirnameÚabspathÚjoin)Ú
check_call)Úmkdtempé   )Úcompatz_in_process.pyc           	   c   s"   t ƒ } z
| V  W d t | ¡ X d S )N)r   ÚshutilÚrmtree)Útd© r   ú</tmp/pip-install-r_9ig3yj/pip/pip/_vendor/pep517/wrappers.pyÚtempdir   s    
r   c               @   s   e Zd ZdZdS )ÚUnsupportedOperationzDMay be raised by build_sdist if the backend indicates that it can't.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r      s   r   c               @   sR   e Zd ZdZdd„ Zddd„Zddd„Zdd	d
„Zddd„Zddd„Z	dd„ Z
dS )ÚPep517HookCallerzæA wrapper around a source directory to be built with a PEP 517 backend.

    source_dir : The path to the source directory, containing pyproject.toml.
    backend : The build backend spec, as per PEP 517, from pyproject.toml.
    c             C   s   t |ƒ| _|| _d S )N)r   Ú
source_dirÚbuild_backend)Úselfr   r   r   r   r   Ú__init__   s    
zPep517HookCaller.__init__Nc             C   s   |   dd|i¡S )aG  Identify packages required for building a wheel

        Returns a list of dependency specifications, e.g.:
            ["wheel >= 0.25", "setuptools"]

        This does not include requirements specified in pyproject.toml.
        It returns the result of calling the equivalently named hook in a
        subprocess.
        Úget_requires_for_build_wheelÚconfig_settings)Ú
_call_hook)r   r   r   r   r   r   "   s    
z-Pep517HookCaller.get_requires_for_build_wheelc             C   s   |   dt|ƒ|dœ¡S )aG  Prepare a *.dist-info folder with metadata for this project.

        Returns the name of the newly created folder.

        If the build backend defines a hook with this name, it will be called
        in a subprocess. If not, the backend will be asked to build a wheel,
        and the dist-info extracted from that.
        Ú prepare_metadata_for_build_wheel)Úmetadata_directoryr   )r   r   )r   r   r   r   r   r   r   0   s    	z1Pep517HookCaller.prepare_metadata_for_build_wheelc             C   s(   |dk	rt |ƒ}|  dt |ƒ||dœ¡S )av  Build a wheel from this project.

        Returns the name of the newly created file.

        In general, this will call the 'build_wheel' hook in the backend.
        However, if that was previously called by
        'prepare_metadata_for_build_wheel', and the same metadata_directory is
        used, the previously built wheel will be copied to wheel_directory.
        NÚbuild_wheel)Úwheel_directoryr   r   )r   r   )r   r    r   r   r   r   r   r   >   s    
zPep517HookCaller.build_wheelc             C   s   |   dd|i¡S )a<  Identify packages required for building a wheel

        Returns a list of dependency specifications, e.g.:
            ["setuptools >= 26"]

        This does not include requirements specified in pyproject.toml.
        It returns the result of calling the equivalently named hook in a
        subprocess.
        Úget_requires_for_build_sdistr   )r   )r   r   r   r   r   r!   P   s    
z-Pep517HookCaller.get_requires_for_build_sdistc             C   s   |   dt|ƒ|dœ¡S )z£Build an sdist from this project.

        Returns the name of the newly created file.

        This calls the 'build_sdist' backend hook in a subprocess.
        Úbuild_sdist)Úsdist_directoryr   )r   r   )r   r#   r   r   r   r   r"   ^   s    zPep517HookCaller.build_sdistc          	   C   s    t j ¡ }tjd dkr&| j d¡}n| j}||d< tƒ \}tj	d|it
|dƒdd ttjt||g| j|d t t
|d	ƒ¡}| d
¡rŽt‚|d S Q R X d S )Nr   é   ÚASCIIÚPEP517_BUILD_BACKENDÚkwargsz
input.json)Úindent)ÚcwdÚenvzoutput.jsonÚunsupportedÚ
return_val)ÚosÚenvironÚcopyÚsysÚversion_infor   Úencoder   r	   Ú
write_jsonÚpjoinr   Ú
executableÚ_in_proc_scriptr   Ú	read_jsonÚgetr   )r   Ú	hook_namer'   r*   r   r   Údatar   r   r   r   k   s    

zPep517HookCaller._call_hook)N)N)NN)N)N)r   r   r   r   r   r   r   r   r!   r"   r   r   r   r   r   r      s   




r   )Ú
contextlibr   r-   Úos.pathr   r   r   r4   r
   Ú
subprocessr   r0   Útempfiler   Ú r	   Ú__file__r6   r   Ú	Exceptionr   Úobjectr   r   r   r   r   Ú<module>   s   