B
    Kkd
                 @   s   d dl mZ d dlZd dl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 d dlmZ erd d	lmZ d d
lmZ d dlmZ eeZdd Zdd Zdd Zdd ZdS )    )absolute_importN)
FeedParser)pkg_resources)
specifiersversion)
exceptions)display_path)MYPY_CHECK_RUNNING)Optional)Message)Distributionc          	   C   s>   | dkrdS t | }tdtttjdd }||kS )aG  
    Check if the python version in use match the `requires_python` specifier.

    Returns `True` if the version of python in use matches the requirement.
    Returns `False` if the version of python in use does not matches the
    requirement.

    Raises an InvalidSpecifier if `requires_python` have an invalid format.
    NT.   )	r   SpecifierSetr   parsejoinmapstrsysversion_info)requires_pythonrequires_python_specifierpython_version r   >/tmp/pip-install-gxxfd9b7/pip/pip/_internal/utils/packaging.pycheck_requires_python   s
    
 r   c             C   sf   t | tjr"| dr"| d}n,| dr8| d}ntdt| j d}t	 }|
| | S )NMETADATAzPKG-INFOzNo metadata found in %s )
isinstancer   DistInfoDistributionhas_metadataget_metadataloggerwarningr   locationr   feedclose)distmetadatafeed_parserr   r   r   r!   ,   s    


r!   c             C   s   t | }|d}y8t|sHtd| j|dttt	j
d d f W n6 tjk
r } ztd| j|| d S d }~X Y nX d S )NzRequires-Pythonz4%s requires Python '%s' but the running Python is %sr   r   z7Package %s has an invalid Requires-Python entry %s - %s)r!   getr   r   UnsupportedPythonVersionproject_namer   r   r   r   r   r   InvalidSpecifierr"   r#   )r'   pkg_info_dictr   er   r   r   check_dist_requires_python<   s    
$r0   c             C   s2   |  dr.x"| dD ]}| r| S qW dS )N	INSTALLERr   )r    get_metadata_linesstrip)r'   liner   r   r   get_installerO   s
    
r5   )
__future__r   loggingr   email.parserr   pip._vendorr   Zpip._vendor.packagingr   r   pip._internalr   pip._internal.utils.miscr   pip._internal.utils.typingr	   typingr
   email.messager   Zpip._vendor.pkg_resourcesr   	getLogger__name__r"   r   r!   r0   r5   r   r   r   r   <module>   s"   
