3
ÀÞL]”  ã               @   s  d dl mZ d dlZd dlZd dlZd dlZd dl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 d d
lmZmZ d dlmZ d dlmZ erÜd dlZd dl m!Z!m"Z" d dl#m$Z$ dZ%ej&e'ƒZ(G dd„ de)ƒZ*dd„ Z+dd„ Z,dS )é    )Úabsolute_importN)ÚlockfileÚpkg_resources)Úversion)Úmake_search_scope)ÚPackageFinder)ÚSelectionPreferences)ÚWINDOWS)Úcheck_path_owner)Ú
ensure_dirÚget_installed_version)Úget_installer)ÚMYPY_CHECK_RUNNING)ÚAnyÚDict)Ú
PipSessionz%Y-%m-%dT%H:%M:%SZc               @   s   e Zd Zdd„ Zdd„ ZdS )ÚSelfCheckStatec             C   sl   i | _ d | _|rhtjj|dƒ| _y,t| jƒ�}tj|ƒtj	 | _ W d Q R X W n t
ttfk
rf   Y nX d S )Nzselfcheck.json)ÚstateÚstatefile_pathÚosÚpathÚjoinÚopenÚjsonÚloadÚsysÚprefixÚIOErrorÚ
ValueErrorÚKeyError)ÚselfÚ	cache_dirÚ	statefile© r#   ú;/tmp/pip-build-69lrc5qx/pip/pip/_internal/utils/outdated.pyÚ__init__"   s     zSelfCheckState.__init__c             C   sÂ   | j s
d S ttjj| j ƒƒs d S ttjj| j ƒƒ tj| j ƒ�z tjj| j ƒrpt	| j ƒ�}t
j|ƒ}W d Q R X ni }|jtƒ|dœ|tj< t	| j dƒ�}t
j||ddd� W d Q R X W d Q R X d S )N)Ú
last_checkÚpypi_versionÚwTú,ú:)Ú	sort_keysÚ
separators)r)   r*   )r   r
   r   r   Údirnamer   r   ÚLockFileÚexistsr   r   r   ÚstrftimeÚSELFCHECK_DATE_FMTr   r   Údump)r    r'   Úcurrent_timer"   r   r#   r#   r$   Úsave2   s    
zSelfCheckState.saveN)Ú__name__Ú
__module__Ú__qualname__r%   r4   r#   r#   r#   r$   r   !   s   r   c             C   s2   yt j| ƒ}dt|ƒkS  t jk
r,   dS X dS )zµChecks whether pkg was installed by pip

    This is used not to display the upgrade message when pip is in fact
    installed by system package manager, such as dnf on Fedora.
    ÚpipFN)r   Úget_distributionr   ÚDistributionNotFound)ÚpkgÚdistr#   r#   r$   Úwas_installed_by_pipR   s
    
r=   c             C   s^  t dƒ}|sdS tj|ƒ}d}�yt|jd�}tjjƒ }d|jkrzd|jkrztjj|jd t	ƒ}|| j
ƒ dk rz|jd }|dkrÞt|d	d
�}tddd�}	tj||	|j| d�}
|
jdƒjƒ }|dkrÈdS t|jƒ}|j||ƒ tj|ƒ}||k �o|j|jk�otdƒ}|�sdS t�rd}nd}tjd|||ƒ W n$ tk
�rX   tjdd	d� Y nX dS )zÛCheck for an update for pip.

    Limit the frequency of checks to once per week. State is stored either in
    the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix
    of the pip script path.
    r8   N)r!   r&   r'   é   é   é<   T)Zsuppress_no_indexF)Zallow_yankedÚallow_all_prereleases)Úsearch_scopeÚselection_prefsÚtrusted_hostsÚsessionzpython -m pipzˆYou are using pip version %s, however version %s is available.
You should consider upgrading via the '%s install --upgrade pip' command.z5There was an error checking the latest version of pip)Úexc_infoé¨   i`'  i€:	 )r   Úpackaging_versionÚparser   r!   ÚdatetimeÚutcnowr   Ústrptimer1   Útotal_secondsr   r   r   ÚcreaterD   Zfind_candidatesZget_bestÚstrr   r4   Úbase_versionr=   r	   ÚloggerÚwarningÚ	ExceptionÚdebug)rE   ÚoptionsÚinstalled_versionÚpip_versionr'   r   r3   r&   rB   rC   ÚfinderÚ	candidateÚremote_versionZlocal_version_is_olderÚpip_cmdr#   r#   r$   Úpip_version_check`   sZ    





r\   )-Ú
__future__r   rJ   r   ÚloggingÚos.pathr   r   Úpip._vendorr   r   Zpip._vendor.packagingr   rH   Zpip._internal.cli.cmdoptionsr   Zpip._internal.indexr   Z$pip._internal.models.selection_prefsr   Zpip._internal.utils.compatr	   Zpip._internal.utils.filesystemr
   Zpip._internal.utils.miscr   r   Zpip._internal.utils.packagingr   Zpip._internal.utils.typingr   ÚoptparseÚtypingr   r   Zpip._internal.downloadr   r1   Ú	getLoggerr5   rQ   Úobjectr   r=   r\   r#   r#   r#   r$   Ú<module>   s0   
1