HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/pip/_internal/vcs/__pycache__/versioncontrol.cpython-310.pyc
o

@%NeY�@s�dZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZddlmZddlmZmZddlmZmZmZmZmZmZmZm Z ddl!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'erldd	lm(Z(d
gZ)e�*e+�Z,eee-ee-fZ.de-de/fd
d�Z0	d#de-de-de-dee-de-f
dd�Z1de-de-dee-fdd�Z2Gdd�de3�Z4Gdd�de3�Z5Gdd�d�Z6Gdd �d �Z7e7�Z8Gd!d"�d"�Z9dS)$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�format_command_args�make_command)�get_url_scheme)�Literal�vcs�name�returncCs&t|�}|dur
dS|gd�tjvS)z3
    Return true if the name looks like a URL.
    NF)�http�https�file�ftp)rr�all_schemes)r�scheme�r'�B/usr/lib/python3/dist-packages/pip/_internal/vcs/versioncontrol.py�is_url9sr)�repo_url�rev�project_name�subdircCs6|�dd�}|�d|�d|��}|r|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-�egg_project_name�reqr'r'r(�make_vcs_requirement_urlCs

r4�location�	repo_rootcCs\|}t|�s|}tj�|�}||krt�d|�dSt|�rtj�||�r'dStj�||�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)r5r6�
orig_location�
last_locationr'r'r(�(find_path_to_project_root_from_repo_rootUs	��
r@c@seZdZdS)�RemoteNotFoundErrorN)�__name__�
__module__�__qualname__r'r'r'r(rArsrAcs"eZdZdef�fdd�Z�ZS)�RemoteNotValidError�urlcst��|�||_dS�N)�super�__init__rF)�selfrF��	__class__r'r(rIws
zRemoteNotValidError.__init__)rBrCrD�strrI�
__classcell__r'r'rKr(rEvsrEc	@s�eZdZdZ		ddeddeedeeddfdd	�Zdefd
d�Z	e
deefdd
��Zdefdd�Zdefdd�Z
deddfdd�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�vc_class�VersionControlr+�
extra_argsr cCs(|durg}||_||_||_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)rRr+rP�branch_name)rJrPr+rRr'r'r(rI�s
zRevOptions.__init__cCsd|jj�d|j�d�S)Nz<RevOptions z: rev=�>)rPrr+�rJr'r'r(�__repr__�szRevOptions.__repr__cCs|jdur	|jjS|jSrG)r+rP�default_arg_revrUr'r'r(�arg_rev�s
zRevOptions.arg_revcCs0g}|j}|dur||j�|�7}||j7}|S)z<
        Return the VCS-specific command arguments.
        N)rXrP�get_base_rev_argsrR)rJ�argsr+r'r'r(�to_args�s
zRevOptions.to_argscCs|jsdSd|j�d�S)N�z (to revision �)�r+rUr'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.
        �rR)rP�make_rev_optionsrR)rJr+r'r'r(�make_new�szRevOptions.make_new�NN)rBrCrD�__doc__rr	rMrrIrV�propertyrXr[r_rbr'r'r'r(rO|s&
����
�rOcs�eZdZUiZeedfed<gd�Zd�fdd�Zde	efdd	�Z
ededfd
d��Z
edeefdd
��Zedeefdd��Zdedddfdd�Zdeddfdd�Zdededfdd�Zdededfdd�Zdededfdd�Z�ZS)�
VcsSupportrQ�	_registry)�ssh�git�hg�bzr�sftp�svnr Ncstjj�|j�t���dSrG)�urllib�parse�uses_netloc�extend�schemesrHrIrUrKr'r(rI�szVcsSupport.__init__cCs
|j��SrG)rg�__iter__rUr'r'r(rs�s
zVcsSupport.__iter__cCst|j���SrG)�listrg�valuesrUr'r'r(�backends�szVcsSupport.backendscCsdd�|jD�S)NcSsg|]}|j�qSr')r9)�.0�backendr'r'r(�
<listcomp>�sz'VcsSupport.dirnames.<locals>.<listcomp>)rvrUr'r'r(�dirnames�szVcsSupport.dirnamescCs g}|jD]}|�|j�q|SrG)rvrqrr)rJrrrxr'r'r(r%�s
zVcsSupport.all_schemes�clscCsLt|d�st�d|j�dS|j|jvr$|�|j|j<t�d|j�dSdS)NrzCannot register VCS %szRegistered VCS backend: %s)�hasattrr:r;rBrrg�debug)rJr{r'r'r(�register�s
�zVcsSupport.registerrcCs||jvr|j|=dSdSrG)rg�rJrr'r'r(�
unregister�s
�zVcsSupport.unregisterr5cCsXi}|j��D]}|�|�}|sqt�d||j�|||<q|s"dSt|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)rgru�get_repository_rootr:r}r�max�len)rJr5�vcs_backends�vcs_backend�	repo_path�inner_most_repo_pathr'r'r(�get_backend_for_dir�s

