Current File : //lib/python3.9/site-packages/pip/_internal/vcs/__pycache__/versioncontrol.cpython-39.pyc
a

[��f�W�@s�dZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZddlmZddlmZmZddlmZmZmZmZmZmZmZm Z ddl!m"Z"m#Z#m$Z$ddl%m&Z&er�dd	lm'Z'd
gZ(e�)e*�Z+eee,ee,fZ-e,e.d�dd
�Z/de,e,e,ee,e,d�dd�Z0e,e,ee,d�dd�Z1Gdd�de2�Z3Gdd�de2�Z4Gdd�d�Z5Gdd�d�Z6e6�Z7Gdd�d�Z8dS)z)Handles all VCS (version control) support�N)�
TYPE_CHECKING�Any�Dict�Iterable�Iterator�List�Mapping�Optional�Tuple�Type�Union)�SpinnerInterface)�
BadCommand�InstallationError)�
HiddenText�ask_path_exists�
backup_dir�display_path�hide_url�
hide_value�is_installable_dir�rmtree)�CommandArgs�call_subprocess�make_command)�get_url_scheme)�Literal�vcs��name�returncCs&t|�}|durdS|gd�tjvS)z3
    Return true if the name looks like a URL.
    NF)�http�https�file�ftp)rr�all_schemes)r�scheme�r'�D/usr/lib/python3.9/site-packages/pip/_internal/vcs/versioncontrol.py�is_url4sr))�repo_url�rev�project_name�subdirr cCs6|�dd�}|�d|�d|��}|r2|d|��7}|S)z�
    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.
    �-�_�@z#egg=z&subdirectory=)�replace)r*r+r,r-Zegg_project_name�reqr'r'r(�make_vcs_requirement_url>s

r3)�location�	repo_rootr cCsV|}t|�s6|}tj�|�}||krt�d|�dSqtj�||�rHdStj�||�S)z�
    Find the the Python project's root by searching up the filesystem from
    `location`. Return the path to project root relative to `repo_root`.
    Return None if the project root is `repo_root`, or cannot be found.
    zOCould not find a Python project for directory %s (tried all parent directories)N)r�os�path�dirname�logger�warning�samefile�relpath)r4r5Z
orig_locationZ
last_locationr'r'r(�(find_path_to_project_root_from_repo_rootPs	�r=c@seZdZdS)�RemoteNotFoundErrorN)�__name__�
__module__�__qualname__r'r'r'r(r>msr>cs"eZdZed��fdd�Z�ZS)�RemoteNotValidError��urlcst��|�||_dS�N)�super�__init__rD)�selfrD��	__class__r'r(rGrszRemoteNotValidError.__init__)r?r@rA�strrG�
__classcell__r'r'rIr(rBqsrBc@s�eZdZdZdedeeeedd�dd�Zed�dd	�Z	e
eed�d
d��Zed�dd
�Zed�dd�Z
edd�dd�ZdS)�
RevOptionsz�
    Encapsulates a VCS-specific revision to install, along with any VCS
    install options.

    Instances of this class should be treated as if immutable.
    N�VersionControl)�vc_classr+�
extra_argsr cCs(|durg}||_||_||_d|_dS)z�
        Args:
          vc_class: a VersionControl subclass.
          rev: the name of the revision to install.
          extra_args: a list of extra options.
        N)rPr+rOZbranch_name)rHrOr+rPr'r'r(rG�szRevOptions.__init__�r cCsd|jj�d|j�d�S)Nz<RevOptions z: rev=�>)rOrr+�rHr'r'r(�__repr__�szRevOptions.__repr__cCs|jdur|jjS|jSrE)r+rO�default_arg_revrSr'r'r(�arg_rev�s
zRevOptions.arg_revcCs0g}|j}|dur"||j�|�7}||j7}|S)z<
        Return the VCS-specific command arguments.
        N)rVrO�get_base_rev_argsrP)rH�argsr+r'r'r(�to_args�s
zRevOptions.to_argscCs|js
dSd|j�d�S)N�z (to revision �)�r+rSr'r'r(�
to_display�szRevOptions.to_display�r+r cCs|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.
        �rP)rO�make_rev_optionsrP)rHr+r'r'r(�make_new�szRevOptions.make_new)NN)r?r@rA�__doc__rr	rKrrGrT�propertyrVrYr]rar'r'r'r(rMws
