a
    ˆÀàg¼  ã                   @   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   úT/var/www/sistema_ama/venv/lib/python3.9/site-packages/pip/_internal/vcs/mercurial.pyÚget_base_rev_args'   s    zMercurial.get_base_rev_argsc                 C   sT   t dd��6}| j|j|d� | jd|gd|jd� W d  ƒ n1 sF0    Y  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 ¡ }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 )	NZ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+   Z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+   r@   r   r   r   r$   U   s    zMercurial.updatec                 C   s4   | j ddgdd|d� ¡ }|  |¡r,t|ƒ}| ¡ S )NZ
showconfigzpaths.defaultFT©r   Ústdout_onlyr   )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|d� ¡ }|S )zW
        Return the repository-local changeset revision number, as an integer.
        Úparentsz--template={rev}FTrC   ©r   rE   )rG   r!   Zcurrent_revisionr   r   r   Úget_revisiong   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
        rI   z--template={node}FTrC   rJ   )rG   r!   Zcurrent_rev_hashr   r   r   Úget_requirement_revisiont   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_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 setup.py, relative to the repo root.
        Return None if setup.py is in the repo root.
        ÚrootFTrC   )r   rE   r1   r   ÚisabsÚabspathr2   r   )rG   r!   Ú	repo_rootr   r   r   Úget_subdirectory‡   s    
ÿ
zMercurial.get_subdirectoryc                    sz   t t| ƒ |¡}|r|S z| jdg|ddddd�}W n2 tyT   t d|¡ Y d S  tyf   Y d S 0 tj	 
| d¡¡S )NrO   FTÚraise)r   r   rD   Úon_returncodeÚ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__rM   r3   Ú	repo_nameÚschemesÚstaticmethodr   r   r-   rA   r$   ÚclassmethodrH   rK   rL   rN   rS   rX   Ú__classcell__r   r   r^   r   r      s,   






r   )Ú
__future__r   Úloggingr1   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"   
 