zVcsSupport.get_backend_for_dirr&cCs&|j��D]}||jvr|SqdS)�9
        Return a VersionControl object or None.
        N)rgrurr)rJr&r�r'r'r(�get_backend_for_scheme�s

�z!VcsSupport.get_backend_for_schemecCs|��}|j�|�S)r�)�lowerrg�getrr'r'r(�get_backendszVcsSupport.get_backend)r N)rBrCrDrgrrM�__annotations__rrrIrrsrerrvrzr%rr~r�r	r�r�r�rNr'r'rKr(rf�s 
	rfc@sZeZdZUdZdZdZdZeedfe	d<dZ
eedfe	d<dZeee	d<e
ded	efd
d��Ze
ded	eefd
d��Ze
ded	efdd��Ze
deded	efdd��Zeded	eefdd��Zdeded	efdd�Ze
	d\deedeed	efdd��Ze
ded	efd d!��Ze
d"ed#ed	eeeeeeefffd$d%��Ze
ded	eeeeeffd&d'��Zed(eed)eed	efd*d+��Zded	eeeffd,d-�Z eded	efd.d/��Z!e
d0ed1ed	efd2d3��Z"deded4ed5e#d	df
d6d7�Z$deded4ed	dfd8d9�Z%deded4ed	dfd:d;�Z&e
ded<eed	efd=d>��Z'deded5e#d	dfd?d@�Z(deded5e#d	dfdAdB�Z)e
ded	efdCdD��Z*e
ded	efdEdF��Z+e
	G		H					G	Id]dJe,eeefdKedLeedMdNdOee-e#dPeedQee.ee/fdRee0dSedTed	efdUdV��Z1e
dWed	efdXdY��Z2e
ded	eefdZd[��Z3dS)^rQr\r'.rr�
unset_environNrW�
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)r{r�r'r'r(�should_add_vcs_url_prefixsz(VersionControl.should_add_vcs_url_prefixr5cC�dS)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'�r{r5r'r'r(�get_subdirectory$szVersionControl.get_subdirectory�repo_dircCs
|�|�S)zR
        Return the revision string that should be used in a requirement.
        )�get_revision)r{r�r'r'r(�get_requirement_revision,s
z'VersionControl.get_requirement_revisionr,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�r4)r{r�r,r*�revisionr-r3r'r'r(�get_src_requirement3s



z"VersionControl.get_src_requirementr+cC�t�)z�
        Return the base revision arguments for a vcs command.

        Args:
          rev: the name of a revision to install.  Cannot be None.
        ��NotImplementedErrorr^r'r'r(rYK�z VersionControl.get_base_rev_argsrF�destcCr�)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')rJrFr�r'r'r(�is_immutable_rev_checkoutUsz(VersionControl.is_immutable_rev_checkoutrRcCst|||d�S)z�
        Return a RevOptions object.

        Args:
          rev: the name of a revision to install.
          extra_args: a list of extra options.
        r`)rO)r{r+rRr'r'r(rabszVersionControl.make_rev_options�repocCs&tj�|�\}}|�tjj�pt|�S)zs
        posix absolute paths start with os.path.sep,
        win32 ones start with drive (like c:\folder)
        )r7r8�
splitdriver��sep�bool)r{r��drive�tailr'r'r(�_is_local_repositoryosz#VersionControl._is_local_repository�netlocr&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)).
        rcr')r{r�r&r'r'r(�get_netloc_and_authxsz"VersionControl.get_netloc_and_authc	Cs�tj�|�\}}}}}d|vrtd�|���|�dd�d}|�||�\}}d}d|vr=|�dd�\}}|s=td�|���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.r\)
rnro�urlsplit�
ValueError�format�splitr��rsplitr�
urlunsplit)	r{rFr&r�r8�query�frag�	user_passr+r'r'r(�get_url_rev_and_auth�s$��
z#VersionControl.get_url_rev_and_auth�username�passwordcCsgS)zM
        Return the RevOptions "extra arguments" to use in obtain().
        r')r�r�r'r'r(�
make_rev_args��zVersionControl.make_rev_argsc
CsT|�|j�\}}}|\}}d}|durt|�}|�||�}|j||d�}	t|�|	fS)zq
        Return the URL and RevOptions object to use in obtain(),
        as a tuple (url, rev_options).
        Nr`)r��secretrr�rar)
