
0c@_*                 @   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 j e  Z Gd d   d e  Z e j 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   S) 	Mercurialhgz.hgclonehg+filehg+httphg+httpshg+sshhg+static-httpc             C   s   |  g S)N )revr   r   :/tmp/pip-build-jynh7p1z/pip/pip/_internal/vcs/mercurial.pyget_base_rev_args'   s    zMercurial.get_base_rev_argsc             C   sO   t  d d  9 } |  j | j d | |  j d | g d | j Wd QRXd S)z?Export the Hg repository at the url to the destination locationkindexporturlarchivecwdN)r   unpackpathrun_command)selflocationr   temp_dirr   r   r   r   +   s    zMercurial.exportc             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updater    )Z
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 | |  j d  } t j   } yM | j |  | j d d | j  t	 | d   } | j
 |  Wd  QRXWnA t t j f k
 r } z t j d | |  WYd  d  } ~ Xn, Xt d d | j    } |  j | d | d  S)	Nhgrcpathsdefaultwz/Could not switch Mercurial repository to %s: %sr'   z-qr    )osr"   joindirnamer   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   switchD   s     zMercurial.switchc             C   sH   |  j  d d g d | t d d | j    } |  j  | d | d  S)Npullz-qr    r'   )r#   r   r*   )r$   r+   r   r,   rB   r   r   r   r'   U   s    zMercurial.updatec             C   sF   |  j  d d g d | j   } |  j |  r< t |  } | j   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 | j   } | S)zW
        Return the repository-local changeset revision number, as an integer.
        parentsz--template={rev}r    )r#   rF   )rH   r%   current_revisionr   r   r   get_revisiond   s    zMercurial.get_revisionc             C   s%   |  j  d d g d | j   } | S)zh
        Return the changeset identification hash, as a 40-character
        hexadecimal string
        rJ   z--template={node}r    )r#   rF   )rH   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   )rH   r+   namer   r   r   is_commit_id_equalx   s    zMercurial.is_commit_id_equalc             C   s^   |  j  d g d | j   } t j j |  sQ t j j t j 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#   rF   r3   r"   isabsabspathr4   r   )rH   r%   Z	repo_rootr   r   r   get_subdirectory}   s
    !zMercurial.get_subdirectoryc                s   t  t |   j |  } | r" | Sy" |  j d g d | d d } Wn; t k
 rl t j d |  d  SYn t k
 r d  SYn Xt j	 j
 | j d   S)NrQ   r    Zlog_failed_cmdFzIcould not determine if %s is under hg control because hg is not availablez
)superr   get_repository_rootr#   r   r(   debugr   r3   r"   normpathrstrip)rH   r%   locr)	__class__r   r   rV      s    			zMercurial.get_repository_root)zhgr   r   r   r   r   )__name__
__module____qualname__rO   r5   	repo_nameschemesstaticmethodr   r   r.   rC   r'   classmethodrI   rL   rN   rP   rT   rV   r   r   )r\   r   r      s   
		r   )
__future__r   loggingr3   Zpip._vendor.six.movesr   Zpip._internal.exceptionsr   r   Zpip._internal.utils.miscr   Zpip._internal.utils.subprocessr   Zpip._internal.utils.temp_dirr   Zpip._internal.utils.typingr	   Zpip._internal.utils.urlsr
   Z pip._internal.vcs.versioncontrolr   r   r   r   r   	getLoggerr]   r(   r   registerr   r   r   r   <module>   s    