
'^c           @   s;  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m	 Z	 d d l
 m Z d d l m Z d d l m Z m Z m Z m Z m Z m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z m Z m  Z  m! Z! m" Z" m# Z# d d l$ m% Z% d d l& m' Z' d d l( m) Z) d d l* m+ Z+ e' rd d l, m- Z- m. Z. m/ Z/ m0 Z0 d d l1 m2 Z2 d d l
 m3 Z3 d d l4 m5 Z5 d d l6 m7 Z7 d d l8 m9 Z9 d d l: m; Z; d d l< m= Z= d d l m> Z> e	 rJe2 d i e- e? e. e? g e. e? f d 6e@ d 6d eA ZB qe2 d i e- e? e? g d f d 6e- e? e. e? g e. e? f d 6e@ d 6e@ d 6d eA ZB n  e jD eE  ZF d    ZG d!   ZH d"   ZI d d d#  ZJ d$   ZK d%   ZL d d d&  ZM d d d'  ZN d(   ZO d)   ZP d* eQ f d+     YZR d S(,   s)   Prepares a distribution for installation
iN(   t   requests(   t   PY2(   t)   make_distribution_for_install_requirement(   t   InstalledDistribution(   t   DirectoryUrlHashUnsupportedt   HashMismatcht   HashUnpinnedt   InstallationErrort   PreviousBuildDirErrort   VcsHashUnsupported(   t   copy2_fixed(   t   MissingHashes(   t
   indent_log(   t   write_delete_marker_file(   t   ask_path_existst
   backup_dirt   display_patht   hide_urlt   path_to_displayt   rmtree(   t   TempDirectory(   t   MYPY_CHECK_RUNNING(   t   unpack_file(   t   vcs(   t   Callablet   Listt   Optionalt   Tuple(   t	   TypedDict(   t   AbstractDistribution(   t   PackageFinder(   t   Link(   t
   Downloader(   t   InstallRequirement(   t   RequirementTracker(   t   Hashest   CopytreeKwargst   ignoret   symlinkst   totalt   copy_functiont   ignore_dangling_symlinksc         C   s6   t  |   } | j |    | j | |  Wd QX| S(   s-   Prepare a distribution for installation.
    N(   R   t   trackt   prepare_distribution_metadata(   t   reqt   req_trackert   findert   build_isolationt   abstract_dist(    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyt   _get_prepared_distributionT   s    	c         C   sD   t  j |  j  } | d  k	 s$ t  | j | d t |  j  d  S(   Nt   url(   R   t   get_backend_for_schemet   schemet   Nonet   AssertionErrort   unpackR   R2   (   t   linkt   locationt   vcs_backend(    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyt   unpack_vcs_linkc   s    c         C   s1  t  } t j j | | j  } t j j |  r t d j t |   d
  } | d k rc t	 } q | d k r t
 j d t |   t j |  q | d k r t |  } t
 j d t |  t |   t j | |  q | d k r t j d  q n  | r-t j |  |  t
 j d	 t |   n  d  S(   Ns8   The file {} exists. (i)gnore, (w)ipe, (b)ackup, (a)abortt   it   wt   bt   as   Deleting %ss   Backing up %s to %sis   Saved %s(   R<   R=   R>   R?   (   t   Truet   ost   patht   joint   filenamet   existsR   t   formatR   t   Falset   loggert   warningt   removeR   t   shutilt   movet   syst   exitt   copyt   info(   RD   R9   R8   RO   t   download_locationt   responset	   dest_file(    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyt
   _copy_filej   s0    			c   	      C   s   t  d d d t  } d  } | r6 t |  | |  } n  | rX | } t j |  d } n t |  | | j |  \ } } t | | |  | S(   Nt   kindR7   t   globally_managedi    (	   R   R@   R5   t   _check_download_dirt	   mimetypest
   guess_typet   _download_http_urlRB   R   (	   R8   R9   t
   downloadert   download_dirt   hashest   temp_dirt   already_downloaded_patht	   from_patht   content_type(    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyt   unpack_http_url   s    c         C   sV   y t  |  |  Wn> t j k
 rQ } t j d t |  t |   t |   n Xd S(   s   Copying special files is not supported, but as a convenience to users
    we skip errors copying them. This supports tools that may create e.g.
    socket files in the project source directory.
    s>   Ignoring special file error '%s' encountered copying %s to %s.N(   R
   RK   t   SpecialFileErrorRH   RI   t   strR   (   t   srct   destt   e(    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyt   _copy2_ignoring_special_files   s    		c            sN     f d   } t  d | d t  } t s7 t | d <n  t j   | |  d  S(   Nc            s   |    k r d d g Sg  S(   Ns   .toxs   .nox(    (   t   dt   names(   t   source(    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyR%      s    R%   R&   R(   (   t   dictR@   R   Rh   RK   t   copytree(   Rk   t   targetR%   t   kwargs(    (   Rk   s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyt   _copy_source_tree   s
    c         C   s   |  j  } |  j   rE t j j |  r4 t |  n  t | |  d Sd } | rf t |  | |  } n  | ru | } n | } | r | j	 |  n  t
 j |  d } t | | |  | S(   s   Unpack link into location.
    i    N(   t	   file_patht   is_existing_dirRA   RB   t   isdirR   Rp   R5   RW   t   check_against_pathRX   RY   R   (   R8   R9   R\   R]   t	   link_pathR_   R`   Ra   (    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyt   unpack_file_url   s$    			c         C   sV   |  j  r t |  |  d S|  j r9 t |  | | d | St |  | | | d | Sd S(   s_  Unpack link into location, downloading if required.

    :param hashes: A Hashes object, one of whose embedded hashes must match,
        or HashMismatch will be raised. If the Hashes is empty, no matches are
        required, and unhashable types of requirements (like VCS ones, which
        would ordinarily raise HashUnsupported) are allowed.
    R]   N(   t   is_vcsR;   R5   t   is_fileRv   Rb   (   R8   R9   R[   R\   R]   (    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyt
   unpack_url   s    		c         C   s   | |   } t  j j | | j  } t | d  ( } x | j D] } | j |  q@ WWd QX| rs | j |  n  | | j j	 j
 d d  f S(   s6   Download link url into temp_dir using provided sessiont   wbNs   content-typet    (   RA   RB   RC   RD   t   opent   chunkst   writeRt   RR   t   headerst   get(   R8   R[   R^   R]   t   downloadRq   t   content_filet   chunk(    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyRZ   #  s    c         C   s   t  j j | |  j  } t  j j |  s. d St j d |  | r y | j |  Wq t	 k
 r t j
 d |  t  j |  d SXn  | S(   s    Check download_dir for previously downloaded file with correct hash
        If a correct file is found return its path else None
    s   File was already downloaded %ss;   Previously-downloaded file %s has bad hash. Re-downloading.N(   RA   RB   RC   RD   RE   R5   RH   RP   Rt   R   RI   t   unlink(   R8   R\   R]   t   download_path(    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyRW   8  s    t   RequirementPreparerc           B   sA   e  Z d  Z d   Z e d    Z d   Z d   Z d   Z RS(   s   Prepares a Requirement
    c         C   sq   t  t |   j   | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 | |  _
 |	 |  _ |
 |  _ d  S(   N(   t   superR   t   __init__t   src_dirt	   build_dirR-   R[   R.   R\   t   wheel_download_dirR/   t   require_hashest   use_user_site(   t   selfR   R\   R   R   R/   R-   R[   R.   R   R   (    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyR   V  s    									c         C   sO   |  j  s t St j j |  j   r& t St j d  t d j	 |  j     d  S(   Ns!   Could not find download directorys0   Could not find or access download directory '{}'(
   R\   RG   RA   RB   RE   R@   RH   t   criticalR   RF   (   R   (    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyt   _download_should_save  s    	c   
      C   s  | j  s t  | j  } | j d k rI | j } t j d t |   n t j d | j p^ |  t   | j	 d k s t  | j |  j  t j j t j j | j	 d   r t d j | | j	    n  |  j r,| j r t    n | j   r	t    n  | j r,| j r,t    q,n  | j d |  j  } |  j r^| r^t   } n  |  j } | j r|  j r|  j } n  y% t  | | j	 |  j! | d | } WnD t" j# k
 r} t j$ d | |  t% d	 j | | |    n X| r| | _& n  | j r$| rt' } q*t( } n t' } | r@t) | j	  n  t* | |  j+ |  j, |  j-  }	 | r| j   rt j d
  q| rt j j t j j | | j.   rt/ | | |  qn  |  j0 r| j r| j1 |  j  qn  Wd QX|	 S(   sC   Prepare a requirement that would be obtained from req.link
        t   files   Processing %ss   Collecting %ss   setup.pys   pip can't proceed with requirements '{}' due to a pre-existing build directory ({}). This is likely due to a previous installation that failed. pip is being responsible and not assuming it can delete this. Please delete it and try again.t   trust_internetR]   s4   Could not install requirement %s because of error %ssD   Could not install requirement {} because of HTTP error {} for URL {}s*   Link is a directory, ignoring download_dirN(2   R8   R6   R4   Rq   RH   RP   R   R,   R   t
   source_dirR5   t   ensure_has_source_dirR   RA   RB   RE   RC   R   RF   R   Rw   R	   Rr   R   t   original_linkt	   is_pinnedR   R]   R   R\   t   is_wheelR   Ry   R[   R    t	   HTTPErrorR   R   t   local_file_pathR@   RG   R   R1   R-   R.   R/   RD   RT   R   t   archive(
   R   R,   R8   RB   R]   R\   t
   local_patht   exct   autodelete_unpackedR0   (    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyt   prepare_linked_requirement  sv    		
$								c      	   C   s   | j  s t d   t j d |  t    |  j rP t d j |    n  | j |  j	  | j
 |  j  t | |  j |  j |  j  } |  j r | j |  j  n  | j |  j  Wd QX| S(   s(   Prepare an editable requirement
        s-   cannot prepare a non-editable req as editables   Obtaining %sso   The editable requirement {} cannot be installed when requiring hashes, because there is no single file to hash.N(   t   editableR6   RH   RP   R   R   R   RF   R   R   t   update_editableR   R1   R-   R.   R/   R   R\   t   check_if_existsR   (   R   R,   R0   (    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyt   prepare_editable_requirement  s    
		c         C   s   | j  s t d   | d k	 s9 t d j | j     t j d | | | j  j  t   * |  j rx t j	 d  n  t
 |  } Wd QX| S(   s1   Prepare an already-installed requirement
        s(   req should have been satisfied but isn'tsA   did not get skip reason skipped but req.satisfied_by is set to {}s   Requirement %s: %s (%s)s   Since it is already installed, we are trusting this package without checking its hash. To ensure a completely repeatable environment, install into an empty virtualenv.N(   t   satisfied_byR6   R5   RF   RH   RP   t   versionR   R   t   debugR   (   R   R,   t   skip_reasonR0   (    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyt   prepare_installed_requirement4  s    
	
(	   t   __name__t
   __module__t   __doc__R   t   propertyR   R   R   R   (    (    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyR   R  s   	-		(S   R   t   loggingRX   RA   RK   RM   t   pip._vendorR    t   pip._vendor.sixR   t   pip._internal.distributionsR   t%   pip._internal.distributions.installedR   t   pip._internal.exceptionsR   R   R   R   R   R	   t   pip._internal.utils.filesystemR
   t   pip._internal.utils.hashesR   t   pip._internal.utils.loggingR   t    pip._internal.utils.marker_filesR   t   pip._internal.utils.miscR   R   R   R   R   R   t   pip._internal.utils.temp_dirR   t   pip._internal.utils.typingR   t   pip._internal.utils.unpackingR   t   pip._internal.vcsR   t   typingR   R   R   R   t   mypy_extensionsR   R   t"   pip._internal.index.package_finderR   t   pip._internal.models.linkR   t   pip._internal.network.downloadR    t   pip._internal.req.req_installR!   t   pip._internal.req.req_trackerR"   R#   Rd   t   boolRG   R$   R5   t	   getLoggerR   RH   R1   R;   RT   Rb   Rh   Rp   Rv   Ry   RZ   RW   t   objectR   (    (    (    s=   /tmp/pip-build-eiI0Wo/pip/pip/_internal/operations/prepare.pyt   <module>   sv   .."

			#		.		