B
    =)H[‹=  ã               @   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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 dd	lmZ d
dgZe e¡ZG dd„ de ƒZ!G dd„ de ƒZ"e"ƒ Z#G dd„ de ƒZ$dd„ Z%dS )z)Handles all VCS (version control) supporté    )Úabsolute_importN)Úparse)Ú
BadCommand)Údisplay_pathÚ
backup_dirÚcall_subprocessÚrmtreeÚask_path_exists)ÚMYPY_CHECK_RUNNING)ÚDictÚOptionalÚTuple)ÚCommandÚvcsÚget_src_requirementc               @   sF   e Zd ZdZddd„Zdd„ Zedd„ ƒZd	d
„ Zdd„ Z	dd„ Z
dS )Ú
RevOptionsz¢
    Encapsulates a VCS-specific revision to install, along with any VCS
    install options.

    Instances of this class should be treated as if immutable.
    Nc             C   s"   |dkrg }|| _ || _|| _dS )z¢
        Args:
          vcs: a VersionControl object.
          rev: the name of the revision to install.
          extra_args: a list of extra options.
        N)Ú
extra_argsÚrevr   )Úselfr   r   r   © r   ú[C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\pip\pip\_internal\vcs\__init__.pyÚ__init__&   s
    zRevOptions.__init__c             C   s   d  | jj| j¡S )Nz<RevOptions {}: rev={!r}>)Úformatr   Únamer   )r   r   r   r   Ú__repr__4   s    zRevOptions.__repr__c             C   s   | j d kr| jjS | j S )N)r   r   Údefault_arg_rev)r   r   r   r   Úarg_rev7   s    
zRevOptions.arg_revc             C   s0   g }| j }|dk	r"|| j |¡7 }|| j7 }|S )z<
        Return the VCS-specific command arguments.
        N)r   r   Úget_base_rev_argsr   )r   Úargsr   r   r   r   Úto_args>   s    
zRevOptions.to_argsc             C   s   | j s
dS d | j ¡S )NÚ z (to revision {}))r   r   )r   r   r   r   Ú
to_displayJ   s    zRevOptions.to_displayc             C   s   | j j|| jd�S )z•
        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   Úmake_rev_optionsr   )r   r   r   r   r   Úmake_newP   s    zRevOptions.make_new)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úpropertyr   r   r!   r#   r   r   r   r   r      s   
r   c                   s†   e Zd Zi ZddddddgZ‡ fdd„Zd	d
„ Zedd„ ƒZedd„ ƒZ	edd„ ƒZ
dd„ Zddd„Zdd„ Zdd„ Zdd„ Z‡  ZS )Ú
VcsSupportÚsshÚgitÚhgÚbzrÚsftpÚsvnc                s:   t j | j¡ tt dd ƒr(t j | j¡ tt| ƒ ¡  d S )NÚuses_fragment)	Úurllib_parseÚuses_netlocÚextendÚschemesÚgetattrr0   Úsuperr)   r   )r   )Ú	__class__r   r   r   ^   s    zVcsSupport.__init__c             C   s
   | j  ¡ S )N)Ú	_registryÚ__iter__)r   r   r   r   r9   g   s    zVcsSupport.__iter__c             C   s   t | j ¡ ƒS )N)Úlistr8   Úvalues)r   r   r   r   Úbackendsj   s    zVcsSupport.backendsc             C   s   dd„ | j D ƒS )Nc             S   s   g | ]
}|j ‘qS r   )Údirname)Ú.0Úbackendr   r   r   ú
<listcomp>p   s    z'VcsSupport.dirnames.<locals>.<listcomp>)r<   )r   r   r   r   Údirnamesn   s    zVcsSupport.dirnamesc             C   s$   g }x| j D ]}| |j¡ qW |S )N)r<   r3   r4   )r   r4   r?   r   r   r   Úall_schemesr   s    zVcsSupport.all_schemesc             C   sF   t |dƒst d|j¡ d S |j| jkrB|| j|j< t d|j¡ d S )Nr   zCannot register VCS %szRegistered VCS backend: %s)ÚhasattrÚloggerÚwarningr$   r   r8   Údebug)r   Úclsr   r   r   Úregistery   s    
zVcsSupport.registerNc             C   s<   || j kr| j |= n$|| j  ¡ kr.| j |j= n
t d¡ d S )Nz0Cannot unregister because no class or name given)r8   r;   r   rD   rE   )r   rG   r   r   r   r   Ú
unregister�   s
    

zVcsSupport.unregisterc             C   s8   x2| j  ¡ D ]$}| |¡rt d||j¡ |jS qW dS )z—
        Return the name of the version control backend if found at given
        location, e.g. vcs.get_backend_name('/path/to/vcs/checkout')
        zDetermine that %s uses VCS: %sN)r8   r;   Úcontrols_locationrD   rF   r   )r   ÚlocationÚvc_typer   r   r   Úget_backend_name‰   s    


