ó
Ð²Ebc           @   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	 „  Z d
 e f d „  ƒ  YZ d d „ Z d d „ Z d S(   sI   Build wheels/sdists by installing build deps to a temporary environment.
iÿÿÿÿN(   t   toml(   t
   check_call(   t	   get_paths(   t   mkdtempi   (   t   Pep517HookCallert   LoggerWrapperc         C   s[   t  t j j |  d ƒ ƒ  } t j | ƒ } Wd  QX| d } | d | d | j d ƒ f S(   Ns   pyproject.tomls   build-systemt   requiress   build-backends   backend-path(   t   opent   ost   patht   joinR    t   loadt   get(   t
   source_dirt   ft   pyproject_datat   buildsys(    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/envbuild.pyt   _load_pyproject   s    
t   BuildEnvironmentc           B   s;   e  Z d  Z d Z e d „ Z d „  Z d „  Z d „  Z	 RS(   s‡   Context manager to install build deps in a simple temporary environment

    Based on code I wrote for pip, which is MIT licensed.
    c         C   s   | |  _  d  S(   N(   t   _cleanup(   t   selft   cleanup(    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/envbuild.pyt   __init__9   s    c         C   sT  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 i |  j d	 6|  j d
 6ƒ} | 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	 rC| t j |  j	 t j d <n | t j d <|  S(   Nt   prefixs   pep517-build-env-s   Temporary build environment: %st   PATHt
   PYTHONPATHt   ntt   posix_prefixt   varst   baset   platbaset   scriptst   purelibt   platlib(   R   R	   t   logt   infoR   t   environR   t   Nonet	   save_patht   save_pythonpatht   nameR   t   pathsept   defpath(   R   t   install_schemet   install_dirsR   t   lib_dirs(    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/envbuild.pyt	   __enter__<   s*    

		
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(
   sA   Install dependencies into this env by calling pip in a subprocessNs   Calling pip to install %ss   -mt   pipt   installs   --ignore-installeds   --prefixt   stdoutt   stderr(   R"   R#   t   syst
   executableR	   t   listR   R   t   loggingt   INFOt   ERROR(   R   t   reqst   cmd(    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/envbuild.pyt   pip_install\   s    c         C   s´   |  j  o* |  j d  k	 o* t j j |  j ƒ } | rF t j |  j ƒ n  |  j d  k rk 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%   R   t   isdirt   shutilt   rmtreeR&   R$   t   popR'   (   R   t   exc_typet   exc_valt   exc_tbt   needs_cleanup(    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/envbuild.pyt   __exit__j   s    	N(
   t   __name__t
   __module__t   __doc__R%   R	   t   TrueR   R.   R;   RD   (    (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/envbuild.pyR      s   	 	c   	      C   s‹   | d k r i  } n  t |  ƒ \ } } } t |  | | ƒ } t ƒ  @ } | j | ƒ | j | ƒ } | j | ƒ | j | | ƒ SWd QXd S(   sm  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   R;   t   get_requires_for_build_wheelt   build_wheel(	   R   t	   wheel_dirt   config_settingsR   t   backendt   backend_patht   hookst   envR9   (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/envbuild.pyRJ   ~   s    
	c   	      C   s‹   | d k r i  } n  t |  ƒ \ } } } t |  | | ƒ } t ƒ  @ } | j | ƒ | j | ƒ } | j | ƒ | j | | ƒ SWd QXd S(   sm  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   R;   t   get_requires_for_build_sdistt   build_sdist(	   R   t	   sdist_dirRL   R   RM   RN   RO   RP   R9   (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/envbuild.pyRR   ”   s    
	(   RG   R   R6   t   pip._vendorR    R=   t
   subprocessR   R3   t	   sysconfigR   t   tempfileR   t   wrappersR   R   t	   getLoggerRE   R"   R   t   objectR   R%   RJ   RR   (    (    (    s8   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/envbuild.pyt   <module>   s   	a