U
    VQh                     @  s   d dl mZ d dlZd dlZd dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZ edZddd	d
dddZdddddZdS )    )annotationsN)BytesGenerator)BytesParser)
WheelError)	WheelFilez6^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))\.dist-info$strz
str | NoneNone)	directorydest_dirbuild_numberreturnc              	     s   fddt  D }t|dkr4td  n|sFtd  |d }t|d}t j |d}t	|d	D}t
tjjd
|}|dg }	|d}
|	std| dW 5 Q R X |dk	r|n|
}|dk	r,|d= |r||d< |d| 7 }||
kr,t	|d}t|dd| W 5 Q R X t|	}t j|| d| d}t|d&}td| dddd |  W 5 Q R X td dS )aB  Repack a previously unpacked wheel directory into a new wheel file.

    The .dist-info/WHEEL file must contain one or more tags so that the target
    wheel file name can be determined.

    :param directory: The unpacked wheel directory
    :param dest_dir: Destination directory (defaults to the current directory)
    c                   s0   g | ](}t jt j |rt|r|qS  )ospathisdirjoinDIST_INFO_REmatch).0fnr	   r   //tmp/pip-build-6059463i/wheel/wheel/cli/pack.py
<listcomp>   s    
zpack.<locals>.<listcomp>   z)Multiple .dist-info directories found in z#No .dist-info directories found in r   ZnameverWHEELrb)policyZTagZBuildzNo tags present in z./WHEEL; cannot determine target wheel filenameN-wb)maxheaderlenz.whlwzRepacking wheel as z... T)endflushOK)r   listdirlenr   r   r   groupr   r   openr   emailr   compat32parseget_allgetr   flattencompute_tagliner   printZwrite_files)r	   r
   r   Zdist_info_dirsZdist_info_dirZname_versionZwheel_file_pathfinfotagsZexisting_build_numberZtagline
wheel_pathZwfr   r   r   pack   sB    





r5   z	list[str])r3   r   c                 C  sX   t dd | D }t dd | D }t dd | D }dd|d|d|gS )zcCompute a tagline from a list of tags.

    :param tags: A list of tags
    :return: A tagline
    c                 S  s   h | ]}| d d qS )r   r   splitr   tagr   r   r   	<setcomp>R   s     z"compute_tagline.<locals>.<setcomp>c                 S  s   h | ]}| d d qS )r   r   r6   r8   r   r   r   r:   S   s     c                 S  s   h | ]}| d d qS )r      r6   r8   r   r   r   r:   T   s     r   .)sortedr   )r3   ZimplsZabivers	platformsr   r   r   r/   L   s    r/   )
__future__r   email.policyr)   os.pathr   reemail.generatorr   email.parserr   Z	wheel.clir   Zwheel.wheelfiler   compiler   r5   r/   r   r   r   r   <module>   s   
=