ó
Ð²Ebc           @   sÍ  d  Z  d d l m Z d d l m Z d d l Z d d l Z d d l Z d d l m Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z e j d d k r² d „  Z d	 „  Z n d
 „  Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d Z d „  Z d „  Z d „  Z d d „ Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ  d  „  Z! d! d" d# d$ d% h Z" d& „  Z# e$ d' k rÉe# ƒ  n  d S((   sg  This is invoked in a subprocess to call the build backend hooks.

It expects:
- Command line args: hook_name, control_dir
- Environment variables:
      PEP517_BUILD_BACKEND=entry.point:spec
      PEP517_BACKEND_PATH=paths (separated with os.pathsep)
- control_dir/input.json:
  - {"kwargs": {...}}

Results:
- control_dir/output.json
  - {"return_val": ...}
iÿÿÿÿ(   t   glob(   t   import_moduleN(   t   joini    i   c         K   s5   t  | d d d ƒ } t j |  | |  Wd  QXd  S(   Nt   wt   encodings   utf-8(   t   opent   jsont   dump(   t   objt   patht   kwargst   f(    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyt
   write_json!   s    c         C   s/   t  |  d d d ƒ } t j | ƒ SWd  QXd  S(   Nt   rR   s   utf-8(   R   R   t   load(   R	   R   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyt	   read_json%   s    c      
   K   s5   t  | d ƒ   } t j |  | d d | Wd  QXd  S(   Nt   wbR   s   utf-8(   R   R   R   (   R   R	   R
   R   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyR   +   s    c         C   s)   t  |  d ƒ  } t j | ƒ SWd  QXd  S(   Nt   rb(   R   R   R   (   R	   R   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyR   /   s    t   BackendUnavailablec           B   s   e  Z d  Z d „  Z RS(   s&   Raised if we cannot import the backendc         C   s   | |  _  d  S(   N(   t	   traceback(   t   selfR   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyt   __init__6   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyR   4   s   t   BackendInvalidc           B   s   e  Z d  Z d „  Z RS(   s    Raised if the backend is invalidc         C   s   | |  _  d  S(   N(   t   message(   R   R   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyR   <   s    (   R   R   R   R   (    (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyR   :   s   t   HookMissingc           B   s   e  Z d  Z RS(   sA   Raised if a hook is missing and we are not executing the fallback(   R   R   R   (    (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyR   @   s   c         C   sX   t  j j t  j j |  ƒ ƒ }  t  j j t  j j | ƒ ƒ } t  j j |  | g ƒ | k S(   s5   Test if a file is located within the given directory.(   t   osR	   t   normcaset   abspatht   commonprefix(   t   filenamet	   directory(    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyt   contained_inD   s    c             sÿ   t  j j d ƒ }  |  r: |  j t  j ƒ } | t j d *n  t  j d } | j d ƒ \ } } } y t | ƒ ‰  Wn# t	 k
 r” t
 t j ƒ  ƒ ‚ n X|  rÉ t ‡  f d †  | Dƒ ƒ sÉ t d ƒ ‚ qÉ n  | rû x) | j d ƒ D] } t ˆ  | ƒ ‰  qß Wn  ˆ  S(   s   Find and load the build backendt   PEP517_BACKEND_PATHi    t   PEP517_BUILD_BACKENDt   :c         3   s!   |  ] } t  ˆ  j | ƒ Vq d  S(   N(   R"   t   __file__(   t   .0R	   (   R   (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pys	   <genexpr>\   s   s(   Backend was not loaded from backend-patht   .(   R   t   environt   gett   splitt   pathsept   sysR	   t	   partitionR   t   ImportErrorR   R   t
   format_exct   anyR   t   getattr(   t   backend_patht   extra_pathitemst   ept   mod_patht   _t   obj_patht	   path_part(    (   R   s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyt   _build_backendK   s&    c         C   s9   t  ƒ  } y | j } Wn t k
 r* g  SX| |  ƒ Sd S(   sf   Invoke the optional get_requires_for_build_wheel hook

    Returns [] if the hook is not defined.
    N(   R:   t   get_requires_for_build_wheelt   AttributeError(   t   config_settingst   backendt   hook(    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyR;   g   s    	c         C   sZ   t  ƒ  } y | j } Wn0 t k
 rH | s8 t ƒ  ‚ n  t | |  | ƒ SX| |  | ƒ Sd S(   sÈ   Invoke optional prepare_metadata_for_build_wheel

    Implements a fallback by building a wheel if the hook isn't defined,
    unless _allow_fallback is False in which case HookMissing is raised.
    N(   R:   t    prepare_metadata_for_build_wheelR<   R   t   _get_wheel_metadata_from_wheel(   t   metadata_directoryR=   t   _allow_fallbackR>   R?   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyR@   u   s    		t   PEP517_ALREADY_BUILT_WHEELc         C   s_   g  } x< |  j  ƒ  D]. } t j d | ƒ } | r | j | ƒ q q W| rO | St d ƒ ‚ d S(   s6   Identify the .dist-info folder inside a wheel ZipFile.s   [^/\\]+-[^/\\]+\.dist-info/s#   No .dist-info folder found in wheelN(   t   namelistt   ret   matcht   appendt	   Exception(   t   whl_zipt   resR	   t   m(    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyt   _dist_info_files‹   s    c      
   C   s¨   d d l  m } |  j | | ƒ } t t j j | t ƒ d ƒ  Wd QXt j j | | ƒ } | | ƒ ) } t | ƒ } | j	 d | d | ƒ Wd QX| d j
 d ƒ d S(	   s   Build a wheel and extract the metadata from it.

    Fallback for when the build backend does not
    define the 'get_wheel_metadata' hook.
    iÿÿÿÿ(   t   ZipFileR   NR	   t   membersi    t   /(   t   zipfileRN   t   build_wheelR   R   R	   R   t   WHEEL_BUILT_MARKERRM   t
   extractallR+   (   R>   RB   R=   RN   t   whl_basenamet   whl_filet   zipft	   dist_info(    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyRA   —   s    c         C   sˆ   |  s
 d St j j |  ƒ } t j j t | t ƒ ƒ s; d St t j j | d ƒ ƒ } | se d GHd St	 | ƒ d k r€ d GHd S| d S(   sH   Check for a wheel already built during the get_wheel_metadata hook.
    s   *.whls+   Found wheel built marker, but no .whl filesi   sH   Found multiple .whl files; unspecified behaviour. Will call build_wheel.i    N(
   t   NoneR   R	   t   dirnamet   isfilet   pjoinRS   R    R   t   len(   RB   t   metadata_parentt	   whl_files(    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyt   _find_already_built_wheelª   s    c         C   sH   t  | ƒ } | r2 t j | |  ƒ t j j | ƒ St ƒ  j |  | | ƒ S(   s»   Invoke the mandatory build_wheel hook.

    If a wheel was already built in the
    prepare_metadata_for_build_wheel fallback, this
    will copy it rather than rebuilding the wheel.
    (   R`   t   shutilt   copy2R   R	   t   basenameR:   RR   (   t   wheel_directoryR=   RB   t   prebuilt_whl(    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyRR   À   s    c         C   s9   t  ƒ  } y | j } Wn t k
 r* g  SX| |  ƒ Sd S(   sf   Invoke the optional get_requires_for_build_wheel hook

    Returns [] if the hook is not defined.
    N(   R:   t   get_requires_for_build_sdistR<   (   R=   R>   R?   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyRf   Ð   s    	t   _DummyExceptionc           B   s   e  Z d  Z RS(   s(   Nothing should ever raise this exception(   R   R   R   (    (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyRg   Þ   s   t   GotUnsupportedOperationc           B   s   e  Z d  Z d „  Z RS(   s9   For internal use when backend raises UnsupportedOperationc         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyR   ä   s    (   R   R   R   R   (    (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyRh   â   s   c         C   sS   t  ƒ  } y | j |  | ƒ SWn/ t | d t ƒ k
 rN t t j ƒ  ƒ ‚ n Xd S(   s&   Invoke the mandatory build_sdist hook.t   UnsupportedOperationN(   R:   t   build_sdistR2   Rg   Rh   R   R0   (   t   sdist_directoryR=   R>   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyRj   è   s
    	R;   R@   RR   Rf   Rj   c          C   sf  t  t j ƒ d k  r% t j d ƒ n  t j d }  t j d } |  t k r_ t j d |  ƒ n  t ƒ  |  } t t | d ƒ ƒ } i t d 6d  d 6} y | | d	   | d <Wn– t
 k
 rÙ } t | d
 <| j | d <nm t k
 r} t | d <| j | d <nD t k
 r+} t | d <| j | d <n t k
 rEt | d <n Xt | t | d ƒ d d ƒd  S(   Ni   s"   Needs args: hook_name, control_diri   i   s   Unknown hook: %ss
   input.jsont   unsupportedt
   return_valR
   t
   no_backendR   t   backend_invalidt   backend_errort   hook_missings   output.jsont   indent(   R]   R-   t   argvt   exitt
   HOOK_NAMESt   globalsR   R\   t   FalseRY   R   t   TrueR   R   R   Rh   R   R   (   t	   hook_namet   control_dirR?   t
   hook_inputt   json_outt   e(    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyt   mainú   s.    


t   __main__(%   R   R    t	   importlibR   R   R   t   os.pathR   R\   RF   Ra   R-   R   t   version_infoR   R   RI   R   R   R   R"   R:   R;   R@   RS   RM   RA   R`   RY   RR   Rf   Rg   Rh   Rj   Ru   R~   R   (    (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_vendor/pep517/_in_process.pyt   <module>   sN   												
		