B
    £»ˆdò  ã               @  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ddœdd„Zddddœdd„Z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	|d
ƒ(}t
| ¡ ƒ\}	}|	s td |¡ƒ‚W dQ R X |dk	r¶|n|}|dk	r"|rÔ|d| 7 }||kr"t	|dƒ4}| ¡ }
t|
|ƒ}
| d¡ | ¡  | |
¡ W dQ R X t|	ƒ}t j ||› d|› d¡}t|dƒ&}td|› dddd | ˆ ¡ W d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	   ú@/var/www/html/venv/lib/python3.7/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   sB    




r/   Úbytesztuple[list[str], str | None])Ú	input_strÚreturnc             C  sn   g }d}x\|   ¡ D ]P}| d¡r@| | d¡d  ¡  d¡¡ q| d¡r| d¡d  ¡  d¡}qW ||fS )z£Read 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)r1   r,   r*   Úliner	   r	   r   r    L   s    
 
r    )r-   r   r2   c             C  s6   |rd|   d¡nd}t || ¡\} }|s2| |7 } | S )zûCompute 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
r4   ó    )ÚencodeÚBUILD_NUM_REÚsubn)r-   r   ÚreplacementZnum_replacedr	   r	   r   r#   ^   s    r#   z	list[str])r,   r2   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   )r8   )r   Útagr	   r	   r   ú	<setcomp>y   s    z"compute_tagline.<locals>.<setcomp>c             S  s   h | ]}|  d ¡d ’qS )r   r   )r8   )r   rA   r	   r	   r   rB   z   s    c             S  s   h | ]}|  d ¡d ’qS )r   é   )r8   )r   rA   r	   r	   r   rB   {   s    r   Ú.)Úsortedr   )r,   ZimplsZabiversÚ	platformsr	   r	   r   r'   s   s    r'   )Ú
__future__r   Úos.pathr
   ÚreZ	wheel.clir   Zwheel.wheelfiler   Úcompiler   r>   r/   r    r#   r'   r	   r	   r	   r   Ú<module>   s   

?