rJrF�
secret_urlr+r�r��secret_passwordr�rR�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.
        �/)rnro�unquote�rstrip)rFr'r'r(�
normalize_url�szVersionControl.normalize_url�url1�url2cCs|�|�|�|�kS)zV
        Compare two repo URLs for identity, ignoring incidental differences.
        )r�)r{r�r�r'r'r(�compare_urls�szVersionControl.compare_urlsr��	verbositycCr�)a
        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.
          verbosity: verbosity level.
        r�)rJr�rFr�r�r'r'r(�	fetch_new�szVersionControl.fetch_newcCr�)z}
        Switch the repo at ``dest`` to point to ``URL``.

        Args:
          rev_options: a RevOptions object.
        r��rJr�rFr�r'r'r(�switch�r�zVersionControl.switchcCr�)z�
        Update an already-existing repo to the given ``rev_options``.

        Args:
          rev_options: a RevOptions object.
        r�r�r'r'r(�update�r�zVersionControl.updatercCr�)z�
        Return whether the id of the current commit equals the given name.

        Args:
          dest: the repository directory.
          name: a string name.
        r�)r{r�rr'r'r(�is_commit_id_equal�s	z!VersionControl.is_commit_id_equalc
Cs�|�|�\}}tj�|�s|j||||d�dS|��}|�|�rl|�|�}|�||j	�r\t
�d|j�
�t|�|�|�||j�sUt
�dt|�|j|�|�|||�dSt
�d�dSt
�d|j|jt|�|�d}nt
�d||j|j�d	}t
�d
|j|�td�|d�|d
�}|dkr�t�d�|dkr�t
�dt|��t|�|j||||d�dS|dkr�t|�}	t
�dt|�|	�t�||	�|j||||d�dS|dkr�t
�d|jt|�||�|�|||�dSdS)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.
        :param verbosity: verbosity level.
        )r�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�r7r8�existsr�r_�is_repository_directoryr�r�r�r:r}�	repo_name�titlerr�r+�infor�r;rrr��sys�exitrr�shutil�mover�)
rJr�rFr�r��rev_display�existing_url�prompt�response�dest_dirr'r'r(�obtain�s�	

��
����
��zVersionControl.obtaincCs(tj�|�r
t|�|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.
        :param verbosity: verbosity level.
        )rFr�N)r7r8r�rr�)rJr5rFr�r'r'r(�unpackVszVersionControl.unpackcCr�)z�
        Return the url used at location

        Raises RemoteNotFoundError if the repository does not have a remote
        url configured.
        r�r�r'r'r(r�br�zVersionControl.get_remote_urlcCr�)zR
        Return the current commit id of the files at the given location.
        r�r�r'r'r(r�lszVersionControl.get_revisionT�raiseF�cmd�show_stdout�cwd�
on_returncodez"Literal["raise", "warn", "ignore"]�extra_ok_returncodes�command_desc�
extra_environ�spinner�log_failed_cmd�stdout_onlyc
Cs�t|jg|�R�}|durt|�}zt||||||||j||	|
d�WSty6td|j�d|j�d���tyEtd|j�d���w)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
        N)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.)rrrrr��FileNotFoundErrorr�PermissionError)r{r�r�r�r�r�r�r�r�r�r�r'r'r(�run_commandss8�

����zVersionControl.run_commandr8cCs,t�d||j|j�tj�tj�||j��S)zL
        Return whether a directory path is a repository directory.
        zChecking in %s for %s (%s)...)r:r}r9rr7r8r��join)r{r8r'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_rootrc)	TNr�NNNNTF)4rBrCrDrr9r�rrr
rMr�r�rWr	�classmethodr�r�r�r�r��staticmethodrrYr�rrOrar�r��AuthInfor�rr�r�r�r��intr�r�r�r�r�r�r�r�rrrrr
r�r�r�r'r'r'r(rQs�
	
�������"�������
�		
Y	�����
���	�
���7rQrG):rd�loggingr7r�r��urllib.parsern�typingrrrrrrrr	r
rr�pip._internal.cli.spinnersr
�pip._internal.exceptionsrr�pip._internal.utils.miscrrrrrrrr�pip._internal.utils.subprocessrrrr�pip._internal.utils.urlsrr�__all__�	getLoggerrBr:rMr�r�r)r4r@�	ExceptionrArErOrfrrQr'r'r'r(�<module>sV4(

�����
���
�CP