o
    d                     @  st   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ZdddZdddZdddZdS )    )annotationsN)
WheelError)	WheelFilez6^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))\.dist-info$s   Build: (\d\w*)$	directorystrdest_dirbuild_number
str | Nonec                   s   fddt  D }t|dkrtd  |s"td  |d }t|d}d}t j |d	}t	|d
}t
| \}	}|	sOtd|W d   n1 sYw   Y  |durd|n|}|dur|rr|d| 7 }||krt	|d}| }
t|
|}
|d |  ||
 W d   n1 sw   Y  t|	}t j|| d| d}t|d}td| dddd |  W d   n1 sw   Y  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
   B/app/.heroku/python/lib/python3.10/site-packages/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WHEELrbzCNo tags present in {}/WHEEL; cannot determine target wheel filename-zrb+z.whlwzRepacking wheel as z... T)endflushOK)r   listdirlenr   r   r   groupr   r   open	read_tagsreadformatset_build_numberseektruncatewritecompute_tagliner   printZwrite_files)r   r   r   Zdist_info_dirsdist_info_dirZname_versionexisting_build_numberZwheel_file_pathftagswheel_file_contentZtagline
wheel_pathZwfr
   r   r   pack   sN   




	r1   	input_strbytesreturntuple[list[str], str | None]c                 C  sj   g }d}|   D ](}|dr||dd  d q|dr0|dd  d}q||fS )zRead tags from a string.

    :param input_str: A string containing one or more tags, separated by spaces
    :return: A list of tags and a list of build tags
    Ns   Tag:     r   asciis   Build: )
splitlines
startswithappendsplitrstripdecode)r2   r.   r,   liner
   r
   r   r"   L   s   
 
r"   r/   c                 C  s6   |r	d|  dnd}t|| \} }|s| |7 } | S )zCompute a build tag and add/replace/remove as necessary.

    :param wheel_file_content: The contents of .dist-info/WHEEL
    :param build_number: The build tags present in .dist-info/WHEEL
    :return: The (modified) contents of .dist-info/WHEEL
    zBuild: %s
r7       )encodeBUILD_NUM_REsubn)r/   r   replacementZnum_replacedr
   r
   r   r%   ^   s   r%   r.   	list[str]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     h | ]	}| d d qS )r   r   r;   r   tagr
   r
   r   	<setcomp>y       z"compute_tagline.<locals>.<setcomp>c                 S  rE   )r   r   rF   rG   r
   r
   r   rI   z   rJ   c                 S  rE   )r      rF   rG   r
   r
   r   rI   {   rJ   r   .)sortedr   )r.   ZimplsZabivers	platformsr
   r
   r   r)   s   s   "r)   )r   r   r   r   r   r	   )r2   r3   r4   r5   )r/   r3   r   r	   r4   r3   )r.   rD   r4   r   )
__future__r   os.pathr   reZ	wheel.clir   Zwheel.wheelfiler   compiler   rA   r1   r"   r%   r)   r
   r
   r
   r   <module>   s    



?
