U ��.e~S�@s�dZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl mZddlmZddlmZmZmZmZmZmZdd lmZmZdd lmZdd lmZe�rdd lm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)dd l*m+Z+ddlm,Z,ddlm-Z-e'e%e.e%e.fZ/dgZ0e�1e2�Z3dd�Z4ddd�Z5dd�Z6Gdd�de7�Z8Gdd�de9�Z:Gdd�de9�Z;e;�Z)r&r=r!r(�r>r#r#r$�__repr__�szRevOptions.__repr__cCs|jdkr|jjS|jS�N)r(r=�default_arg_revr@r#r#r$�arg_rev�s zRevOptions.arg_revcCs0g}|j}|dk r"||j�|�7}||j7}|S)z< Return the VCS-specific command arguments. N)rDr=�get_base_rev_argsr<)r>�argsr(r#r#r$�to_args�s  zRevOptions.to_argscCs|js dSd�|j�S)N�z (to revision {}))r(r&r@r#r#r$� to_display�szRevOptions.to_displaycCs|jj||jd�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_new�szRevOptions.make_new)NN) r8r9r:�__doc__r?rA�propertyrDrGrIrLr#r#r#r$r;js �   r;cs|eZdZiZddddddgZ�fdd�Zd d �Zed d ��Zed d��Z edd��Z dd�Z dd�Z dd�Z dd�Z�ZS)� VcsSupportZsshZgitZhgZbzrZsftpZsvncs:tj�|j�ttdd�r(tj�|j�tt|���dS)N� uses_fragment) � urllib_parseZ uses_netloc�extend�schemes�getattrrP�superrOr?r@�� __class__r#r$r?�s zVcsSupport.__init__cCs |j��SrB)� _registry�__iter__r@r#r#r$rY�szVcsSupport.__iter__cCst|j���SrB)�listrX�valuesr@r#r#r$�backends�szVcsSupport.backendscCsdd�|jD�S)NcSsg|] }|j�qSr#)r1)�.0�backendr#r#r$� �sz'VcsSupport.dirnames..)r\r@r#r#r$�dirnames�szVcsSupport.dirnamescCs g}|jD]}|�|j�q |SrB)r\rRrS)r>rSr^r#r#r$r �s zVcsSupport.all_schemescCsHt|d�st�d|j�dS|j|jkrD|�|j|j<t�d|j�dS)Nr!zCannot register VCS %szRegistered VCS backend: %s)�hasattrr2r3r8r!rX�debug)r>�clsr#r#r$�register�s   zVcsSupport.registercCs||jkr|j|=dSrB)rX�r>r!r#r#r$� unregister�s zVcsSupport.unregistercCs6|j��D]&}|�|�r t�d||j�|Sq dS)zv Return a VersionControl object if a repository of that type is found at the given directory. zDetermine that %s uses VCS: %sN)rXr[�controls_locationr2rbr!)r>r5Z vcs_backendr#r#r$�get_backend_for_dir�s � zVcsSupport.get_backend_for_dircCs|��}|j�|�S)z9 Return a VersionControl object or None. )�lowerrX�getrer#r#r$� get_backend�szVcsSupport.get_backend)r8r9r:rXrSr?rYrNr\r`r rdrfrhrk� __classcell__r#r#rVr$rO�s      rOc @s8eZdZdZdZdZdZdZdZe dd��Z e dd��Z e dd ��Z e d d ��Z ed d ��Ze d8dd��Ze dd��Zdd�Ze dd��Ze dd��Zedd��Zdd�Zedd��Ze dd��Zd d!�Zd"d#�Zd$d%�Ze d&d'��Zd(d)�Zd*d+�Ze d,d-��Ze d.d/��Z e d9d2d3��Z!e d4d5��Z"e d6d7��Z#dS):�VersionControlrHr#NcCs|���d�|j�� S)z� Return whether the vcs prefix (e.g. "git+") should be added to a repository's remote url when used in a requirement. z{}:)ri� startswithr&r!)rcZ remote_urlr#r#r$�should_add_vcs_url_prefixsz(VersionControl.should_add_vcs_url_prefixcCsdS)z~ Return the path to setup.py, relative to the repo root. Return None if setup.py is in the repo root. Nr#�rcr5r#r#r$�get_subdirectoryszVersionControl.get_subdirectorycCs |�|�S)zR Return the revision string that should be used in a requirement. )� get_revision)rc�repo_dirr#r#r$�get_requirement_revisionsz'VersionControl.get_requirement_revisioncCsV|�|�}|dkrdS|�|�r.d�|j|�}|�|�}|�|�}t||||d�}|S)aC 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} Nz{}+{})r*)�get_remote_urlror&r!rtrqr,)rcrsr)r'Zrevisionr*r+r#r#r$�get_src_requirements    �z"VersionControl.get_src_requirementcCst�dS)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$rE8sz VersionControl.get_base_rev_argscCst|||d�S)z� Return a RevOptions object. Args: rev: the name of a revision to install. extra_args: a list of extra options. rJ)r;)rcr(r<r#r#r$rKBs zVersionControl.make_rev_optionscCs&tj�|�\}}|�tjj�p$t|�S)zy posix absolute paths start with os.path.sep, win32 ones start with drive (like c:\folder) )r-r.� splitdrivern�sep�bool)rcZrepoZdrive�tailr#r#r$�_is_local_repositoryNsz#VersionControl._is_local_repositorycCst�dS)z� 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. Nrw�r>r5�urlr#r#r$�exportXszVersionControl.exportcCs|dfS)aZ 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)). )NNr#)rc�netlocr"r#r#r$�get_netloc_and_authbsz"VersionControl.get_netloc_and_authc Cs�t�|�\}}}}}d|kr*td�|���|�dd�d}|�||�\}}d}d|krf|�dd�\}}t�||||df�}|||fS)z� Parse the repository URL to use, and return the URL, revision, and auth info to use. Returns: (url, rev, (username, password)). �+zvSorry, {!r} is a malformed VCS url. The format is +://, e.g. svn+http://myrepo/svn/MyApp#egg=MyApp�N�@rH)rQZurlsplit� ValueErrorr&�splitr��rsplitZ urlunsplit) rcrr"r�r.ZqueryZfrag� user_passr(r#r#r$�get_url_rev_and_authus ��z#VersionControl.get_url_rev_and_authcCsgS)zM Return the RevOptions "extra arguments" to use in obtain(). r#)�username�passwordr#r#r$� make_rev_args�szVersionControl.make_rev_argsc CsT|�|j�\}}}|\}}d}|dk r.t|�}|�||�}|j||d�} t|�| fS)z� Return the URL and RevOptions object to use in obtain() and in some cases export(), as a tuple (url, rev_options). NrJ)r��secretr r�rKr ) r>rZ secret_urlr(r�r�Zsecret_passwordr�r<� rev_optionsr#r#r$�get_url_rev_options�s z"VersionControl.get_url_rev_optionscCst�|��d�S)zi Normalize a URL for comparison by unquoting it and removing any trailing slash. �/)rQZunquote�rstrip�rr#r#r$� normalize_url�szVersionControl.normalize_urlcCs|�|�|�|�kS)zV Compare two repo URLs for identity, ignoring incidental differences. )r�)rcZurl1Zurl2r#r#r$� compare_urls�szVersionControl.compare_urlscCst�dS)z� 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. Nrw�r>�destrr�r#r#r$� fetch_new�s zVersionControl.fetch_newcCst�dS)z} Switch the repo at ``dest`` to point to ``URL``. Args: rev_options: a RevOptions object. Nrwr�r#r#r$�switch�szVersionControl.switchcCst�dS)z� Update an already-existing repo to the given ``rev_options``. Args: rev_options: a RevOptions object. Nrwr�r#r#r$�update�szVersionControl.updatecCst�dS)z� Return whether the id of the current commit equals the given name. Args: dest: the repository directory. name: a string name. Nrw)rcr�r!r#r#r$�is_commit_id_equal�s z!VersionControl.is_commit_id_equalc Cs�|�|�\}}tj�|�s,|�|||�dS|��}|�|�r�|�|�}|�||j �r�t � d|j � �t|�|�|�||j�s�t �dt|�|j |�|�|||�n t �d�dSt �d|j|j t|�|�d}nt �d||j|j �d}t �d |j|�td |d |d �}|d k�r$t�d�|dk�rXt �dt|��t|�|�|||�dS|dk�r�t|�}t �dt|�|�t�||�|�|||�dS|dk�r�t �d|j t|�||�|�|||�dS)a 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. Nz)%s in %s exists, and has correct URL (%s)zUpdating %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 %szWhat to do? %srr��a�����r�z Deleting %sr�zBacking up %s to %sr�zSwitching %s %s to %s%s)r�r-r.r/r�rI�is_repository_directoryrur�r�r2rb� repo_name�titler r�r(�infor�r3r!r�sys�exitr r�shutilZmover�) r>r�rr�Z rev_displayZ existing_url�promptZresponseZdest_dirr#r#r$�obtain�s�    �� ���    �  �zVersionControl.obtaincCs&tj�|�rt|�|j||d�dS)z� Clean up current location and download the url repository (and vcs infos) into location :param url: the repository URL starting with a vcs prefix. r�N)r-r.r/r r�r~r#r#r$�unpack?s zVersionControl.unpackcCst�dS)z� Return the url used at location Raises RemoteNotFoundError if the repository does not have a remote url configured. Nrwrpr#r#r$ruKszVersionControl.get_remote_urlcCst�dS)zR Return the current commit id of the files at the given location. Nrwrpr#r#r$rrUszVersionControl.get_revisionT�raisec Cs|t|jf|��}z t||||||||j|| d� WStk rv} z(| jtjkrdtd|j|jf��n�W5d} ~ XYnXdS)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 )� on_returncode�extra_ok_returncodes� command_desc� extra_environ� unset_environ�spinner�log_failed_cmdzCCannot find command %r - do you have %r installed and in your PATH?N)rr!r r��OSError�errnoZENOENTr) rc�cmdZ show_stdout�cwdr�r�r�r�r�r��er#r#r$� run_command\s&�  ��zVersionControl.run_commandcCs,t�d||j|j�tj�tj�||j��S)zL Return whether a directory path is a repository directory. zChecking in %s for %s (%s)...)r2rbr1r!r-r.r/r0)rcr.r#r#r$r��s �z&VersionControl.is_repository_directorycCs |�|�S)a6 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�rpr#r#r$rg�s z VersionControl.controls_location)NN)TNr�NNNNT)$r8r9r:r!r1r�rSr�rC� classmethodrorqrtrv� staticmethodrErKr}r�r�r�r�r�r�r�r�r�r�r�r�r�rurrr�r�rgr#r#r#r$rm�sr                 ]   � ' rm)N)>rMZ __future__rr�Zloggingr-r�r�Z pip._vendorrZpip._vendor.six.moves.urllibrrQZpip._internal.exceptionsrZpip._internal.utils.compatrZpip._internal.utils.miscrrr r r r Zpip._internal.utils.subprocessr rZpip._internal.utils.typingrZpip._internal.utils.urlsr�typingrrrrrrrrrrZpip._internal.utils.uirrr�strZAuthInfo�__all__Z getLoggerr8r2r%r,r6� Exceptionr7�objectr;rOrrmr#r#r#r$�s<        0     HG