U
    ™P^-  ã                   @   sx   d dl mZ d dlZd dlZd dlZd dlmZ erDd dlmZm	Z	 dd„ Z
dd„ Zd	d
„ Zdd„ Zdd„ Zdd„ ZdS )é    )Úabsolute_importN)ÚMYPY_CHECK_RUNNING)ÚOptionalÚTuplec                   C   s   t ƒ p
tƒ S )z9Returns glibc version string, or None if not using glibc.)Úglibc_version_string_confstrÚglibc_version_string_ctypes© r   r   ú:/tmp/pip-install-220asx0h/pip/pip/_internal/utils/glibc.pyÚglibc_version_string   s    r
   c               
   C   s8   zt  d¡ ¡ \} }W n tttfk
r2   Y dS X |S )z@Primary implementation of glibc_version_string using os.confstr.ÚCS_GNU_LIBC_VERSIONN)ÚosÚconfstrÚsplitÚAttributeErrorÚOSErrorÚ
ValueError)Ú_Úversionr   r   r	   r      s
    r   c                  C   sv   zddl } W n tk
r"   Y dS X |  d¡}z
|j}W n tk
rN   Y dS X | j|_|ƒ }t|tƒsr| 	d¡}|S )z=Fallback implementation of glibc_version_string using ctypes.r   NÚascii)
ÚctypesÚImportErrorÚCDLLÚgnu_get_libc_versionr   Úc_char_pÚrestypeÚ
isinstanceÚstrÚdecode)r   Úprocess_namespacer   Úversion_strr   r   r	   r   &   s    



r   c                 C   sH   t  d| ¡}|s$t d|  t¡ dS t| d¡ƒ|koFt| d¡ƒ|kS )Nz$(?P<major>[0-9]+)\.(?P<minor>[0-9]+)z=Expected glibc version with 2 components major.minor, got: %sFÚmajorÚminor)ÚreÚmatchÚwarningsÚwarnÚRuntimeWarningÚintÚgroup)r   Úrequired_majorÚminimum_minorÚmr   r   r	   Úcheck_glibc_versionF   s    ÿÿÿr,   c                 C   s   t ƒ }|d krdS t|| |ƒS )NF)r
   r,   )r)   r*   r   r   r   r	   Úhave_compatible_glibcW   s    r-   c                  C   s   t ƒ } | dkrdS d| fS dS )z“Try to determine the glibc version

    Returns a tuple of strings (lib, version) which default to empty strings
    in case the lookup fails.
    N)Ú r.   Úglibc)r
   )Úglibc_versionr   r   r	   Úlibc_verp   s    r1   )Ú
__future__r   r   r"   r$   Úpip._internal.utils.typingr   Útypingr   r   r
   r   r   r,   r-   r1   r   r   r   r	   Ú<module>   s    