U
    ¸mœdÜ	  ã                	   @   s   d Z ddlZddlZddlZddlZddlmZmZmZ ddl	m
Z
 G dd„ deƒZeee dœd	d
„Ze ¡ eee dœdd„ƒZeee dœdd„Zedk�rddlZe ¡ Ze d¡sÄtdƒ‚edeƒ edeejƒƒ eddd� ee dde dd¡d ¡ƒD ]Zeedd� �qdS )z�PEP 656 support.

This module implements logic to detect if the currently running Python is
linked against musl, and what musl version is used.
é    N)ÚIteratorÚ
NamedTupleÚOptionalé   )ÚELFFilec                   @   s   e Zd ZU eed< eed< dS )Ú_MuslVersionÚmajorÚminorN)Ú__name__Ú
__module__Ú__qualname__ÚintÚ__annotations__© r   r   úM/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/packaging/_musllinux.pyr      s   
r   )ÚoutputÚreturnc                 C   sx   dd„ dd„ |   ¡ D ƒD ƒ}t|ƒdk s<|d d d… dkr@d S t d	|d
 ¡}|sXd S tt| d
¡ƒt| d¡ƒd�S )Nc                 S   s   g | ]}|r|‘qS r   r   ©Ú.0Únr   r   r   Ú
<listcomp>   s      z'_parse_musl_version.<locals>.<listcomp>c                 s   s   | ]}|  ¡ V  qd S )N)Ústripr   r   r   r   Ú	<genexpr>   s     z&_parse_musl_version.<locals>.<genexpr>é   r   é   ÚmuslzVersion (\d+)\.(\d+)r   )r   r	   )Ú
splitlinesÚlenÚreÚmatchr   r   Úgroup)r   ÚlinesÚmr   r   r   Ú_parse_musl_version   s     r#   )Ú
executabler   c              
   C   st   z$t | dƒ�}t|ƒj}W 5 Q R X W n tttfk
r@   Y dS X |dksRd|krVdS tj|gtjdd�}t	|j
ƒS )a`  Detect currently-running musl runtime version.

    This is done by checking the specified executable's dynamic linking
    information, and invoking the loader to parse its output for a version
    string. If the loader is musl, the output would be something like::

        musl libc (x86_64)
        Version 1.2.2
        Dynamic Program Loader
    ÚrbNr   T)ÚstderrÚuniversal_newlines)Úopenr   ÚinterpreterÚOSErrorÚ	TypeErrorÚ
ValueErrorÚ
subprocessÚrunÚPIPEr#   r&   )r$   ÚfÚldÚprocr   r   r   Ú_get_musl_version   s    r3   )Úarchr   c                 c   sH   t tjƒ}|dkrdS t|jddƒD ]}d|j› d|› d| › �V  q$dS )aT  Generate musllinux tags compatible to the current platform.

    :param arch: Should be the part of platform tag after the ``linux_``
        prefix, e.g. ``x86_64``. The ``linux_`` prefix is assumed as a
        prerequisite for the current platform to be musllinux-compatible.

    :returns: An iterator of compatible musllinux tags.
    NéÿÿÿÿÚ
musllinux_Ú_)r3   Úsysr$   Úranger	   r   )r4   Úsys_muslr	   r   r   r   Úplatform_tags6   s
    	
r;   Ú__main__zlinux-z	not linuxzplat:zmusl:ztags:ú )Úendz[.-]r7   ú-r5   z
      )Ú__doc__Ú	functoolsr   r-   r8   Útypingr   r   r   Z_elffiler   r   Ústrr#   Ú	lru_cacher3   r;   r
   Ú	sysconfigÚget_platformÚplatÚ
startswithÚAssertionErrorÚprintr$   ÚsubÚsplitÚtr   r   r   r   Ú<module>   s(   


"