ó
“àfac           @   s³  d  d l  Z  d  d l m Z d  d l Z d  d l m Z m Z m Z d  d l	 Z	 d  d l
 m Z m Z m Z d  d l Z d  d l m Z d d l m Z d d	 d
 d d d d g Z y d  d l j Z d „  Z Wn  e k
 rñ e d „  ƒ Z n Xe d „  ƒ Z d e f d „  ƒ  YZ d	 e f d „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d d d „ Z d d d „ Z  d „  Z! d e" f d „  ƒ  YZ# d e  j$ f d „  ƒ  YZ% d S(   iÿÿÿÿN(   t   contextmanager(   t   dirnamet   abspatht   join(   t
   check_callt   check_outputt   STDOUT(   t   mkdtempi   (   t   compatt   BackendUnavailablet   BackendInvalidt   HookMissingt   UnsupportedOperationt   default_subprocess_runnert   quiet_subprocess_runnert   Pep517HookCallerc           C   s   t  j t d ƒ S(   Ns   _in_process.py(   t	   resourcest   patht   __package__(    (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyt   _in_proc_script_path   s    c           c   s   t  t t t ƒ ƒ d ƒ Vd  S(   Ns   _in_process.py(   t   pjoinR   R   t   __file__(    (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyR      s    c          c   s'   t  ƒ  }  z	 |  VWd  t j |  ƒ Xd  S(   N(   R   t   shutilt   rmtree(   t   td(    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyt   tempdir!   s    		c           B   s   e  Z d  Z d „  Z RS(   sE   Will be raised if the backend cannot be imported in the hook process.c         C   s   | |  _  d  S(   N(   t	   traceback(   t   selfR   (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyt   __init__,   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyR	   *   s   c           B   s   e  Z d  Z d „  Z RS(   s)   Will be raised if the backend is invalid.c         C   s   | |  _  | |  _ | |  _ d  S(   N(   t   backend_namet   backend_patht   message(   R   R    R!   R"   (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyR   2   s    		(   R   R   R   R   (    (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyR
   0   s   c           B   s   e  Z d  Z d „  Z RS(   s    Will be raised on missing hooks.c         C   s#   t  t |  ƒ j | ƒ | |  _ d  S(   N(   t   superR   R   t	   hook_name(   R   R$   (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyR   :   s    (   R   R   R   R   (    (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyR   8   s   c           B   s   e  Z d  Z d „  Z RS(   sD   May be raised by build_sdist if the backend indicates that it can't.c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyR   A   s    (   R   R   R   R   (    (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyR   ?   s   c         C   s?   t  j j ƒ  } | r% | j | ƒ n  t |  d | d | ƒd S(   s5   The default method of calling the wrapper subprocess.t   cwdt   envN(   t   ost   environt   copyt   updateR   (   t   cmdR%   t   extra_environR&   (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyR   E   s    c         C   sE   t  j j ƒ  } | r% | j | ƒ n  t |  d | d | d t ƒd S(   sD   A method of calling the wrapper subprocess while suppressing output.R%   R&   t   stderrN(   R'   R(   R)   R*   R   R   (   R+   R%   R,   R&   (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyR   N   s    c         C   s©   t  j j | ƒ r! t d ƒ ‚ n  t  j j |  ƒ } t  j j t  j j | | ƒ ƒ } t  j j | ƒ } t  j j | ƒ } t  j j | | g ƒ | k r¥ t d ƒ ‚ n  | S(   sè   Normalise and check a backend path.

    Ensure that the requested backend path is specified as a relative path,
    and resolves to a location under the given source tree.

    Return an absolute version of the requested path.
    s   paths must be relatives    paths must be inside source tree(	   R'   R   t   isabst
   ValueErrorR   t   normpathR   t   normcaset   commonprefix(   t   source_treet	   requestedt
   abs_sourcet   abs_requestedt   norm_sourcet   norm_requested(    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyt   norm_and_checkW   s    !c           B   sz   e  Z d  Z d	 d	 d	 d „ Z e d „  ƒ Z d	 d „ Z d	 e d „ Z	 d	 d	 d „ Z
 d	 d „ Z d	 d „ Z d „  Z RS(
   sº  A wrapper around a source directory to be built with a PEP 517 backend.

    :param source_dir: The path to the source directory, containing
        pyproject.toml.
    :param build_backend: The build backend spec, as per PEP 517, from
        pyproject.toml.
    :param backend_path: The backend path, as per PEP 517, from pyproject.toml.
    :param runner: A callable that invokes the wrapper subprocess.
    :param python_executable: The Python executable used to invoke the backend

    The 'runner', if provided, must expect the following:

    - cmd: a list of strings representing the command and arguments to
      execute, as would be passed to e.g. 'subprocess.check_call'.
    - cwd: a string representing the working directory that must be
      used for the subprocess. Corresponds to the provided source_dir.
    - extra_environ: a dict mapping environment variable names to values
      which must be set for the subprocess execution.
    c         C   sŒ   | d  k r t } n  t | ƒ |  _ | |  _ | r[ g  | D] } t |  j | ƒ ^ q: } n  | |  _ | |  _ | s t j	 } n  | |  _
 d  S(   N(   t   NoneR   R   t
   source_dirt   build_backendR9   R!   t   _subprocess_runnert   syst
   executablet   python_executable(   R   R;   R<   R!   t   runnerR@   t   p(    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyR   ƒ   s    		(		c         c   s,   |  j  } | |  _  z	 d VWd | |  _  Xd S(   s\   A context manager for temporarily overriding the default subprocess
        runner.
        N(   R=   (   R   RA   t   prev(    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyt   subprocess_runnerš   s
    			c         C   s   |  j  d i | d 6ƒ S(   sI  Identify packages required for building a wheel

        Returns a list of dependency specifications, e.g.::

            ["wheel >= 0.25", "setuptools"]

        This does not include requirements specified in pyproject.toml.
        It returns the result of calling the equivalently named hook in a
        subprocess.
        t   get_requires_for_build_wheelt   config_settings(   t
   _call_hook(   R   RF   (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyRE   ¦   s    c         C   s+   |  j  d i t | ƒ d 6| d 6| d 6ƒ S(   su  Prepare a ``*.dist-info`` folder with metadata for this project.

        Returns the name of the newly created folder.

        If the build backend defines a hook with this name, it will be called
        in a subprocess. If not, the backend will be asked to build a wheel,
        and the dist-info extracted from that (unless _allow_fallback is
        False).
        t    prepare_metadata_for_build_wheelt   metadata_directoryRF   t   _allow_fallback(   RG   R   (   R   RI   RF   RJ   (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyRH   µ   s    c         C   sF   | d k	 r t | ƒ } n  |  j d i t | ƒ d 6| d 6| d 6ƒ S(   sv  Build a wheel from this project.

        Returns the name of the newly created file.

        In general, this will call the 'build_wheel' hook in the backend.
        However, if that was previously called by
        'prepare_metadata_for_build_wheel', and the same metadata_directory is
        used, the previously built wheel will be copied to wheel_directory.
        t   build_wheelt   wheel_directoryRF   RI   N(   R:   R   RG   (   R   RL   RF   RI   (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyRK   Ç   s    c         C   s   |  j  d i | d 6ƒ S(   s>  Identify packages required for building a wheel

        Returns a list of dependency specifications, e.g.::

            ["setuptools >= 26"]

        This does not include requirements specified in pyproject.toml.
        It returns the result of calling the equivalently named hook in a
        subprocess.
        t   get_requires_for_build_sdistRF   (   RG   (   R   RF   (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyRM   Û   s    c         C   s$   |  j  d i t | ƒ d 6| d 6ƒ S(   s£   Build an sdist from this project.

        Returns the name of the newly created file.

        This calls the 'build_sdist' backend hook in a subprocess.
        t   build_sdistt   sdist_directoryRF   (   RG   R   (   R   RO   RF   (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyRN   ê   s    c         C   sö  t  j d d k r( |  j j d ƒ } n	 |  j } i | d 6} |  j r” t j j |  j ƒ } t  j d d k r‡ | j t  j ƒ  ƒ } n  | | d <n  t	 ƒ  S} i | d 6} t
 j | t | d ƒ d d ƒt ƒ  D } |  j }	 |  j |	 t t | ƒ ƒ | | g d	 |  j d
 | ƒWd  QXt
 j t | d ƒ ƒ }
 |
 j d ƒ r]t |
 j d d ƒ ƒ ‚ n  |
 j d ƒ r‡t |
 j d d ƒ ƒ ‚ n  |
 j d ƒ rÆt d |  j d |  j d |
 j d d ƒ ƒ ‚ n  |
 j d ƒ rät | ƒ ‚ n  |
 d SWd  QXd  S(   Ni    i   t   ASCIIt   PEP517_BUILD_BACKENDt   PEP517_BACKEND_PATHt   kwargss
   input.jsont   indentR%   R,   s   output.jsont   unsupportedR   t    t
   no_backendt   backend_invalidR    R!   R"   t   backend_errort   hook_missingt
   return_val(   R>   t   version_infoR<   t   encodeR!   R'   t   pathsepR   t   getfilesystemencodingR   R   t
   write_jsonR   R   R@   R=   R   t   strR;   t	   read_jsont   getR   R	   R
   R   (   R   R$   RS   R<   R,   R!   R   t
   hook_inputt   scriptt   pythont   data(    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyRG   ö   s@    						N(   R   R   R   R:   R   R    RD   RE   t   TrueRH   RK   RM   RN   RG   (    (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyR   o   s   t   LoggerWrapperc           B   sA   e  Z d  Z d „  Z d „  Z e d „  ƒ Z d „  Z d „  Z RS(   sd   
    Read messages from a pipe and redirect them
    to a logger (see python's logging module).
    c         C   sf   t  j j |  ƒ t |  _ | |  _ | |  _ t j ƒ  \ |  _	 |  _
 t j |  j	 ƒ |  _ |  j ƒ  d  S(   N(   t	   threadingt   ThreadR   Rh   t   daemont   loggert   levelR'   t   pipet   fd_readt   fd_writet   fdopent   readert   start(   R   Rm   Rn   (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyR   .  s    			c         C   s   |  j  S(   N(   Rq   (   R   (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyt   fileno;  s    c         C   s   |  j  t j ƒ r |  d  S|  S(   Niÿÿÿÿ(   t   endswithR'   t   linesep(   t   msg(    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyt   remove_newline>  s    c         C   s.   x' |  j  D] } |  j |  j | ƒ ƒ q
 Wd  S(   N(   Rs   t   _writeRy   (   R   t   line(    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyt   runB  s    c         C   s   |  j  j |  j | ƒ d  S(   N(   Rm   t   logRn   (   R   R"   (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyRz   F  s    (	   R   R   R   R   Ru   t   staticmethodRy   R|   Rz   (    (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyRi   (  s   			(&   Rj   t
   contextlibR    R'   t   os.pathR   R   R   R   R   t
   subprocessR   R   R   R>   t   tempfileR   RV   R   t   __all__t   importlib.resourcesR   R   t   ImportErrorR   t	   ExceptionR	   R
   R   R   R:   R   R   R9   t   objectR   Rk   Ri   (    (    (    s:   /tmp/pip-install-YjPQSb/pip/pip/_vendor/pep517/wrappers.pyt   <module>   s<   					¹