��rMcs�eZdZUiZeedfed<gd�Zdd��fdd�Ze	ed�dd	�Z
eedd�d
d��Z
eeed�dd
��Zeeed�dd��Zeddd�dd�Zedd�dd�Zeedd�dd�Zeedd�dd�Zeedd�dd�Z�ZS)�
VcsSupportrN�	_registry)Zssh�gitZhgZbzr�sftp�svnNrQcstjj�|j�t���dSrE)�urllib�parse�uses_netloc�extend�schemesrFrGrSrIr'r(rG�szVcsSupport.__init__cCs
|j��SrE)re�__iter__rSr'r'r(rn�szVcsSupport.__iter__cCst|j���SrE)�listre�valuesrSr'r'r(�backends�szVcsSupport.backendscCsdd�|jD�S)NcSsg|]
}|j�qSr')r8)�.0�backendr'r'r(�
<listcomp>��z'VcsSupport.dirnames.<locals>.<listcomp>)rqrSr'r'r(�dirnames�szVcsSupport.dirnamescCs g}|jD]}|�|j�q
|SrE)rqrlrm)rHrmrsr'r'r(r%�s
zVcsSupport.all_schemes)�clsr cCsHt|d�st�d|j�dS|j|jvrD|�|j|j<t�d|j�dS)NrzCannot register VCS %szRegistered VCS backend: %s)�hasattrr9r:r?rre�debug)rHrwr'r'r(�register�s
zVcsSupport.registerrcCs||jvr|j|=dSrE)re�rHrr'r'r(�
unregister�s
zVcsSupport.unregister�r4r cCsXi}|j��D],}|�|�}|s"qt�d||j�|||<q|sDdSt|td�}||S)zv
        Return a VersionControl object if a repository of that type is found
        at the given directory.
        zDetermine that %s uses VCS: %sN)�key)rerp�get_repository_rootr9ryr�max�len)rHr4Zvcs_backends�vcs_backendZ	repo_pathZinner_most_repo_pathr'r'r(�get_backend_for_dir�s

zVcsSupport.get_backend_for_dir)r&r cCs&|j��D]}||jvr
|Sq
dS)�9
        Return a VersionControl object or None.
        N)rerprm)rHr&r�r'r'r(�get_backend_for_scheme�s

z!VcsSupport.get_backend_for_schemecCs|��}|j�|�S)r�)�lowerre�getr{r'r'r(�get_backendszVcsSupport.get_backend)r?r@rArerrK�__annotations__rmrGrrnrcrrqrvr%rrzr|r	r�r�r�rLr'r'rIr(rd�s
	rdc@s�eZdZUdZdZdZdZeedfe	d<dZ
eedfe	d<dZeee	d<e
eed�d	d
��Ze
eeed�dd
��Ze
eed�dd��Ze
eeed�dd��Zeeeed�dd��Zeeed�dd�Ze
dPeeeeed�dd��Ze
eed�dd��Ze
eeeeeeeeeffd �d!d"��Ze
eeeeeefd#�d$d%��Zeeeeeed&�d'd(��Zeeeefd#�d)d*�Z eeed#�d+d,��Z!e
eeed-�d.d/��Z"eeedd0�d1d2�Z#eeedd0�d3d4�Z$eeedd0�d5d6�Z%e
eeeed7�d8d9��Z&eedd:�d;d<�Z'eedd=�d>d?�Z(e
eed�d@dA��Z)e
eed�dBdC��Z*e
dQe+eeefeeedGee,e-eeee.ee/fee0eeedH�dIdJ��Z1e
eedK�dLdM��Z2e
eeed�dNdO��Z3dS)RrNrZr'.rm�
unset_environNrU)�
remote_urlr cCs|���|j�d��S)z�
        Return whether the vcs prefix (e.g. "git+") should be added to a
        repository's remote url when used in a requirement.
        �:)r��
