U
    Eh                     @   s   d dl m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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)NoneMetadataError)display_path)MYPY_CHECK_RUNNING)OptionalTuple)Message)Distributionc                 C   s4   | dkrdS t | }tdtt|}||kS )a  
    Check if the given Python version matches a "Requires-Python" specifier.

    :param version_info: A 3-tuple of ints representing a Python
        major-minor-micro version to check (e.g. `sys.version_info[:3]`).

    :return: `True` if the given Python version satisfies the requirement.
        Otherwise, return `False`.

    :raises InvalidSpecifier: If `requires_python` has an invalid format.
    NT.)r   ZSpecifierSetr   parsejoinmapstr)requires_pythonversion_infoZrequires_python_specifierZpython_version r   C./venv/lib/python3.8/site-packages/pip/_internal/utils/packaging.pycheck_requires_python   s
    
r   c                 C   s   d}t | tjr&| |r&| |}n0| dr@d}| |}ntdt| j d}|dkrht	| |t
 }|| | S )z
    :raises NoneMetadataError: if the distribution reports `has_metadata()`
        True but `get_metadata()` returns None.
    ZMETADATAzPKG-INFOzNo metadata found in %s N)
isinstancer   ZDistInfoDistributionhas_metadataget_metadataloggerZwarningr   locationr   r   Zfeedclose)distZmetadata_nameZmetadataZfeed_parserr   r   r   r   ,   s    


r   c                 C   s&   t | }|d}|dk	r"t|}|S )z_
    Return the "Requires-Python" metadata for a distribution, or None
    if not present.
    zRequires-PythonN)r   getr   )r   Zpkg_info_dictr   r   r   r   get_requires_pythonG   s
    
r!   c                 C   s2   |  dr.| dD ]}| r|   S qdS )NZ	INSTALLERr   )r   Zget_metadata_linesstrip)r   liner   r   r   get_installerX   s
    
r$   )Z
__future__r   ZloggingZemail.parserr   Zpip._vendorr   Zpip._vendor.packagingr   r   Zpip._internal.exceptionsr   Zpip._internal.utils.miscr   Zpip._internal.utils.typingr	   typingr
   r   Zemail.messager   Zpip._vendor.pkg_resourcesr   Z	getLogger__name__r   r   r   r!   r$   r   r   r   r   <module>   s    
