U
    „~$h»  ã                   @   sn   d Z ddlZddlmZmZmZ ddlmZ ddlm	Z
 ddlmZ ddlm	Z	 ddlmZ G dd	„ d	ƒZdS )
z`Represents a wheel file and provides access to the various parts of the
name that have meaning.
é    N)ÚDictÚIterableÚList)ÚTag)ÚInvalidWheelFilename)Úparse_wheel_filename)Ú
deprecatedc                   @   s†   e Zd ZdZe dej¡Zeddœdd„Z	e
e dœdd	„Ze
e ed
œdd„Ze
e eeef edœdd„Zee ed
œdd„ZdS )ÚWheelzA wheel filez¨^(?P<namever>(?P<name>[^\s-]+?)-(?P<ver>[^\s-]*?))
        ((-(?P<build>\d[^-]*?))?-(?P<pyver>[^\s-]+?)-(?P<abi>[^\s-]+?)-(?P<plat>[^\s-]+?)
        \.whl|\.dist-info)$N)ÚfilenameÚreturnc              
      s  ˆ j  |¡}|st|› d�ƒ‚|ˆ _| d¡ dd¡ˆ _| d¡}d|krªzt|ƒ W nF tk
rœ } z(t	d|›d|j
d › d	�d
ddd� W 5 d}~X Y nX | dd¡}|ˆ _| d¡ˆ _| d¡ d¡ˆ _| d¡ d¡ˆ _| d¡ d¡ˆ _‡ fdd„ˆ jD ƒˆ _dS )zX
        :raises InvalidWheelFilename: when the filename is invalid for a wheel
        z is not a valid wheel filename.ÚnameÚ_ú-ÚverzWheel filename zU is not correctly normalised. Future versions of pip will raise the following error:
r   z

zvto rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata)z25.1iŠ2  )ÚreasonÚreplacementÚgone_inÚissueNÚbuildÚpyverÚ.ÚabiÚplatc                    s0   h | ](}ˆ j D ]}ˆ jD ]}t|||ƒ’qqqS © )ÚabisÚplatsr   )Ú.0ÚxÚyÚz©Úselfr   ú>/tmp/pip-unpacked-wheel-g27rp152/pip/_internal/models/wheel.pyÚ	<setcomp>B   s        z!Wheel.__init__.<locals>.<setcomp>)Úwheel_file_reÚmatchr   r
   ÚgroupÚreplacer   r   ÚPackagingInvalidWheelNamer   ÚargsÚversionÚ	build_tagÚsplitÚ
pyversionsr   r   Ú	file_tags)r!   r
   Ú
wheel_infoÚ_versionÚer   r    r"   Ú__init__   s2    
ô
ÿzWheel.__init__)r   c                 C   s   t dd„ | jD ƒƒS )z4Return the wheel's tags as a sorted list of strings.c                 s   s   | ]}t |ƒV  qd S ©N)Ústr©r   Útagr   r   r"   Ú	<genexpr>H   s     z0Wheel.get_formatted_file_tags.<locals>.<genexpr>)Úsortedr.   r    r   r   r"   Úget_formatted_file_tagsF   s    zWheel.get_formatted_file_tags)Útagsr   c                    s<   zt ‡ fdd„t|ƒD ƒƒW S  tk
r6   tƒ ‚Y nX dS )aÜ  Return the lowest index that one of the wheel's file_tag combinations
        achieves in the given list of supported tags.

        For example, if there are 8 supported tags and one of the file tags
        is first in the list, then return 0.

        :param tags: the PEP 425 tags to check the wheel against, in order
            with most preferred first.

        :raises ValueError: If none of the wheel's file tags match one of
            the supported tags.
        c                 3   s    | ]\}}|ˆ j kr|V  qd S r3   )r.   )r   ÚiÚtr    r   r"   r7   X   s     
 z*Wheel.support_index_min.<locals>.<genexpr>N)ÚnextÚ	enumerateÚStopIterationÚ
ValueError©r!   r:   r   r    r"   Úsupport_index_minJ   s    zWheel.support_index_min)r:   Útag_to_priorityr   c                    s   t ‡ fdd„| jD ƒƒS )a¨  Return the priority of the most preferred tag that one of the wheel's file
        tag combinations achieves in the given list of supported tags using the given
        tag_to_priority mapping, where lower priorities are more-preferred.

        This is used in place of support_index_min in some cases in order to avoid
        an expensive linear scan of a large list of tags.

        :param tags: the PEP 425 tags to check the wheel against.
        :param tag_to_priority: a mapping from tag to priority of that tag, where
            lower is more preferred.

        :raises ValueError: If none of the wheel's file tags match one of
            the supported tags.
        c                 3   s   | ]}|ˆ krˆ | V  qd S r3   r   r5   ©rC   r   r"   r7   m   s     z0Wheel.find_most_preferred_tag.<locals>.<genexpr>)Úminr.   )r!   r:   rC   r   rD   r"   Úfind_most_preferred_tag\   s    ÿzWheel.find_most_preferred_tagc                 C   s   | j  |¡ S )zŽReturn whether the wheel is compatible with one of the given tags.

        :param tags: the PEP 425 tags to check the wheel against.
        )r.   Ú
isdisjointrA   r   r   r"   Ú	supportedq   s    zWheel.supported)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚreÚcompileÚVERBOSEr$   r4   r2   r   r9   r   ÚintrB   r   rF   r   ÚboolrH   r   r   r   r"   r	      s   ü* 
þr	   )rL   rM   Útypingr   r   r   Úpip._vendor.packaging.tagsr   Úpip._vendor.packaging.utilsr   r(   r   Úpip._internal.exceptionsÚpip._internal.utils.deprecationr   r	   r   r   r   r"   Ú<module>   s   