o
    hY                     @   s  d 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m	Z	m
Z
mZmZmZmZmZmZmZmZ ddlmZ ddlmZmZ ddlmZmZmZmZmZmZmZm Z  ddl!m"Z"m#Z#m$Z$m%Z% ddl&m'Z' erldd	lm(Z( d
gZ)e*e+Z,eee- ee- f Z.de-de/fddZ0	d#de-de-de-dee- de-f
ddZ1de-de-dee- fddZ2G dd de3Z4G dd de3Z5G dd dZ6G dd  d Z7e7 Z8G d!d" d"Z9dS )$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returnc                 C   s&   t | }|du r
dS |g dtj v S )z3
    Return true if the name looks like a URL.
    NF)httphttpsfileftp)r   r   all_schemes)r   scheme r'   \/var/www/html/olx_land/venv/lib/python3.10/site-packages/pip/_internal/vcs/versioncontrol.pyis_url9   s   r)   repo_urlrevproject_namesubdirc                 C   s6   | dd}|  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_urlC   s
   
r4   location	repo_rootc                 C   s\   | }t | s| }tj| } | |krtd| dS t | rtj|| r'dS tj| |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)r5   r6   orig_locationlast_locationr'   r'   r(   (find_path_to_project_root_from_repo_rootU   s   	r@   c                   @   s   e Zd ZdS )RemoteNotFoundErrorN)__name__
__module____qualname__r'   r'   r'   r(   rA   r   s    rA   c                       s"   e Zd Zdef fddZ  ZS )RemoteNotValidErrorurlc                    s   t  | || _d S N)super__init__rF   )selfrF   	__class__r'   r(   rI   w   s   
zRemoteNotValidError.__init__)rB   rC   rD   strrI   __classcell__r'   r'   rK   r(   rE   v   s    rE   c                	   @   s   e Zd ZdZ		dded dee dee ddfdd	Zdefd
dZ	e
dee fddZdefddZdefddZdedd f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.
    Nvc_classVersionControlr+   
extra_argsr    c                 C   s(   |du rg }|| _ || _|| _d| _dS )z
        Args:
          vc_class: a VersionControl subclass.
          rev: the name of the revision to install.
          extra_args: a list of extra options.
        N)rR   r+   rP   branch_name)rJ   rP   r+   rR   r'   r'   r(   rI      s   
zRevOptions.__init__c                 C   s   d| j j d| jdS )Nz<RevOptions z: rev=>)rP   r   r+   rJ   r'   r'   r(   __repr__   s   zRevOptions.__repr__c                 C   s   | j d u r	| jjS | j S rG   )r+   rP   default_arg_revrU   r'   r'   r(   arg_rev   s   
zRevOptions.arg_revc                 C   s0   g }| j }|dur|| j|7 }|| j7 }|S )z<
        Return the VCS-specific command arguments.
        N)rX   rP   get_base_rev_argsrR   )rJ   argsr+   r'   r'   r(   to_args   s   
zRevOptions.to_argsc                 C   s   | j sdS d| j  dS )N z (to revision )r+   rU   r'   r'   r(   
to_display   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.
        rR   )rP   make_rev_optionsrR   )rJ   r+   r'   r'   r(   make_new   s   zRevOptions.make_newNN)rB   rC   rD   __doc__r   r	   rM   r   rI   rV   propertyrX   r[   r_   rb   r'   r'   r'   r(   rO   |   s&    

rO   c                       s   e Zd ZU i Zeedf ed< g dZd fddZde	e fdd	Z
eded fd
dZedee fddZedee fddZded ddfddZdeddfddZdeded fddZdeded fddZdeded fddZ  ZS )
VcsSupportrQ   	_registry)sshgithgbzrsftpsvnr    Nc                    s   t jj| j t   d S rG   )urllibparseuses_netlocextendschemesrH   rI   rU   rK   r'   r(   rI      s   zVcsSupport.__init__c                 C   s
   | j  S rG   )rg   __iter__rU   r'   r'   r(   rs      s   
zVcsSupport.__iter__c                 C   s   t | j S rG   )listrg   valuesrU   r'   r'   r(   backends   s   zVcsSupport.backendsc                 C   s   dd | j D S )Nc                 S   s   g | ]}|j qS r'   )r9   ).0backendr'   r'   r(   
<listcomp>   s    z'VcsSupport.dirnames.<locals>.<listcomp>)rv   rU   r'   r'   r(   dirnames   s   zVcsSupport.dirnamesc                 C   s    g }| j D ]}||j q|S rG   )rv   rq   rr   )rJ   rr   rx   r'   r'   r(   r%      s   
zVcsSupport.all_schemesclsc                 C   sL   t |dstd|j d S |j| jvr$| | j|j< td|j d S d S )Nr   zCannot register VCS %szRegistered VCS backend: %s)hasattrr:   r;   rB   r   rg   debug)rJ   r{   r'   r'   r(   register   s   
zVcsSupport.registerr   c                 C   s   || j v r| j |= d S d S rG   )rg   rJ   r   r'   r'   r(   
unregister   s   
zVcsSupport.unregisterr5   c                 C   sX   i }| j  D ]}||}|sqtd||j |||< q|s"dS t|td}|| S )zv
        Return a VersionControl object if a repository of that type is found
        at the given directory.
        zDetermine that %s uses VCS: %sN)key)rg   ru   get_repository_rootr:   r}   r   maxlen)rJ   r5   vcs_backendsvcs_backend	repo_pathinner_most_repo_pathr'   r'   r(   get_backend_for_dir   s   

zVcsSupport.get_backend_for_dirr&   c                 C   s&   | j  D ]}||jv r|  S qdS )9
        Return a VersionControl object or None.
        N)rg   ru   rr   )rJ   r&   r   r'   r'   r(   get_backend_for_scheme   s
   
z!VcsSupport.get_backend_for_schemec                 C   s   |  }| j|S )r   )lowerrg   getr   r'   r'   r(   get_backend  s   zVcsSupport.get_backend)r    N)rB   rC   rD   rg   r   rM   __annotations__rr   rI   r   rs   re   r   rv   rz   r%   r   r~   r   r	   r   r   r   rN   r'   r'   rK   r(   rf      s    
 	rf   c                   @   sZ  e Zd ZU dZdZdZdZeedf e	d< dZ
eedf e	d< dZee e	d< eded	efd
dZeded	ee fddZeded	efddZededed	efddZeded	ee fddZdeded	efddZe	d\dee dee d	efddZeded	efd d!Zed"ed#ed	eeeee ee f f fd$d%Zeded	eeee ef fd&d'Zed(ee d)ee d	efd*d+Zded	eeef fd,d-Z eded	efd.d/Z!ed0ed1ed	efd2d3Z"deded4ed5e#d	df
d6d7Z$deded4ed	dfd8d9Z%deded4ed	dfd:d;Z&eded<ee d	efd=d>Z'deded5e#d	dfd?d@Z(deded5e#d	dfdAdBZ)eded	efdCdDZ*eded	efdEdFZ+e	G		H					G	Id]dJe,ee ef dKedLee dMdNdOee-e#  dPee dQee.ee/f  dRee0 dSedTed	efdUdVZ1edWed	efdXdYZ2eded	ee fdZd[Z3dS )^rQ   r\   r'   .rr   unset_environNrW   
remote_urlr    c                 C   s   |  | 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_prefix  s   z(VersionControl.should_add_vcs_url_prefixr5   c                 C      dS )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{   r5   r'   r'   r(   get_subdirectory$  s   zVersionControl.get_subdirectoryrepo_dirc                 C   s
   |  |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,   c                 C   sL   |  |}| |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   r   r   r   r4   )r{   r   r,   r*   revisionr-   r3   r'   r'   r(   get_src_requirement3  s   



z"VersionControl.get_src_requirementr+   c                 C      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(   rY   K     z VersionControl.get_base_rev_argsrF   destc                 C   r   )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'   )rJ   rF   r   r'   r'   r(   is_immutable_rev_checkoutU  s   z(VersionControl.is_immutable_rev_checkoutrR   c                 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`   )rO   )r{   r+   rR   r'   r'   r(   ra   b  s   zVersionControl.make_rev_optionsrepoc                 C   s&   t j|\}}|t jjpt|S )zs
        posix absolute paths start with os.path.sep,
        win32 ones start with drive (like c:\folder)
        )r7   r8   
splitdriver   sepbool)r{   r   drivetailr'   r'   r(   _is_local_repositoryo  s   z#VersionControl._is_local_repositorynetlocr&   c                 C   s   |dfS )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)).
        rc   r'   )r{   r   r&   r'   r'   r(   get_netloc_and_authx  s   z"VersionControl.get_netloc_and_authc           	      C   s   t j|\}}}}}d|vrtd||ddd }| ||\}}d}d|v r=|dd\}}|s=td|t j	||||df}|||fS )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   Nr0   zyThe URL {!r} has an empty revision (after @) which is not supported. Include a revision after @ or remove @ from the URL.r\   )
rn   ro   urlsplit
ValueErrorformatsplitr   rsplitr   
urlunsplit)	r{   rF   r&   r   r8   queryfrag	user_passr+   r'   r'   r(   get_url_rev_and_auth  s$   
z#VersionControl.get_url_rev_and_authusernamepasswordc                 C   s   g S )zM
        Return the RevOptions "extra arguments" to use in obtain().
        r'   )r   r   r'   r'   r(   make_rev_args     zVersionControl.make_rev_argsc           
      C   sT   |  |j\}}}|\}}d}|durt|}| ||}| j||d}	t||	fS )zq
        Return the URL and RevOptions object to use in obtain(),
        as a tuple (url, rev_options).
        Nr`   )r   secretr   r   ra   r   )
rJ   rF   
secret_urlr+   r   r   secret_passwordr   rR   rev_optionsr'   r'   r(   get_url_rev_options  s   z"VersionControl.get_url_rev_optionsc                 C   s   t j| dS )zi
        Normalize a URL for comparison by unquoting it and removing any
        trailing slash.
        /)rn   ro   unquoterstrip)rF   r'   r'   r(   normalize_url  s   zVersionControl.normalize_urlurl1url2c                 C   s   |  ||  |kS )zV
        Compare two repo URLs for identity, ignoring incidental differences.
        )r   )r{   r   r   r'   r'   r(   compare_urls  s   zVersionControl.compare_urlsr   	verbosityc                 C   r   )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   )rJ   r   rF   r   r   r'   r'   r(   	fetch_new  s   zVersionControl.fetch_newc                 C   r   )z}
        Switch the repo at ``dest`` to point to ``URL``.

        Args:
          rev_options: a RevOptions object.
        r   rJ   r   rF   r   r'   r'   r(   switch  r   zVersionControl.switchc                 C   r   )z
        Update an already-existing repo to the given ``rev_options``.

        Args:
          rev_options: a RevOptions object.
        r   r   r'   r'   r(   update  r   zVersionControl.updater   c                 C   r   )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   r   r'   r'   r(   is_commit_id_equal  s   	z!VersionControl.is_commit_id_equalc           
      C   s  |  |\}}tj|s| j||||d dS | }| |rl| |}| ||j	r\t
d| j t|| | ||jsUt
dt|| j| | ||| dS t
d dS t
d| j| jt|| d}nt
d|| j| j d	}t
d
| j| td|d |d }|dkrtd |dkrt
dt| t| | j||||d dS |dkrt|}	t
dt||	 t||	 | j||||d dS |dkrt
d| jt||| | ||| dS dS )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)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?  {}r   r   ar   zDeleting %sr   zBacking up %s to %sr   zSwitching %s %s to %s%s)r   r7   r8   existsr   r_   is_repository_directoryr   r   r   r:   r}   	repo_nametitler   r   r+   infor   r;   r   r   r   sysexitr   r   shutilmover   )
rJ   r   rF   r   r   rev_displayexisting_urlpromptresponsedest_dirr'   r'   r(   obtain  s   	



zVersionControl.obtainc                 C   s(   t j|r
t| | j|||d dS )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.
        )rF   r   N)r7   r8   r   r   r   )rJ   r5   rF   r   r'   r'   r(   unpackV  s   zVersionControl.unpackc                 C   r   )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   b  r   zVersionControl.get_remote_urlc                 C   r   )zR
        Return the current commit id of the files at the given location.
        r   r   r'   r'   r(   r   l  s   zVersionControl.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                 C   s   t | jg|R  }|du rt|}zt|||||||| j||	|
dW S  ty6   td| jd| jd tyE   td| 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   zCannot find command z - do you have z installed and in your PATH?zNo 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.)r   r   r   r   r   FileNotFoundErrorr   PermissionError)r{   r   r   r   r   r   r   r   r   r   r   r'   r'   r(   run_commands  s8   
zVersionControl.run_commandr8   c                 C   s,   t d|| j| j tjtj|| jS )zL
        Return whether a directory path is a repository directory.
        zChecking in %s for %s (%s)...)r:   r}   r9   r   r7   r8   r   join)r{   r8   r'   r'   r(   r     s   z&VersionControl.is_repository_directoryc                 C   s   |  |r|S dS )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)4rB   rC   rD   r   r9   r   rr   r
   rM   r   r   rW   r	   classmethodr   r   r   r   r   staticmethodr   rY   r   r   rO   ra   r   r   AuthInfor   r   r   r   r   r   intr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r'   r'   r'   r(   rQ     s   
 	"
		
Y	
	
7rQ   rG   ):rd   loggingr7   r   r   urllib.parsern   typingr   r   r   r   r   r   r   r	   r
   r   r   pip._internal.cli.spinnersr   pip._internal.exceptionsr   r   pip._internal.utils.miscr   r   r   r   r   r   r   r   pip._internal.utils.subprocessr   r   r   r   pip._internal.utils.urlsr   r   __all__	getLoggerrB   r:   rM   r   r   r)   r4   r@   	ExceptionrA   rE   rO   rf   r   rQ   r'   r'   r'   r(   <module>   sV    4(



CP