zVcsSupport.get_backend_namec             C   s    |  ¡ }|| jkr| j| S d S )N)Úlowerr8   )r   r   r   r   r   Úget_backend•   s    
zVcsSupport.get_backendc             C   s   |   |¡}|r|  |¡S d S )N)rM   rO   )r   rK   rL   r   r   r   Úget_backend_from_locationš   s    

z$VcsSupport.get_backend_from_location)NN)r$   r%   r&   r8   r4   r   r9   r(   r<   rA   rB   rH   rI   rM   rO   rP   Ú__classcell__r   r   )r7   r   r)   Z   s   	
r)   c                   sÚ   e Zd ZdZdZdZdZdZd0‡ fdd„	Zdd„ Z	d1dd	„Z
d
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd2d,d-„Zed.d/„ ƒZ‡  ZS )3ÚVersionControlr    r   Nc                s   || _ tt| ƒj||Ž d S )N)Úurlr6   rR   r   )r   rS   r   Úkwargs)r7   r   r   r   ­   s    zVersionControl.__init__c             C   s   t ‚dS )z™
        Return the base revision arguments for a vcs command.

        Args:
          rev: the name of a revision to install.  Cannot be None.
        N)ÚNotImplementedError)r   r   r   r   r   r   ±   s    z VersionControl.get_base_rev_argsc             C   s   t | ||d�S )z�
        Return a RevOptions object.

        Args:
          rev: the name of a revision to install.
          extra_args: a list of extra options.
        )r   )r   )r   r   r   r   r   r   r"   º   s    zVersionControl.make_rev_optionsc             C   s"   t j |¡\}}| t jj¡p |S )zy
           posix absolute paths start with os.path.sep,
           win32 ones start with drive (like c:\folder)
        )ÚosÚpathÚ
splitdriveÚ
startswithÚsep)r   ÚrepoÚdriveÚtailr   r   r   Ú_is_local_repositoryÄ   s    z#VersionControl._is_local_repositoryc             C   s   |  dd¡S )Nú/Ú_)Úreplace)r   Úsurnamer   r   r   Útranslate_egg_surnameÎ   s    z$VersionControl.translate_egg_surnamec             C   s   t ‚dS )z�
        Export the repository at the url to the destination location
        i.e. only download the files, without vcs informations
        N)rU   )r   rK   r   r   r   ÚexportÒ   s    zVersionControl.exportc       	      C   sz   d}d| j kst|| j  ƒ‚| j  dd¡d }t |¡\}}}}}d}d|kr^| dd¡\}}t ||||df¡}||fS )zm
        Returns the correct repository URL and revision by parsing the given
        repository URL
        zvSorry, '%s' is a malformed VCS url. The format is <vcs>+<protocol>://<url>, e.g. svn+http://myrepo/svn/MyApp#egg=MyAppú+é   Nú@r    )rS   ÚAssertionErrorÚsplitr1   ÚurlsplitÚrsplitÚ
urlunsplit)	r   Úerror_messagerS   ÚschemeÚnetlocrW   ÚqueryÚfragr   r   r   r   Úget_url_revÙ   s    zVersionControl.get_url_revc             C   s2   |  d¡ | j¡rtd| ƒ‚|  |¡|  |¡fS )zA
        Returns (url, revision), where both are strings
        r_   zBad directory: %s)ÚrstripÚendswithr=   rh   Úget_urlÚget_revision)r   rK   r   r   r   Úget_infoì   s    
zVersionControl.get_infoc             C   s   t  |¡ d¡S )zi
        Normalize a URL for comparison by unquoting it and removing any
        trailing slash.
        r_   )r1   Úunquoters   )r   rS   r   r   r   Únormalize_urlô   s    zVersionControl.normalize_urlc             C   s   |   |¡|   |¡kS )zV
        Compare two repo URLs for identity, ignoring incidental differences.
        )ry   )r   Úurl1Úurl2r   r   r   Úcompare_urlsû   s    zVersionControl.compare_urlsc             C   s   t ‚dS )zx
        Called when installing or updating an editable package, takes the
        source path of the checkout.
        N)rU   )r   Údestr   r   r   Úobtain  s    zVersionControl.obtainc             C   s   t ‚dS )z}
        Switch the repo at ``dest`` to point to ``URL``.

        Args:
          rev_options: a RevOptions object.
        N)rU   )r   r}   rS   Úrev_optionsr   r   r   Úswitch  s    zVersionControl.switchc             C   s   t ‚dS )zŠ
        Update an already-existing repo to the given ``rev_options``.

        Args:
          rev_options: a RevOptions object.
        N)rU   )r   r}   r   r   r   r   Úupdate  s    zVersionControl.updatec             C   s   t ‚dS )z¬
        Return whether the id of the current commit equals the given name.

        Args:
          dest: the repository directory.
          name: a string name.
        N)rU   )r   r}   r   r   r   r   Úis_commit_id_equal  s    z!VersionControl.is_commit_id_equalc       
      C   s¾  d}d}|  ¡ }tj |¡rÞd}tj tj || j¡¡rÆ|  |¡}|  ||¡r¦t 	d| j
 ¡ t|ƒ|¡ |  ||j¡sšt dt|ƒ| j