startswithr)rwr�r'r'r(�should_add_vcs_url_prefixsz(VersionControl.should_add_vcs_url_prefixr}cCsdS)z�
        Return the path to Python project root, relative to the repo root.
        Return None if the project root is in the repo root.
        Nr'�rwr4r'r'r(�get_subdirectoryszVersionControl.get_subdirectory)�repo_dirr cCs
|�|�S)zR
        Return the revision string that should be used in a requirement.
        )�get_revision)rwr�r'r'r(�get_requirement_revision'sz'VersionControl.get_requirement_revision)r�r,r cCsL|�|�}|�|�r$|j�d|��}|�|�}|�|�}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}
        �+)r-)�get_remote_urlr�rr�r�r3)rwr�r,r*Zrevisionr-r2r'r'r(�get_src_requirement.s



z"VersionControl.get_src_requirementr^cCst�dS)z�
        Return the base revision arguments for a vcs command.

        Args:
          rev: the name of a revision to install.  Cannot be None.
        N��NotImplementedErrorr\r'r'r(rWFsz VersionControl.get_base_rev_args)rD�destr cCsdS)aZ
        Return true if the commit hash checked out at dest matches
        the revision in url.

        Always return False, if the VCS does not support immutable commit
        hashes.

        This method does not check if there are local uncommitted changes
        in dest after checkout, as pip currently has no use case for that.
        Fr')rHrDr�r'r'r(�is_immutable_rev_checkoutPsz(VersionControl.is_immutable_rev_checkout)r+rPr cCst|||d�S)z�
        Return a RevOptions object.

        Args:
          rev: the name of a revision to install.
          extra_args: a list of extra options.
        r_)rM)rwr+rPr'r'r(r`]szVersionControl.make_rev_options)�repor cCs&tj�|�\}}|�tjj�p$t|�S)zs
        posix absolute paths start with os.path.sep,
        win32 ones start with drive (like c:\folder)
        )r6r7�
splitdriver��sep�bool)rwr��drive�tailr'r'r(�_is_local_repositoryjsz#VersionControl._is_local_repository)�netlocr&r cCs|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')rwr�r&r'r'r(�get_netloc_and_authssz"VersionControl.get_netloc_and_auth)rDr c	Cs�tj�|�\}}}}}d|vr,td�|���|�dd�d}|�||�\}}d}d|vrz|�dd�\}}|sztd�|���tj�	||||df�}|||fS)z�
        Parse the repository URL to use, and return the URL, revision,
        and auth info to use.

        Returns: (url, rev, (username, password)).
        r�zvSorry, {!r} is a malformed VCS url. The format is <vcs>+<protocol>://<url>, e.g. svn+http://myrepo/svn/MyApp#egg=MyApp�Nr0zyThe URL {!r} has an empty revision (after @) which is not supported. Include a revision after @ or remove @ from the URL.rZ)
rirj�urlsplit�
ValueError�format�splitr��rsplitr�
urlunsplit)	rwrDr&r�r7�query�frag�	user_passr+r'r'r(�get_url_rev_and_auth�s(����z#VersionControl.get_url_rev_and_auth)�username�passwordr cCsgS)zM
        Return the RevOptions "extra arguments" to use in obtain().
        r')r�r�r'r'r(�
make_rev_args�szVersionControl.make_rev_argsc
CsT|�|j�\}}}|\}}d}|dur.t|�}|�||�}|j||d�}	t|�|	fS)zq
        Return the URL and RevOptions object to use in obtain(),
        as a tuple (url, rev_options).
        Nr_)r��secretrr�r`r)
