
0c@_                 @   s   d  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 Z d d l	 m
 Z
 d d l m Z d d l m Z m Z e j e  Z d	 d
   Z Gd d   d e  Z d d d  Z d d d  Z d S)zIBuild wheels/sdists by installing build deps to a temporary environment.
    N)toml)
check_call)	get_paths)mkdtemp   )Pep517HookCallerLoggerWrapperc             C   s\   t  t j j |  d    } t j |  } Wd  QRX| d } | d | d | j d  f S)Nzpyproject.tomlzbuild-systemrequireszbuild-backendzbackend-path)openospathjoinr   loadget)
source_dirfZpyproject_dataZbuildsys r   :/tmp/pip-build-jynh7p1z/pip/pip/_vendor/pep517/envbuild.py_load_pyproject   s    
r   c               @   sO   e  Z d  Z d Z d Z d d d  Z d d   Z d d	   Z d
 d   Z d S)BuildEnvironmentzContext manager to install build deps in a simple temporary environment

    Based on code I wrote for pip, which is MIT licensed.
    NTc             C   s   | |  _  d  S)N)_cleanup)selfcleanupr   r   r   __init__9   s    zBuildEnvironment.__init__c             C   sR  t  d d  |  _ t j d |  j  t j j d d   |  _ t j j d d   |  _ t j	 d k rj d n d } t
 | d d	 |  j d
 |  j i } | d } |  j r | t j |  j t j d <n | t j t j t j d <| d | d k r| d } n | d t j | d } |  j rA| t j |  j t j d <n | t j d <|  S)Nprefixzpep517-build-env-zTemporary build environment: %sPATH
PYTHONPATHntposix_prefixvarsbaseplatbasescriptspurelibplatlib)r   r   loginfor   environr   	save_pathsave_pythonpathnamer   pathsepdefpath)r   Zinstall_schemeZinstall_dirsr"   Zlib_dirsr   r   r   	__enter__<   s*    		
		
zBuildEnvironment.__enter__c             C   sw   | s
 d St  j d |  t j d d d d d |  j g t |  } t | d t t  t j	  d	 t t  t j
  d S)
zAInstall dependencies into this env by calling pip in a subprocessNzCalling pip to install %sz-mpipinstallz--ignore-installedz--prefixstdoutstderr)r%   r&   sys
executabler   listr   r   loggingINFOERROR)r   reqscmdr   r   r   pip_install\   s    zBuildEnvironment.pip_installc             C   s   |  j  o* |  j d  k	 o* t j j |  j  } | rC t j |  j  |  j d  k rh t j j d d   n |  j t j d <|  j	 d  k r t j j d d   n |  j	 t j d <d  S)Nr   r   )
r   r   r   isdirshutilrmtreer(   r'   popr)   )r   exc_typeexc_valexc_tbZneeds_cleanupr   r   r   __exit__j   s    	zBuildEnvironment.__exit__)	__name__
__module____qualname____doc__r   r   r-   r:   rB   r   r   r   r   r      s    r   c       	   
   C   s   | d k r i  } t  |   \ } } } t |  | |  } t   @ } | j |  | j |  } | j |  | j | |  SWd QRXd S)am  Build a wheel from a source directory using PEP 517 hooks.

    :param str source_dir: Source directory containing pyproject.toml
    :param str wheel_dir: Target directory to create wheel in
    :param dict config_settings: Options to pass to build backend

    This is a blocking function which will run pip in a subprocess to install
    build requirements.
    N)r   r   r   r:   Zget_requires_for_build_wheelbuild_wheel)	r   	wheel_dirconfig_settingsr	   backendbackend_pathhooksenvr8   r   r   r   rG   ~   s    
rG   c       	   
   C   s   | d k r i  } t  |   \ } } } t |  | |  } t   @ } | j |  | j |  } | j |  | j | |  SWd QRXd S)am  Build an sdist from a source directory using PEP 517 hooks.

    :param str source_dir: Source directory containing pyproject.toml
    :param str sdist_dir: Target directory to place sdist in
    :param dict config_settings: Options to pass to build backend

    This is a blocking function which will run pip in a subprocess to install
    build requirements.
    N)r   r   r   r:   Zget_requires_for_build_sdistbuild_sdist)	r   Z	sdist_dirrI   r	   rJ   rK   rL   rM   r8   r   r   r   rN      s    
rN   )rF   r   r5   Zpip._vendorr   r<   
subprocessr   r2   	sysconfigr   tempfiler   Zwrappersr   r   	getLoggerrC   r%   r   objectr   rG   rN   r   r   r   r   <module>   s   a