3
ûâdeQ  ã               @   s    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
mZ d dlmZ d dlmZ d dlmZmZmZmZ ejeƒZG dd	„ d	eƒZejeƒ dS )
é    N)ÚListÚOptional)Ú
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ee	e d	œd
d„ƒZ
eeeddœdd„Zeeeddœdd„Zeeeddœdd„Zeeedœdd„ƒZeeedœdd„ƒZeeedœdd„ƒZeeee edœdd„ƒZeeee dœdd„ƒZeeee dœ‡ fd d!„ƒZ‡  ZS )#Ú	MercurialÚhgz.hgÚcloneúhg+fileúhg+httpúhg+httpsúhg+sshúhg+static-http)ÚrevÚreturnc             C   s   | gS )N© )r   r   r   ú:/tmp/pip-build-red6nood/pip/pip/_internal/vcs/mercurial.pyÚget_base_rev_args    s    zMercurial.get_base_rev_argsN)ÚdestÚurlÚrev_optionsr   c             C   sP   |j ƒ }tjd||t|ƒƒ | jtddd||ƒƒ | jtdd|jƒ ƒ|d� d S )NzCloning hg %s%s to %sr   z
--noupdatez-qÚupdate)Úcwd)Z
to_displayÚloggerÚinfor   Úrun_commandr   Úto_args)Úselfr   r   r   Úrev_displayr   r   r   Ú	fetch_new$   s    
zMercurial.fetch_newc       	      C   s²   t jj|| jdƒ}tjƒ }y>|j|ƒ |jdd|jƒ t	|dƒ�}|j
|ƒ W d Q R X W n6 ttjfk
rŽ } ztjd||ƒ W Y d d }~X n X tdd|jƒ ƒ}| j||d� d S )	NÚhgrcÚpathsÚdefaultÚwz/Could not switch Mercurial repository to %s: %sr   z-q)r   )ÚosÚpathÚjoinÚdirnameÚconfigparserÚRawConfigParserÚreadÚsetZsecretÚopenÚwriteÚOSErrorÚNoSectionErrorr    Úwarningr   r#   r"   )	r$   r   r   r   Úrepo_configÚconfigÚconfig_fileÚexcÚcmd_argsr   r   r   Úswitch2   s    
 zMercurial.switchc             C   s4   | j ddg|d� tdd|jƒ ƒ}| j ||d� d S )NÚpullz-q)r   r   )r"   r   r#   )r$   r   r   r   r<   r   r   r   r   @   s    zMercurial.update)Úlocationr   c             C   s4   | j ddgdd|d�jƒ }| j|ƒr,t|ƒ}|jƒ S )NÚ
showconfigzpaths.defaultFT)Úshow_stdoutÚstdout_onlyr   )r"   ÚstripÚ_is_local_repositoryr	   )Úclsr?   r   r   r   r   Úget_remote_urlE   s    
zMercurial.get_remote_urlc             C   s   | j ddgdd|d�jƒ }|S )zW
        Return the repository-local changeset revision number, as an integer.
        Úparentsz--template={rev}FT)rA   rB   r   )r"   rC   )rE   r?   Úcurrent_revisionr   r   r   Úget_revisionQ   s    zMercurial.get_revisionc             C   s   | j ddgdd|d�jƒ }|S )zh
        Return the changeset identification hash, as a 40-character
        hexadecimal string
        rG   z--template={node}FT)rA   rB   r   )r"   rC   )rE   r?   Úcurrent_rev_hashr   r   r   Úget_requirement_revision^   s    z"Mercurial.get_requirement_revision)r   Únamer   c             C   s   dS )z&Always assume the versions don't matchFr   )rE   r   rL   r   r   r   Úis_commit_id_equall   s    zMercurial.is_commit_id_equalc             C   sD   | j dgdd|d�jƒ }tjj|ƒs:tjjtj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.
        ÚrootFT)rA   rB   r   )r"   rC   r+   r,   ÚisabsÚabspathr-   r   )rE   r?   Z	repo_rootr   r   r   Úget_subdirectoryq   s
    zMercurial.get_subdirectoryc                sv   t ƒ j|ƒ}|r|S y| jdg|ddddd�}W n2 tk
rP   tjd|ƒ d S  tk
rb   d S X tjj	|j
dƒƒS )NrN   FTÚraise)r   rA   rB   Úon_returncodeZlog_failed_cmdzIcould not determine if %s is under hg control because hg is not availablez
)ÚsuperÚget_repository_rootr"   r   r    Údebugr   r+   r,   ÚnormpathÚrstrip)rE   r?   ÚlocÚr)Ú	__class__r   r   rU      s&    zMercurial.get_repository_root)r   r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__rL   r.   Ú	repo_nameÚschemesÚstaticmethodÚstrr   r   r   r
   r&   r=   r   ÚclassmethodrF   rI   rK   r   ÚboolrM   rQ   rU   Ú__classcell__r   r   )r[   r   r      s2       r   )r/   Úloggingr+   Útypingr   r   Zpip._internal.exceptionsr   r   Zpip._internal.utils.miscr   r   Zpip._internal.utils.subprocessr   Zpip._internal.utils.urlsr	   Z pip._internal.vcs.versioncontrolr
   r   r   r   Ú	getLoggerr\   r    r   Úregisterr   r   r   r   Ú<module>   s   
 