3
™©Þ[‹	  ã               @   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 ej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_pathc             C   s>   | dkrdS t j| ƒ}tjdj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-65viz3iy/pip/pip/_internal/utils/packaging.pyÚcheck_requires_python   s
    

 r   c             C   sf   t | tjƒr"| jdƒr"| jdƒ}n,| jdƒr8| jdƒ}ntjdt| jƒƒ d}t	ƒ }|j
|ƒ |jƒ 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 | ƒ}|jdƒ}y8t|ƒsHtjd| j|djttt	j
d d… ƒƒf ƒ‚W n4 tjk
r~ } ztjd| j||ƒ d S d }~X 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_python3   s    
$r,   c             C   s2   | j dƒr.x"| jdƒD ]}|jƒ r|jƒ S qW dS )NÚ	INSTALLERr   )r   Úget_metadata_linesÚstrip)r#   Úliner   r   r   Úget_installerF   s
    
r1   )Ú
__future__r   Úloggingr   Úemail.parserr   Úpip._vendorr   Úpip._vendor.packagingr   r   Úpip._internalr   Úpip._internal.utils.miscr   Ú	getLoggerÚ__name__r   r   r   r,   r1   r   r   r   r   Ú<module>   s   
