ó
b]c           @@  s´  d  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 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 d d l m Z e r+d d	 l m Z m Z m Z m Z m Z m Z m Z m Z m  Z  d d
 l! m" Z" e e e# e e# f Z$ n  d g Z% e j& e' ƒ Z( d d „ Z* d e+ f d „  ƒ  YZ, d e- f d „  ƒ  YZ. d e- f d „  ƒ  YZ/ e/ ƒ  Z0 d e- f d „  ƒ  YZ1 d S(   s)   Handles all VCS (version control) supporti    (   t   absolute_importN(   t   pkg_resources(   t   parse(   t
   BadCommand(   t   ask_path_existst
   backup_dirt   call_subprocesst   display_patht   rmtree(   t   MYPY_CHECK_RUNNING(	   t   Anyt   Dictt   Iterablet   Listt   Mappingt   Optionalt   Textt   Tuplet   Type(   t   SpinnerInterfacet   vcsc         C@  sD   t  j | ƒ } d j |  | | ƒ } | r@ | d j | ƒ 7} n  | S(   sº   
    Return the URL for a VCS requirement.

    Args:
      repo_url: the remote VCS url, with any needed VCS prefix (e.g. "git+").
      project_name: the (unescaped) project name.
    s   {}@{}#egg={}s   &subdirectory={}(   R   t   to_filenamet   format(   t   repo_urlt   revt   project_namet   subdirt   egg_project_namet   req(    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   make_vcs_requirement_url!   s
    t   RemoteNotFoundErrorc           B@  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyR   1   s   t
   RevOptionsc           B@  sP   e  Z d  Z d d d „ Z d „  Z e d „  ƒ Z d „  Z d „  Z	 d „  Z
 RS(   s¢   
    Encapsulates a VCS-specific revision to install, along with any VCS
    install options.

    Instances of this class should be treated as if immutable.
    c         C@  s4   | d k r g  } n  | |  _ | |  _ | |  _ d S(   s©   
        Args:
          vc_class: a VersionControl subclass.
          rev: the name of the revision to install.
          extra_args: a list of extra options.
        N(   t   Nonet
   extra_argsR   t   vc_class(   t   selfR$   R   R#   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   __init__>   s
    			c         C@  s   d j  |  j j |  j ƒ S(   Ns   <RevOptions {}: rev={!r}>(   R   R$   t   nameR   (   R%   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   __repr__R   s    c         C@  s    |  j  d  k r |  j j S|  j  S(   N(   R   R"   R$   t   default_arg_rev(   R%   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   arg_revU   s    
c         C@  sE   g  } |  j  } | d k	 r4 | |  j j | ƒ 7} n  | |  j 7} | S(   s<   
        Return the VCS-specific command arguments.
        N(   R*   R"   R$   t   get_base_rev_argsR#   (   R%   t   argsR   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   to_args]   s    	c         C@  s   |  j  s d Sd j |  j  ƒ S(   Nt    s    (to revision {})(   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt
   to_displayj   s    	c         C@  s   |  j  j | d |  j ƒS(   s•   
        Make a copy of the current instance, but with a new rev.

        Args:
          rev: the name of the revision for the new object.
        R#   (   R$   t   make_rev_optionsR#   (   R%   R   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   make_newq   s    N(   R   R    t   __doc__R"   R&   R(   t   propertyR*   R-   R/   R1   (    (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyR!   5   s   			t
   VcsSupportc           B@  s‰   e  Z i  Z d  d d d d d g Z d „  Z d „  Z e d „  ƒ Z e d	 „  ƒ Z e d
 „  ƒ Z	 d „  Z
 d „  Z d „  Z d „  Z RS(   t   ssht   gitt   hgt   bzrt   sftpt   svnc         C@  sR   t  j j |  j ƒ t t  d d  ƒ r; t  j j |  j ƒ n  t t |  ƒ j	 ƒ  d  S(   Nt   uses_fragment(
   t   urllib_parset   uses_netloct   extendt   schemest   getattrR"   R;   t   superR4   R&   (   R%   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyR&   €   s    c         C@  s   |  j  j ƒ  S(   N(   t	   _registryt   __iter__(   R%   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyRC   Š   s    c         C@  s   t  |  j j ƒ  ƒ S(   N(   t   listRB   t   values(   R%   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   backends   s    c         C@  s   g  |  j  D] } | j ^ q
 S(   N(   RF   t   dirname(   R%   t   backend(    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   dirnames’   s    c         C@  s.   g  } x! |  j  D] } | j | j ƒ q W| S(   N(   RF   R>   R?   (   R%   R?   RH   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   all_schemes—   s    c         C@  se   t  | d ƒ s& t j d | j ƒ d  S| j |  j k ra | ƒ  |  j | j <t j d | j ƒ n  d  S(   NR'   s   Cannot register VCS %ss   Registered VCS backend: %s(   t   hasattrt   loggert   warningR   R'   RB   t   debug(   R%   t   cls(    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   registerŸ   s    c         C@  s    | |  j  k r |  j  | =n  d  S(   N(   RB   (   R%   R'   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt
   unregister¨   s    c         C@  sG   x@ |  j  j ƒ  D]/ } | j | ƒ r t j d | | j ƒ | Sq Wd S(   sv   
        Return a VersionControl object if a repository of that type is found
        at the given directory.
        s   Determine that %s uses VCS: %sN(   RB   RE   t   controls_locationRL   RN   R'   R"   (   R%   t   locationt   vcs_backend(    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   get_backend_for_dir­   s    	c         C@  s   | j  ƒ  } |  j j | ƒ S(   s9   
        Return a VersionControl object or None.
        (   t   lowerRB   t   get(   R%   R'   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   get_backendº   s    (   R   R    RB   R?   R&   RC   R3   RF   RI   RJ   RP   RQ   RU   RX   (    (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyR4   |   s   	
					t   VersionControlc        	   B@  s”  e  Z d  Z d  Z d  Z d Z d Z d Z e	 d „  ƒ Z
 e	 d „  ƒ Z e	 d „  ƒ Z e	 d „  ƒ Z e d „  ƒ Z e	 d d d „ ƒ Z e	 d „  ƒ Z d „  Z e	 d	 „  ƒ Z e	 d
 „  ƒ Z e d „  ƒ Z d „  Z e d „  ƒ Z e	 d „  ƒ Z d „  Z d „  Z d „  Z e	 d „  ƒ Z d „  Z d „  Z e	 d „  ƒ Z e	 d „  ƒ Z  e	 e! d d d d d d d „ ƒ Z" e	 d „  ƒ Z# e	 d „  ƒ Z$ RS(   R.   c         C@  s    | j  ƒ  j d j |  j ƒ ƒ S(   sŽ   
        Return whether the vcs prefix (e.g. "git+") should be added to a
        repository's remote url when used in a requirement.
        s   {}:(   RV   t
   startswithR   R'   (   RO   t
   remote_url(    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   should_add_vcs_url_prefixÐ   s    c         C@  s   d S(   sI   
        Return the path to setup.py, relative to the repo root.
        N(   R"   (   RO   t   repo_dir(    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   get_subdirectoryØ   s    c         C@  s   |  j  | ƒ S(   sR   
        Return the revision string that should be used in a requirement.
        (   t   get_revision(   RO   R]   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   get_requirement_revisionß   s    c         C@  s€   |  j  | ƒ } | d k r d S|  j | ƒ rF d j |  j | ƒ } n  |  j | ƒ } |  j | ƒ } t | | | d | ƒ} | S(   sC  
        Return the requirement string to use to redownload the files
        currently at the given repository directory.

        Args:
          project_name: the (unescaped) project name.

        The return value has a form similar to the following:

            {repository_url}@{revision}#egg={project_name}
        s   {}+{}R   N(   t   get_remote_urlR"   R\   R   R'   R`   R^   R   (   RO   R]   R   R   t   revisionR   R   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   get_src_requirementæ   s    	c         C@  s
   t  ‚ d S(   s™   
        Return the base revision arguments for a vcs command.

        Args:
          rev: the name of a revision to install.  Cannot be None.
        N(   t   NotImplementedError(   R   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyR+     s    c         C@  s   t  |  | d | ƒS(   s   
        Return a RevOptions object.

        Args:
          rev: the name of a revision to install.
          extra_args: a list of extra options.
        R#   (   R!   (   RO   R   R#   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyR0     s    
c         C@  s7   t  j j | ƒ \ } } | j t  j j ƒ p6 t | ƒ S(   sy   
           posix absolute paths start with os.path.sep,
           win32 ones start with drive (like c:\folder)
        (   t   ost   patht
   splitdriveRZ   t   sept   bool(   RO   t   repot   drivet   tail(    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   _is_local_repository  s    c         C@  s
   t  ‚ d S(   sÑ   
        Export the repository at the url to the destination location
        i.e. only download the files, without vcs informations

        :param url: the repository URL starting with a vcs prefix.
        N(   Rd   (   R%   RS   t   url(    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   export!  s    c         C@  s
   | d f S(   sZ  
        Parse the repository URL's netloc, and return the new netloc to use
        along with auth information.

        Args:
          netloc: the original repository URL netloc.
          scheme: the repository URL's scheme without the vcs prefix.

        This is mainly for the Subversion class to override, so that auth
        information can be provided via the --username and --password options
        instead of through the URL.  For other subclasses like Git without
        such an option, auth information must stay in the URL.

        Returns: (netloc, (username, password)).
        N(   NN(   R"   (   RO   t   netloct   scheme(    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   get_netloc_and_auth*  s    c   	      C@  sÈ   t  j | ƒ \ } } } } } d | k rB t d j | ƒ ƒ ‚ n  | j d d ƒ d } |  j | | ƒ \ } } d } d | k r | j d d ƒ \ } } n  t  j | | | | d f ƒ } | | | f S(   s¢   
        Parse the repository URL to use, and return the URL, revision,
        and auth info to use.

        Returns: (url, rev, (username, password)).
        t   +sv   Sorry, {!r} is a malformed VCS url. The format is <vcs>+<protocol>://<url>, e.g. svn+http://myrepo/svn/MyApp#egg=MyAppi   t   @R.   N(	   R<   t   urlsplitt
   ValueErrorR   t   splitRr   R"   t   rsplitt
   urlunsplit(	   RO   Rn   Rq   Rp   Rf   t   queryt   fragt	   user_passR   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   get_url_rev_and_auth=  s    	c         C@  s   g  S(   sM   
        Return the RevOptions "extra arguments" to use in obtain().
        (    (   t   usernamet   password(    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   make_rev_argsV  s    c         C@  sU   |  j  | ƒ \ } } } | \ } } |  j | | ƒ } |  j | d | ƒ} | | f S(   sŒ   
        Return the URL and RevOptions object to use in obtain() and in
        some cases export(), as a tuple (url, rev_options).
        R#   (   R}   R€   R0   (   R%   Rn   R   R|   R~   R   R#   t   rev_options(    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   get_url_rev_options]  s
    c         C@  s   t  j |  ƒ j d ƒ S(   si   
        Normalize a URL for comparison by unquoting it and removing any
        trailing slash.
        t   /(   R<   t   unquotet   rstrip(   Rn   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   normalize_urlj  s    c         C@  s   |  j  | ƒ |  j  | ƒ k S(   sV   
        Compare two repo URLs for identity, ignoring incidental differences.
        (   R†   (   RO   t   url1t   url2(    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   compare_urlss  s    c         C@  s
   t  ‚ d S(   sð   
        Fetch a revision from a repository, in the case that this is the
        first fetch from the repository.

        Args:
          dest: the directory to fetch the repository to.
          rev_options: a RevOptions object.
        N(   Rd   (   R%   t   destRn   R   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt	   fetch_new{  s    	c         C@  s
   t  ‚ d S(   s}   
        Switch the repo at ``dest`` to point to ``URL``.

        Args:
          rev_options: a RevOptions object.
        N(   Rd   (   R%   RŠ   Rn   R   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   switch†  s    c         C@  s
   t  ‚ d S(   sŠ   
        Update an already-existing repo to the given ``rev_options``.

        Args:
          rev_options: a RevOptions object.
        N(   Rd   (   R%   RŠ   Rn   R   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   update  s    c         C@  s
   t  ‚ d S(   s¬   
        Return whether the id of the current commit equals the given name.

        Args:
          dest: the repository directory.
          name: a string name.
        N(   Rd   (   RO   RŠ   R'   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   is_commit_id_equal˜  s    	c   	      C@  s†  |  j  | ƒ \ } } t j j | ƒ s> |  j | | | ƒ d S| j ƒ  } |  j | ƒ r.|  j | ƒ } |  j | | ƒ rú t	 j
 d |  j j ƒ  t | ƒ | ƒ |  j | | j ƒ sé t	 j d t | ƒ |  j | ƒ |  j | | | ƒ n t	 j d ƒ d St	 j d |  j |  j t | ƒ | ƒ d d f } n( t	 j d | |  j |  j ƒ d d f } t	 j d |  j | ƒ t d | d | d ƒ } | d k r£t j d ƒ n  | d	 k ræt	 j d t | ƒ ƒ t | ƒ |  j | | | ƒ d S| d
 k r>t | ƒ } t	 j d t | ƒ | ƒ t j | | ƒ |  j | | | ƒ d S| d k r‚t	 j d |  j t | ƒ | | ƒ |  j | | | ƒ n  d S(   s  
        Install or update in editable mode the package represented by this
        VersionControl object.

        :param dest: the repository directory in which to install or update.
        :param url: the repository URL starting with a vcs prefix.
        Ns)   %s in %s exists, and has correct URL (%s)s   Updating %s %s%ss$   Skipping because already up-to-date.s   %s %s in %s exists with URL %ss%   (s)witch, (i)gnore, (w)ipe, (b)ackup t   st   it   wt   bs0   Directory %s already exists, and is not a %s %s.s   (i)gnore, (w)ipe, (b)ackup s+   The plan is to install the %s repository %ss   What to do?  %si    i   t   aiÿÿÿÿs   Deleting %ss   Backing up %s to %ss   Switching %s %s to %s%s(   R   R   R‘   R’   (   R   R‘   R’   (   R‚   Re   Rf   t   existsR‹   R/   t   is_repository_directoryRa   R‰   RL   RN   t	   repo_namet   titleR   RŽ   R   t   infoR   RM   R'   R   t   syst   exitR   R   t   shutilt   moveRŒ   (	   R%   RŠ   Rn   R   t   rev_displayt   existing_urlt   promptt   responset   dest_dir(    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   obtain£  s€    				
	
	c         C@  s6   t  j j | ƒ r t | ƒ n  |  j | d | ƒd S(   sµ   
        Clean up current location and download the url repository
        (and vcs infos) into location

        :param url: the repository URL starting with a vcs prefix.
        Rn   N(   Re   Rf   R”   R   R¢   (   R%   RS   Rn   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   unpack   s    c         C@  s
   t  ‚ d S(   s–   
        Return the url used at location

        Raises RemoteNotFoundError if the repository does not have a remote
        url configured.
        N(   Rd   (   RO   RS   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyRa     s    c         C@  s
   t  ‚ d S(   sR   
        Return the current commit id of the files at the given location.
        N(   Rd   (   RO   RS   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyR_     s    t   raisec	   
      C@  s™   |  j  g | } y; t | | | d | d | d | d | d |  j d | ƒSWnG t k
 r” }	 |	 j t j k rŽ t d |  j  |  j  f ƒ ‚ q• ‚  n Xd S(	   s«   
        Run a VCS subcommand
        This is simply a wrapper around call_subprocess that adds the VCS
        command name, and checks that the VCS is available
        t   on_returncodet   extra_ok_returncodest   command_desct   extra_environt   unset_environt   spinnersC   Cannot find command %r - do you have %r installed and in your PATH?N(   R'   R   R©   t   OSErrort   errnot   ENOENTR   (
   RO   t   cmdt   show_stdoutt   cwdR¥   R¦   R§   R¨   Rª   t   e(    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   run_command  s    	c         C@  s>   t  j d | |  j |  j ƒ t j j t j j | |  j ƒ ƒ S(   sL   
        Return whether a directory path is a repository directory.
        s   Checking in %s for %s (%s)...(   RL   RN   RG   R'   Re   Rf   R”   t   join(   RO   Rf   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyR•   C  s    	c         C@  s   |  j  | ƒ S(   s6  
        Check if a location is controlled by the vcs.
        It is meant to be overridden to implement smarter detection
        mechanisms for specific vcs.

        This can do more than is_repository_directory() alone.  For example,
        the Git override checks that Git is actually available.
        (   R•   (   RO   RS   (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyRR   M  s    (    (    N(%   R   R    R'   RG   R–   R?   R©   R"   R)   t   classmethodR\   R^   R`   Rc   t   staticmethodR+   R0   Rm   Ro   Rr   R}   R€   R‚   R†   R‰   R‹   RŒ   R   RŽ   R¢   R£   Ra   R_   t   TrueR²   R•   RR   (    (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyRY   Æ   sN   

										]	

(2   R2   t
   __future__R    R¬   t   loggingRe   R›   R™   t   pip._vendorR   t   pip._vendor.six.moves.urllibR   R<   t   pip._internal.exceptionsR   t   pip._internal.utils.miscR   R   R   R   R   t   pip._internal.utils.typingR	   t   typingR
   R   R   R   R   R   R   R   R   t   pip._internal.utils.uiR   t   strt   AuthInfot   __all__t	   getLoggerR   RL   R"   R   t	   ExceptionR   t   objectR!   R4   R   RY   (    (    (    s?   lib/python2.7/site-packages/pip/_internal/vcs/versioncontrol.pyt   <module>   s.   (@	GG	