U
    @vgI                     @   sR  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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 d d
lmZmZmZ d dlmZ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% d dl&m'Z'm(Z(m)Z)m*Z* d dl+m,Z, dZ-e.e/Z0dddZ1dd Z2G dd de3Z4dd Z5dd Z6dS )    )absolute_importN)pkg_resources)version)ensure_binary)LinkCollector)PackageFinder)SearchScope)SelectionPreferences)adjacent_tmp_filecheck_path_ownerreplace)
ensure_dirget_installed_versionredact_auth_from_url)get_installer)MYPY_CHECK_RUNNING)Values)AnyDictTextUnion)
PipSessionz%Y-%m-%dT%H:%M:%SZFc                 C   s`   |j g|j }|jr8|s8tdddd |D  g }|jp@g }tj||d}t	| |d}|S )z
    :param session: The Session to use to make requests.
    :param suppress_no_index: Whether to ignore the --no-index option
        when constructing the SearchScope object.
    zIgnoring indexes: %s,c                 s   s   | ]}t |V  qd S N)r   ).0url r   E/tmp/pip-unpacked-wheel-gw11q0wt/pip/_internal/self_outdated_check.py	<genexpr>?   s     z&make_link_collector.<locals>.<genexpr>)
find_links
index_urls)sessionsearch_scope)
	index_urlextra_index_urlsno_indexloggerdebugjoinr   r   creater   )r!   optionssuppress_no_indexr    r   r"   link_collectorr   r   r   make_link_collector0   s    

 r-   c                 C   s   t | }t| }|S r   )r   hashlibsha224	hexdigest)key	key_bytesnamer   r   r   _get_statefile_nameO   s    r4   c                   @   s(   e Zd Zdd Zedd Zdd ZdS )SelfCheckStatec              
   C   sn   i | _ d | _|rjtj|dt| j| _z&t| j}t	|| _ W 5 Q R X W n t
ttfk
rh   Y nX d S )N	selfcheck)statestatefile_pathospathr(   r4   r1   openjsonloadIOError
ValueErrorKeyError)self	cache_dir	statefiler   r   r   __init__W   s      zSelfCheckState.__init__c                 C   s   t jS r   )sysprefix)rA   r   r   r   r1   i   s    zSelfCheckState.keyc              	   C   s   | j s
d S ttj| j s d S ttj| j  | j|t|d}t	j
|ddd}t| j }|t| W 5 Q R X zt|j| j  W n tk
r   Y nX d S )N)r1   
last_checkpypi_versionT)r   :)	sort_keys
separators)r8   r   r9   r:   dirnamer   r1   strftimeSELFCHECK_DATE_FMTr<   dumpsr
   writer   r   r3   OSError)rA   rH   current_timer7   textfr   r   r   savem   s     zSelfCheckState.saveN)__name__
__module____qualname__rD   propertyr1   rU   r   r   r   r   r5   V   s   
r5   c                 C   s6   zt | }dt|kW S  t jk
r0   Y dS X dS )zChecks 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_pip   s
    
r_   c                 C   sT  t d}|sdS t|}d}z
t|jd}tj }d|jkrzd|jkrztj|jd t	}|| 
 dk rz|jd }|dkrt| |dd}td	d	d
}	tj||	d}
|
dj}|dkrW dS t|j}||| t|}||k o|j|jkotd}|sW dS dtj}td||| W n$ tk
rN   tjddd Y nX dS )zCheck 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.
    rZ   N)rB   rG   rH   i:	 T)r*   r+   F)allow_yankedallow_all_prereleases)r,   selection_prefsz	{} -m pipzYou 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)r   packaging_versionparser5   rB   datetimeutcnowr7   strptimerN   total_secondsr-   r	   r   r)   find_best_candidatebest_candidatestrr   rU   base_versionr_   formatrE   
executabler&   warning	Exceptionr'   )r!   r*   installed_versionpip_versionrH   r7   rR   rG   r,   rb   finderrk   remote_versionlocal_version_is_olderpip_cmdr   r   r   pip_self_version_check   sl    





  rx   )F)7
__future__r   rf   r.   r<   loggingos.pathr9   rE   pip._vendorr   Zpip._vendor.packagingr   rd   Zpip._vendor.sixr   pip._internal.index.collectorr   "pip._internal.index.package_finderr   !pip._internal.models.search_scoper   $pip._internal.models.selection_prefsr	   pip._internal.utils.filesystemr
   r   r   pip._internal.utils.miscr   r   r   pip._internal.utils.packagingr   pip._internal.utils.typingr   optparser   typingr   r   r   r   pip._internal.network.sessionr   rN   	getLoggerrV   r&   r-   r4   objectr5   r_   rx   r   r   r   r   <module>   s<   
 
;