ó
ä™L]c           @   sF  d  Z  d d l m Z d d l m 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 e f d „  ƒ  YZ 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 rBe ƒ  n  d S(   s$  This is invoked in a subprocess to call the build backend hooks.

It expects:
- Command line args: hook_name, control_dir
- Environment variable: PEP517_BUILD_BACKEND=entry.point:spec
- 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 RS(   s&   Raised if we cannot import the backend(   t   __name__t
   __module__t   __doc__(    (    (    s;   /tmp/pip-build-sZz8gW/pip/pip/_vendor/pep517/_in_process.pyR      s   c          C   s…   t  j d }  |  j d ƒ \ } } } y t | ƒ } Wn t k
 rN t ‚ n X| r� x) | j d ƒ D] } t | | ƒ } qe Wn  | S(   s   Find and load the build backendt   PEP517_BUILD_BACKENDt   :t   .(   t   ost   environt	   partitionR   t   ImportErrorR   t   splitt   getattr(   t   ept   mod_patht   _t   obj_patht   objt	   path_part(    (    s;   /tmp/pip-build-sZz8gW/pip/pip/_vendor/pep517/_in_process.pyt   _build_backend   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-sZz8gW/pip/pip/_vendor/pep517/_in_process.pyR   +   s    	c         C   sH   t  ƒ  } y | j } Wn t k
 r6 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.
    N(   R   t    prepare_metadata_for_build_wheelR   t   _get_wheel_metadata_from_wheel(   t   metadata_directoryR   R   R   (    (    s;   /tmp/pip-build-sZz8gW/pip/pip/_vendor/pep517/_in_process.pyR   9   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   rest   patht   m(    (    s;   /tmp/pip-build-sZz8gW/pip/pip/_vendor/pep517/_in_process.pyt   _dist_info_filesK   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   zipfileR*   t   build_wheelt   openR
   R'   R   t   WHEEL_BUILT_MARKERR)   t
   extractallR   (   R   R   R   R*   t   whl_basenamet   whl_filet   zipft	   dist_info(    (    s;   /tmp/pip-build-sZz8gW/pip/pip/_vendor/pep517/_in_process.pyR   W   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   pjoinR1   R    R   t   len(   R   t   metadata_parentt	   whl_files(    (    s;   /tmp/pip-build-sZz8gW/pip/pip/_vendor/pep517/_in_process.pyt   _find_already_built_wheelj   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   R/   (   t   wheel_directoryR   R   t   prebuilt_whl(    (    s;   /tmp/pip-build-sZz8gW/pip/pip/_vendor/pep517/_in_process.pyR/   €   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-sZz8gW/pip/pip/_vendor/pep517/_in_process.pyRD   �   s    	t   _DummyExceptionc           B   s   e  Z d  Z RS(   s(   Nothing should ever raise this exception(   R   R   R   (    (    (    s;   /tmp/pip-build-sZz8gW/pip/pip/_vendor/pep517/_in_process.pyRE   ž   s   t   GotUnsupportedOperationc           B   s   e  Z d  Z RS(   s9   For internal use when backend raises UnsupportedOperation(   R   R   R   (    (    (    s;   /tmp/pip-build-sZz8gW/pip/pip/_vendor/pep517/_in_process.pyRF   ¢   s   c         C   sG   t  ƒ  } y | j |  | ƒ SWn# t | d t ƒ k
 rB t ‚ n Xd S(   s&   Invoke the mandatory build_sdist hook.t   UnsupportedOperationN(   R   t   build_sdistR   RE   RF   (   t   sdist_directoryR   R   (    (    s;   /tmp/pip-build-sZz8gW/pip/pip/_vendor/pep517/_in_process.pyRH   ¦   s
    	R   R   R/   RD   RH   c          C   s  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 <Wn5 t k
 rÍ t | d
 <n t k
 rç 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_backends   output.jsont   indent(   R;   t   syst   argvt   exitt
   HOOK_NAMESt   globalst   compatt	   read_jsonR:   t   FalseR7   R   t   TrueRF   t
   write_json(   t	   hook_namet   control_dirR   t
   hook_inputt   json_out(    (    s;   /tmp/pip-build-sZz8gW/pip/pip/_vendor/pep517/_in_process.pyt   main¸   s     t   __main__(   R   R    t	   importlibR   R
   t   os.pathR   R:   R!   R?   RO   RT   R$   R   R   R   R   R1   R)   R   R>   R7   R/   RD   RE   RF   RH   RR   R]   R   (    (    (    s;   /tmp/pip-build-sZz8gW/pip/pip/_vendor/pep517/_in_process.pyt   <module>   s:   								
		