rHrDZ
secret_urlr+r�r�Zsecret_passwordr�rP�rev_optionsr'r'r(�get_url_rev_options�sz"VersionControl.get_url_rev_optionscCstj�|��d�S)zi
        Normalize a URL for comparison by unquoting it and removing any
        trailing slash.
        �/)rirj�unquote�rstriprCr'r'r(�
normalize_url�szVersionControl.normalize_url)�url1�url2r cCs|�|�|�|�kS)zV
        Compare two repo URLs for identity, ignoring incidental differences.
        )r�)rwr�r�r'r'r(�compare_urls�szVersionControl.compare_urls)r�rDr�r cCst�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.
        Nr��rHr�rDr�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.
        Nr�r�r'r'r(�switch�szVersionControl.switchcCst�dS)z�
        Update an already-existing repo to the given ``rev_options``.

        Args:
          rev_options: a RevOptions object.
        Nr�r�r'r'r(�update�szVersionControl.update)r�rr cCst�dS)z�
        Return whether the id of the current commit equals the given name.

        Args:
          dest: the repository directory.
          name: a string name.
        Nr�)rwr�rr'r'r(�is_commit_id_equal�s	z!VersionControl.is_commit_id_equal)r�rDr c	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�rZt
�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?  {}rr��a���r�zDeleting %sr�zBacking up %s to %sr�zSwitching %s %s to %s%s)r�r6r7�existsr�r]�is_repository_directoryr�r�r�r9ry�	repo_name�titlerr�r+�infor�r:rrr��sys�exitrr�shutil�mover�)	rHr�rDr�Zrev_displayZexisting_url�promptZresponseZdest_dirr'r'r(�obtain�s�

��
���




�zVersionControl.obtain)r4rDr cCs&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.
        rCN)r6r7r�rr�)rHr4rDr'r'r(�unpackMszVersionControl.unpackcCst�dS)z�
        Return the url used at location

        Raises RemoteNotFoundError if the repository does not have a remote
        url configured.
        Nr�r�r'r'r(r�XszVersionControl.get_remote_urlcCst�dS)zR
        Return the current commit id of the files at the given location.
        Nr�r�r'r'r(r�bszVersionControl.get_revisionT�raiseFz"Literal["raise", "warn", "ignore"])�cmd�show_stdout�cwd�
on_returncode�extra_ok_returncodes�command_desc�
extra_environ�spinner�log_failed_cmd�stdout_onlyr c
Cs�t|jg|�R�}z"t||||||||j||	|
d�WSty`td|j�d|j�d���Yn$ty�td|j�d���Yn0dS)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
        )r�r�r�r�r�r�r�r�zCannot find command z - do you have z installed and in your PATH?zNo permission to execute z� - install it locally, globally (ask admin), or check your PATH. See possible solutions at https://pip.pypa.io/en/latest/reference/pip_freeze/#fixing-permission-denied.N)rrrr��FileNotFoundErrorr�PermissionError)rwr�r�r�r�r�r�r�r�r�r�r'r'r(�run_commandis2�

���zVersionControl.run_command)r7r cCs,t�d||j|j�tj�tj�||j��S)zL
        Return whether a directory path is a repository directory.
        zChecking in %s for %s (%s)...)r9ryr8rr6r7r��join)rwr7r'r'r(r��sz&VersionControl.is_repository_directorycCs|�|�r|SdS)ay
        Return the "root" (top-level) directory controlled by the vcs,
        or `None` if the directory is not in any.

        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.
        N)r�r�r'r'r(r�s
z"VersionControl.get_repository_root)NN)	TNr�NNNNTF)4r?r@rArr8r�rmr
rKr�r�rUr	�classmethodr�r�r�r�r��staticmethodrrWr�rrMr`r�r��AuthInfor�rr�r�r�r�r�r�r�r�r�r�r�r�rr�intrrr
r�r�rr'r'r'r(rN
s�
	
��� �		
X	�
�5rN)N)9rbZloggingr6r�r��urllib.parseri�typingrrrrrrrr	r
rrZpip._internal.cli.spinnersr
Zpip._internal.exceptionsrrZpip._internal.utils.miscrrrrrrrrZpip._internal.utils.subprocessrrrZpip._internal.utils.urlsrr�__all__Z	getLoggerr?r9rKr�r�r)r3r=�	Exceptionr>rBrMrdrrNr'r'r'r(�<module>s>4(

���CP