B
    Kkd                 @   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dd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-gxxfd9b7/pip/pip/_vendor/pep517/wrappers.pytempdir   s    
r   c               @   s   e Zd ZdZdS )BackendUnavailablezEWill be raised if the backend cannot be imported in the hook process.N)__name__
__module____qualname____doc__r   r   r   r   r      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)r   r   r   r   r   r   r   r   r      s   r   c             C   s*   t j }|r|| t| ||d dS )z5The default method of calling the wrapper subprocess.)cwdenvN)osenvironcopyupdater   )cmdr   extra_environr   r   r   r   default_subprocess_runner   s    

r   c               @   s^   e Zd ZdZdd Ze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 )Pep517HookCallerzA 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 || _|| _t| _d S )N)r   
source_dirbuild_backendr   _subprocess_runner)selfr    r!   r   r   r   __init__.   s    
zPep517HookCaller.__init__c             c   s   | j }|| _ d V  || _ d S )N)r"   )r#   runnerprevr   r   r   subprocess_runner5   s    z"Pep517HookCaller.subprocess_runnerNc             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+   J   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-   Y   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/   m   s    
z-Pep517HookCaller.get_requires_for_build_sdistc             C   s   |  dt||dS )zBuild 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#   r1   r)   r   r   r   r0   {   s    zPep517HookCaller.build_sdistc          	   C   s   t jd dkr| jd}n| j}t p}tjd|it|ddd | jt j	t
||g| jd|id tt|d	}|d
rt|drt|d S Q R X d S )Nr      ASCIIkwargsz
input.json)indentPEP517_BUILD_BACKEND)r   r   zoutput.jsonunsupported
no_backend
return_val)sysversion_infor!   encoder   r	   
write_jsonpjoinr"   
executable_in_proc_scriptr    	read_jsongetr   r   )r#   	hook_namer4   r!   r   datar   r   r   r*      s     

zPep517HookCaller._call_hook)N)N)NN)N)N)r   r   r   r   r$   r   r'   r(   r+   r-   r/   r0   r*   r   r   r   r   r   (   s   

 


r   )NN)
contextlibr   r   os.pathr   r   r   r>   r
   
subprocessr   r:   tempfiler    r	   __file__r@   r   	Exceptionr   r   r   objectr   r   r   r   r   <module>   s   	
	