U
    d7                     @  s^   d dl mZ d dlZd dlZd dlmZ d dlmZ e	dZ
e	dZdddd	d
dZdS )    )annotationsN)
WheelError)	WheelFilez6^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))\.dist-info$s   Build: (\d\w*)$strz
str | None)	directorydest_dirbuild_numberc              	     s@   fddt  D }t|dkr4td  n|sFtd  |d }t|d}d}t j |d	}t	|f}g }	|D ]D}
|

d
r|	|
dd   q|

dr|
dd  }q|	std|W 5 Q R X |dk	r|n|}|dk	r|r|d| 7 }||kr|r0d| dnd}t	|dH}| }t||\}}|sf||7 }|d |  || W 5 Q R X tdd |	D }tdd |	D }tdd |	D }dd|d|d|g}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	   2/tmp/pip-unpacked-wheel-v7gjrrul/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nameverNZWHEELzTag:  zBuild: zCNo tags present in {}/WHEEL; cannot determine target wheel filename-zBuild: %s
ascii    zrb+c                 S  s   h | ]}| d d qS )r   r   splitr   tagr	   r	   r   	<setcomp>O   s     zpack.<locals>.<setcomp>c                 S  s   h | ]}| d d qS )r   r   r   r   r	   r	   r   r   P   s     c                 S  s   h | ]}| d d qS )r      r   r   r	   r	   r   r   Q   s     .z.whlwzRepacking wheel as z... T)endflushOK)r
   listdirlenr   r   r   groupr   r   open
startswithappendr   rstripformatencodereadBUILD_NUM_REsubnseektruncatewritesortedr   printZwrite_files)r   r   r   Zdist_info_dirsdist_info_dirZname_versionZexisting_build_numberZwheel_file_pathftagslinereplacementZwheel_file_contentZnum_replacedZimplsZabivers	platformsZtagline
wheel_pathZwfr	   r   r   pack   sj    






 
"r>   )
__future__r   os.pathr
   reZ	wheel.clir   Zwheel.wheelfiler   compiler   r0   r>   r	   r	   r	   r   <module>   s   