|¡ |  ||¡ qÄt d¡ qÞt d| j| j
t|ƒ|¡ d}nt d|| j| j
¡ d	}|�rºt d
| j|¡ td|d  |d ƒ}|dk�r<t d| j
t|ƒ||¡ |  |||¡ n~|dk�rHnr|dk�rpt dt|ƒ¡ t|ƒ d}nJ|dk�r¦t|ƒ}	t dt|ƒ|	¡ t ||	¡ d}n|dk�rºt d¡ |S )zè
        Prepare a location to receive a checkout/clone.

        Return True if the location is ready for (and requires) a
        checkout/clone, False otherwise.

        Args:
          rev_options: a RevOptions object.
        TFz)%s in %s exists, and has correct URL (%s)zUpdating %s %s%sz$Skipping because already up-to-date.z%s %s in %s exists with URL %s)z%(s)witch, (i)gnore, (w)ipe, (b)ackup )ÚsÚiÚwÚbz0Directory %s already exists, and is not a %s %s.)z(i)gnore, (w)ipe, (b)ackup )r„   r…   r†   z+The plan is to install the %s repository %szWhat to do?  %sr   rf   rƒ   zSwitching %s %s to %s%sr„   r…   zDeleting %sr†   zBacking up %s to %sÚaéÿÿÿÿ)r!   rV   rW   ÚexistsÚjoinr=   ru   r|   rD   rF   Ú	repo_nameÚtitler   r‚   r   Úinfor�   rE   r   r	   r€   r   r   ÚshutilÚmoveÚsysÚexit)
r   r}   rS   r   ÚcheckoutÚpromptÚrev_displayÚexisting_urlÚresponseÚdest_dirr   r   r   Úcheck_destination$  s‚    








z VersionControl.check_destinationc             C   s"   t j |¡rt|ƒ |  |¡ dS )zq
        Clean up current location and download the url repository
        (and vcs infos) into location
        N)rV   rW   r‰   r   r~   )r   rK   r   r   r   Úunpack}  s    zVersionControl.unpackc             C   s   t ‚dS )zê
        Return a string representing the requirement needed to
        redownload the files currently present in location, something
        like:
          {repository_url}@{revision}#egg={project_name}-{version_identifier}
        N)rU   )r   ÚdistrK   r   r   r   r   †  s    z"VersionControl.get_src_requirementc             C   s   t ‚dS )z_
        Return the url used at location
        Used in get_info or check_destination
        N)rU   )r   rK   r   r   r   ru   �  s    zVersionControl.get_urlc             C   s   t ‚dS )zR
        Return the current commit id of the files at the given location.
        N)rU   )r   rK   r   r   r   rv   –  s    zVersionControl.get_revisionTÚraisec       	   
   C   sr   | j g| }yt||||||| j|d�S  tk
rl } z(|jtjkrZtd| j | j f ƒ‚n‚ W dd}~X Y nX dS )z«
        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
        )Úunset_environÚspinnerzCCannot find command %r - do you have %r installed and in your PATH?N)r   r   rœ   ÚOSErrorÚerrnoÚENOENTr   )	r   ÚcmdÚshow_stdoutÚcwdÚon_returncodeÚcommand_descÚextra_environr�   Úer   r   r   Úrun_commandœ  s    	zVersionControl.run_commandc             C   s0   t  d|| j| j¡ tj || j¡}tj |¡S )z¨
        Check if a location is controlled by the vcs.
        It is meant to be overridden to implement smarter detection
        mechanisms for specific vcs.
        zChecking in %s for %s (%s)...)rD   rF   r=   r   rV   rW   rŠ   r‰   )rG   rK   rW   r   r   r   rJ   ·  s    z VersionControl.controls_location)N)NN)TNr›   NNN)r$   r%   r&   r   r=   r4   rœ   r   r   r   r"   r^   rc   rd   rr   rw   ry   r|   r~   r€   r�   r‚   r˜   r™   r   ru   rv   r¨   ÚclassmethodrJ   rQ   r   r   )r7   r   rR   ¤   s:   	


		
Y		   
rR   c             C   sZ   t  |¡}|rFy|ƒ  | |¡S  tk
rD   t d||j¡ |  ¡ S X t d|¡ |  ¡ S )NzPcannot determine version of editable source in %s (%s command not found in path)ztcannot determine version of editable source in %s (is not SVN checkout, Git clone, Mercurial clone or Bazaar branch))r   rP   r   r   rD   rE   r   Úas_requirement)rš   rK   Úversion_controlr   r   r   r   Ä  s    

)&r'   Ú
__future__r   ÚcopyrŸ   ÚloggingrV   rŽ   r�   Zpip._vendor.six.moves.urllibr   r1   Úpip._internal.exceptionsr   Úpip._internal.utils.miscr   r   r   r   r	   Úpip._internal.utils.typingr
   Útypingr   r   r   Úpip._internal.basecommandr   Ú__all__Ú	getLoggerr$   rD   Úobjectr   r)   r   rR   r   r   r   r   r   Ú<module>   s.   
=G  "