a
    ñ»jÇ  ã                   @  sœ   d dl mZ d dlZd dlZd dlZd dlmZmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZmZmZmZ e e¡ZG dd	„ d	eƒZe e¡ dS )
é    )ÚannotationsN)Ú
BadCommandÚInstallationError)Ú
HiddenTextÚdisplay_path)Úmake_command)Úpath_to_url)Ú
RevOptionsÚVersionControlÚ(find_path_to_project_root_from_repo_rootÚvcsc                      sø   e Zd ZdZdZdZdZedddœdd	„ƒZdd
ddddœdd„Z	d&dd
ddddœdd„Z
d'dd
ddddœdd„Zedddœdd„ƒZedddœdd„ƒZedddœdd„ƒZeddddœd d!„ƒZedddœd"d#„ƒZedddœ‡ fd$d%„ƒZ‡  ZS )(Ú	MercurialÚhgz.hgÚclone)zhg+filezhg+httpzhg+httpszhg+sshzhg+static-httpÚstrz	list[str])ÚrevÚreturnc                 C  s   d| › �gS )Nz--rev=© )r   r   r   úAE:\soccer\ml_env\Lib\site-packages\pip/_internal/vcs/mercurial.pyÚget_base_rev_args!   s    zMercurial.get_base_rev_argsr   r	   ÚintÚNone)ÚdestÚurlÚrev_optionsÚ	verbosityr   c                 C  s�   |  ¡ }t d||t|ƒ¡ |dkr*d}n |dkr8d}n|dkrFd}nd}|  td	d
g|¢|‘|‘R Ž ¡ | jtdg|¢| ¡ ‘R Ž |d� d S )NzCloning hg %s%s to %sr   )z--quieté   r   é   )ú	--verbose)r   z--debugr   z
--noupdateÚupdate©Úcwd)Ú
to_displayÚloggerÚinfor   Úrun_commandr   Úto_args)Úselfr   r   r   r   Úrev_displayÚflagsr   r   r   Ú	fetch_new%   s&    ü þzMercurial.fetch_newr   c              
   C  sæ   g }t j || jd¡}t ¡ }|dkr0| d¡ zR| |¡ | dd|j	¡ t
|dƒ�}| |¡ W d   ƒ n1 sv0    Y  W n8 ttjfyº }	 zt d||	¡ W Y d }	~	n0d }	~	0 0 tdg|¢| ¡ ‘R Ž }
| j|
|d	� d S )
NÚhgrcr   ú-qÚpathsÚdefaultÚwz/Could not switch Mercurial repository to %s: %sr   r    )ÚosÚpathÚjoinÚdirnameÚconfigparserÚRawConfigParserÚappendÚreadÚsetÚsecretÚopenÚwriteÚOSErrorÚNoSectionErrorr#   Úwarningr   r&   r%   )r'   r   r   r   r   Úextra_flagsÚrepo_configÚconfigÚconfig_fileÚexcÚcmd_argsr   r   r   Úswitch=   s    

,$zMercurial.switchc                 C  sT   g }|dkr|  d¡ | jdg|¢|d� tdg|¢| ¡ ‘R Ž }| j||d� d S )Nr   r,   Úpullr    r   )r6   r%   r   r&   )r'   r   r   r   r   r?   rD   r   r   r   r   V   s    
zMercurial.update)Úlocationr   c                 C  s4   | j ddgdd|d� ¡ }|  |¡r,t|ƒ}| ¡ S )NÚ
showconfigzpaths.defaultFT©Úshow_stdoutÚstdout_onlyr!   )r%   ÚstripÚ_is_local_repositoryr   )ÚclsrG   r   r   r   r   Úget_remote_urlf   s    ü

zMercurial.get_remote_urlc                 C  s   | j ddgdd|d� ¡ }|S )zW
        Return the repository-local changeset revision number, as an integer.
        Úparentsz--template={rev}FTrI   ©r%   rL   )rN   rG   Úcurrent_revisionr   r   r   Úget_revisionr   s    ü
zMercurial.get_revisionc                 C  s   | j ddgdd|d� ¡ }|S )zh
        Return the changeset identification hash, as a 40-character
        hexadecimal string
        rP   z--template={node}FTrI   rQ   )rN   rG   Úcurrent_rev_hashr   r   r   Úget_requirement_revision   s    ü
z"Mercurial.get_requirement_revisionz
str | NoneÚbool)r   Únamer   c                 C  s   dS )z&Always assume the versions don't matchFr   )rN   r   rW   r   r   r   Úis_commit_id_equal�   s    zMercurial.is_commit_id_equalc                 C  sD   | j dgdd|d� ¡ }tj |¡s:tj tj ||¡¡}t||ƒ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.
        ÚrootFTrI   )r%   rL   r0   r1   ÚisabsÚabspathr2   r   )rN   rG   Ú	repo_rootr   r   r   Úget_subdirectory’   s    
ÿ
zMercurial.get_subdirectoryc                   sv   t ƒ  |¡}|r|S z| jdg|ddddd�}W n2 tyP   t d|¡ Y d S  tyb   Y d S 0 tj 	| 
d¡¡S )NrY   FTÚraise)r!   rJ   rK   Úon_returncodeÚlog_failed_cmdzIcould not determine if %s is under hg control because hg is not availablez
)ÚsuperÚget_repository_rootr%   r   r#   Údebugr   r0   r1   ÚnormpathÚrstrip)rN   rG   ÚlocÚr©Ú	__class__r   r   rb       s*    ú
ýzMercurial.get_repository_root)r   )r   )Ú__name__Ú
__module__Ú__qualname__rW   r3   Ú	repo_nameÚschemesÚstaticmethodr   r*   rE   r   ÚclassmethodrO   rS   rU   rX   r]   rb   Ú__classcell__r   r   rh   r   r      s.    û ûr   )Ú
__future__r   r4   Úloggingr0   Úpip._internal.exceptionsr   r   Úpip._internal.utils.miscr   r   Úpip._internal.utils.subprocessr   Úpip._internal.utils.urlsr   Ú pip._internal.vcs.versioncontrolr	   r
   r   r   Ú	getLoggerrj   r#   r   Úregisterr   r   r   r   Ú<module>   s   
 &