a
    û"©b*  ã                   @   sÌ   d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZmZ er¤d dl	mZ d dlmZ e e¡ZG dd„ deƒZe e¡ dS )é    )Úabsolute_importN)Úconfigparser)Ú
BadCommandÚSubProcessError)Údisplay_path)Úmake_command)ÚTempDirectory)ÚMYPY_CHECK_RUNNING)Úpath_to_url)ÚVersionControlÚ!find_path_to_setup_from_repo_rootÚvcs)Ú
HiddenText)Ú
RevOptionsc                       s˜   e Zd ZdZdZdZdZedd„ ƒZdd„ Z	d	d
„ Z
dd„ Zdd„ Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZe‡ fdd„ƒZ‡  ZS )Ú	MercurialÚhgz.hgÚclone)r   zhg+filezhg+httpzhg+httpszhg+sshzhg+static-httpc                 C   s   | gS )N© )Úrevr   r   úd/home/yuhw/wc/wire-cell-python-pr-11/pr11/lib/python3.9/site-packages/pip/_internal/vcs/mercurial.pyÚget_base_rev_args'   s    zMercurial.get_base_rev_argsc                 C   sR   t dd��4}| j|j|d� | jd|g|jd� W d  ƒ n1 sD0    Y  dS )z?Export the Hg repository at the url to the destination locationÚexport)Úkind)ÚurlÚarchive©ÚcwdN)r   ÚunpackÚpathÚrun_command)ÚselfÚlocationr   Útemp_dirr   r   r   r   +   s
    
ÿzMercurial.exportc                 C   sP   |  ¡ }t d||t|ƒ¡ |  tddd||ƒ¡ | jtdd| ¡ ƒ|d� d S )NzCloning hg %s%s to %sr   z
--noupdateú-qÚupdater   )Ú
to_displayÚloggerÚinfor   r   r   Úto_args)r    Údestr   Úrev_optionsÚrev_displayr   r   r   Ú	fetch_new5   s    üþzMercurial.fetch_newc           	   
   C   sÈ   t j || jd¡}t ¡ }zR| |¡ | dd|j¡ t	|dƒ�}| 
|¡ W d   ƒ n1 s`0    Y  W n8 ttjfy¤ } zt d||¡ W Y d }~n(d }~0 0 tdd| ¡ ƒ}| j||d� d S )	NÚhgrcÚpathsÚdefaultÚwz/Could not switch Mercurial repository to %s: %sr$   r#   r   )Úosr   ÚjoinÚdirnamer   ÚRawConfigParserÚreadÚsetÚsecretÚopenÚwriteÚOSErrorÚNoSectionErrorr&   Úwarningr   r(   r   )	r    r)   r   r*   Úrepo_configÚconfigÚconfig_fileÚexcÚcmd_argsr   r   r   ÚswitchD   s    
,ÿzMercurial.switchc                 C   s4   | j ddg|d� tdd| ¡ ƒ}| j ||d� d S )NÚpullr#   r   r$   )r   r   r(   )r    r)   r   r*   rA   r   r   r   r$   U   s    zMercurial.updatec                 C   s0   | j ddg|d� ¡ }|  |¡r(t|ƒ}| ¡ S )NÚ
showconfigzpaths.defaultr   )r   ÚstripÚ_is_local_repositoryr
   )Úclsr!   r   r   r   r   Úget_remote_url[   s    þ

zMercurial.get_remote_urlc                 C   s   | j ddg|d� ¡ }|S )zW
        Return the repository-local changeset revision number, as an integer.
        Úparentsz--template={rev}r   ©r   rE   )rG   r!   Úcurrent_revisionr   r   r   Úget_revisiond   s    ÿ
zMercurial.get_revisionc                 C   s   | j ddg|d� ¡ }|S )zh
        Return the changeset identification hash, as a 40-character
        hexadecimal string
        rI   z--template={node}r   rJ   )rG   r!   Úcurrent_rev_hashr   r   r   Úget_requirement_revisionm   s
    þ
z"Mercurial.get_requirement_revisionc                 C   s   dS )z&Always assume the versions don't matchFr   )rG   r)   Únamer   r   r   Úis_commit_id_equalx   s    zMercurial.is_commit_id_equalc                 C   s@   | j dg|d� ¡ }tj |¡s6tj tj ||¡¡}t||ƒS )z~
        Return the path to setup.py, relative to the repo root.
        Return None if setup.py is in the repo root.
        Úrootr   )r   rE   r1   r   ÚisabsÚabspathr2   r   )rG   r!   Ú	repo_rootr   r   r   Úget_subdirectory}   s    ÿ
zMercurial.get_subdirectoryc                    st   t t| ƒ |¡}|r|S z| jdg|dd�}W n2 tyN   t d|¡ Y d S  ty`   Y d S 0 tj	 
| d¡¡S )NrQ   F)r   Úlog_failed_cmdzIcould not determine if %s is under hg control because hg is not availablez
)Úsuperr   Úget_repository_rootr   r   r&   Údebugr   r1   r   ÚnormpathÚrstrip)rG   r!   ÚlocÚr©Ú	__class__r   r   rX   Š   s"    ý
ÿzMercurial.get_repository_root)Ú__name__Ú
__module__Ú__qualname__rO   r3   Ú	repo_nameÚschemesÚstaticmethodr   r   r,   rB   r$   ÚclassmethodrH   rL   rN   rP   rU   rX   Ú__classcell__r   r   r^   r   r      s,   







r   )Ú
__future__r   Úloggingr1   Úpip._vendor.six.movesr   Úpip._internal.exceptionsr   r   Úpip._internal.utils.miscr   Úpip._internal.utils.subprocessr   Úpip._internal.utils.temp_dirr   Úpip._internal.utils.typingr	   Úpip._internal.utils.urlsr
   Ú pip._internal.vcs.versioncontrolr   r   r   r   r   Ú	getLoggerr`   r&   r   Úregisterr   r   r   r   Ú<module>   s    
