U
    «ÃT_ö  ã                   @   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ÚInstallationError)Ú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   ú?/tmp/pip-unpacked-wheel-8u7dkzi1/pip/_internal/vcs/mercurial.pyÚget_base_rev_args'   s    zMercurial.get_base_rev_argsc              	   C   s@   t dd��,}| j|j|d� | jd|gd|jd� W 5 Q R X dS )z?Export the Hg repository at the url to the destination locationÚexport)Úkind)ÚurlÚarchiveF©Úshow_stdoutÚ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Úupdate©r   )Ú
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 ¡ }z>| |¡ | dd|j¡ t	|dƒ�}| 
|¡ W 5 Q R X W n6 ttjfk
rŽ } zt d||¡ W 5 d }~X Y n X 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,   rC   r   r   r   r%   U   s    zMercurial.updatec                 C   s2   | j ddgd|d� ¡ }|  |¡r*t|ƒ}| ¡ S )NÚ
showconfigzpaths.defaultFr   )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|d� ¡ }|S )zW
        Return the repository-local changeset revision number, as an integer.
        Úparentsz--template={rev}Fr   ©r    rG   )rI   r"   Úcurrent_revisionr   r   r   Úget_revisiond   s     þ
zMercurial.get_revisionc                 C   s   | j ddgd|d� ¡ }|S )zh
        Return the changeset identification hash, as a 40-character
        hexadecimal string
        rK   z--template={node}Fr   rL   )rI   r"   Úcurrent_rev_hashr   r   r   Úget_requirement_revisionn   s     þ
z"Mercurial.get_requirement_revisionc                 C   s   dS )z&Always assume the versions don't matchFr   )rI   r+   Únamer   r   r   Úis_commit_id_equaly   s    zMercurial.is_commit_id_equalc                 C   sB   | j dgd|d� ¡ }tj |¡s8t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.
        ÚrootFr   )r    rG   r3   r   ÚisabsÚabspathr4   r   )rI   r"   Ú	repo_rootr   r   r   Úget_subdirectory~   s      ÿ
zMercurial.get_subdirectoryc              	      sP   t t| ƒ |¡rdS z| jdg|dddd� W dS  ttfk
rJ   Y dS X d S )NTÚidentifyFÚraise)r   r   Úon_returncodeÚlog_failed_cmd)Úsuperr   Úcontrols_locationr    r   r   )rI   r"   ©Ú	__class__r   r   r]   ‹   s    ûzMercurial.controls_location)Ú__name__Ú
__module__Ú__qualname__rQ   r5   Ú	repo_nameÚschemesÚstaticmethodr   r   r.   rD   r%   ÚclassmethodrJ   rN   rP   rR   rW   r]   Ú__classcell__r   r   r^   r   r      s,   



	



r   )Ú
__future__r   Úloggingr3   Z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    
|