ó
'—^c           @   s“  d  Z  d d l m Z d d l m 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 d d l 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   joint   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-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyt   __init__   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyR      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-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyR   %   s    (   R   R   R	   R   (    (    (    s;   /tmp/pip-build-eiI0Wo/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-eiI0Wo/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   ost   patht   normcaset   abspatht   commonprefix(   t   filenamet	   directory(    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyt   contained_in-   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   (   t   obj(    s;   /tmp/pip-build-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pys	   <genexpr>E   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-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyt   _build_backend4   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-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyR.   P   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_directoryR0   t   _allow_fallbackR1   R2   (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyR3   ^   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-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyt   _dist_info_filest   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   ZipFilet   wbNR   t   membersi    t   /(   t   zipfileRA   t   build_wheelt   openR   R   R   t   WHEEL_BUILT_MARKERR@   t
   extractallR   (   R1   R5   R0   RA   t   whl_basenamet   whl_filet   zipft	   dist_info(    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyR4   €   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   pjoinRH   R    R   t   len(   R5   t   metadata_parentt	   whl_files(    (    s;   /tmp/pip-build-eiI0Wo/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.
    (   RU   t   shutilt   copy2R   R   t   basenameR-   RF   (   t   wheel_directoryR0   R5   t   prebuilt_whl(    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyRF   ©   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/   (   R0   R1   R2   (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyR[   ¹   s    	t   _DummyExceptionc           B   s   e  Z d  Z RS(   s(   Nothing should ever raise this exception(   R   R   R	   (    (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyR\   Ç   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-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyR   Í   s    (   R   R   R	   R   (    (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyR]   Ë   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_sdistR%   R\   R]   R   R#   (   t   sdist_directoryR0   R1   (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyR_   Ñ   s
    	R.   R3   RF   R[   R_   c          C   sl  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 j 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
 rHt | d <n Xt j | t | d ƒ d d ƒd  S(   Ni   s"   Needs args: hook_name, control_diri   i   s   Unknown hook: %ss
   input.jsont   unsupportedt
   return_valt   kwargst
   no_backendR   t   backend_invalidt   backend_errort   hook_missings   output.jsont   indent(   RR   R    t   argvt   exitt
   HOOK_NAMESt   globalst   compatt	   read_jsonRQ   t   FalseRN   R   t   TrueR   R
   R   R]   R   t
   write_json(   t	   hook_namet   control_dirR2   t
   hook_inputt   json_outt   e(    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyt   mainã   s.    


t   __main__("   R	   R    t	   importlibR   R   t   os.pathR   RQ   R9   RV   R    R   Rm   R<   R   R
   R   R   R-   R.   R3   RH   R@   R4   RU   RN   RF   R[   R\   R]   R_   Rk   Rw   R   (    (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_vendor/pep517/_in_process.pyt   <module>   sD   									
		