o
    ca%                     @   s   d dl Zd dlZd dl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 ddlmZmZ ed	ejZG d
d deZdd Zdd Zdd Zdd ZdS )    N)dist)iglob   )bdist_wheel)	WheelFile   )
WheelErrorrequire_pkgresourcesz]
    (?P<name>.+?)-(?P<ver>.+?)
    (-(?P<pyver>py\d\.\d+)
     (-(?P<arch>.+?))?
    )?.egg$c                   @   s   e Zd ZdZdZdd ZdS )_bdist_wheel_tagFNc                 C   s    | j r| jd ur| jS t| S )N)full_tag_suppliedfull_tagr   get_tag)self r   3/usr/lib/python3/dist-packages/wheel/cli/convert.pyr      s   
z_bdist_wheel_tag.get_tag)__name__
__module____qualname__r   r   r   r   r   r   r   r
      s    r
   c                 C   s$  t j| }t|}|std|| }tj	dd}t j
| r?t| }|| W d    n1 s9w   Y  n't | D ]!}t j| |}t j
|rZt|| qDt|t j|| qD|d }	|	rv|	dd }	|d< |d p{ddd	d
d	}
|
dkrd|	dd   nd}|d d u }|rtt }ntt }||_|	|_d|_|d pd|_|sd|_|	||
f|_t j|djdi |}|t j|d| |j|dd dj||
fi |}t t j||d}|!| W d    n	1 sw   Y  t"| d S )NzInvalid egg file name: {}_e2wsuffixpyver. archany_-cpr   noneTz{name}-{ver}.dist-infozEGG-INFO	egg2wheel	generatorz{name}-{ver}-{pyver}-{}-{}.whlwr   )#ospathbasenameegg_info_rematchr   format	groupdicttempfilemkdtempisfilezipfileZipFile
extractalllistdirjoinshutilcopy2copytreereplacer   r   Distributionr
   root_is_pure
python_tagplat_name_supplied	plat_namer   r   egg2distwrite_wheelfiler   write_filesrmtree)egg_pathdest_dirfilenamer(   egg_infodireggpthsrcr   r   abiroot_is_purelibbwdist_info_dir
wheel_namewfr   r   r   r    %   sP   
r    c           
      C   s   d}|rt |}|std|f | d\}}}|s#td| f |dd }|d\}}}|rA|drA|}|dd}nd	}|d\}}}	|sTtd| f |r`|d
}|d}|||	|dS )at  Extract metadata from filenames.

    Extracts the 4 metadataitems needed (name, version, pyversion, arch) from
    the installer filename and the name of the egg-info directory embedded in
    the zipfile (if any).

    The egginfo filename has the format::

        name-ver(-pyver)(-arch).egg-info

    The installer filename has the format::

        name-ver.arch(-pyver).exe

    Some things to note:

    1. The installer filename is not definitive. An installer can be renamed
       and work perfectly well as an installer. So more reliable data should
       be used whenever possible.
    2. The egg-info data should be preferred for the name and version, because
       these come straight from the distutils metadata, and are mandatory.
    3. The pyver from the egg-info data should be ignored, as it is
       constructed from the version of Python used to build the installer,
       which is irrelevant - the installer filename is correct here (even to
       the point that when it's not there, any version is implied).
    4. The architecture must be taken from the installer filename, as it is
       not included in the egg-info data.
    5. Architecture-neutral installers still have an architecture because the
       installer format itself (being executable) is architecture-specific. We
       should therefore ignore the architecture if the content is pure-python.
    Nz!Egg info filename %s is not validr   z"Installer filename %s is not validpyr   r   zpy2.py3namever)rP   rQ   r   r   )r'   search
ValueError	partition
rpartition
startswithr6   group)
wininfo_nameegginfo_nameegginfow_nameseprestrest2w_pyverw_verw_archr   r   r   parse_wininst_info[   s*   !


rb   c                 C   s  t | }d }| D ]
}d|v r|} nqttj| |}d}| D ]}|j	dr2d} nq&|r:ddi}nddi}d| }	d	|	 }
g }d}| D ]Q}|j
d
d\}}| }||d }|d u ro|
|  d
 }|j}|| }||_|j|= ||j|< |r|| |s|dr|}qNd|v r|d
\}}}qNtjdd}||| W d    n1 sw   Y  d}|d }|d pddddd}|rd}|dkr|dd}d|	|||f}|rtt }ntt }||_||_d|_|d pd|_|sd|_|||f|_tj|d|	 }| tj||| |j!|dd tj||}t"|d}|#| W d    n	1 sJw   Y  t$%| d S )Nz	.egg-infoTPLATLIBFpurelibr   platlibz%(name)s-%(ver)sz%s.data//r   z
.egg-info/_b2wr   r   r   r   r   r   r   r   rO   r   z%s.dist-infowininst2wheelr!   r#   )&r.   r/   namelistrb   r$   r%   r&   infolistrB   rV   splitlowerget
NameToInfoappendendswithrU   r+   r,   r0   r6   r2   r   r   r7   r
   r8   r9   r:   r;   r   r   r<   r=   r   r>   r3   r?   )r%   rA   bdwrY   rB   inforI   zipinfopaths	dist_infodatadirmemberskeyr&   basepatholdnamenewnamer\   r   rD   rH   r   r   rL   rJ   rK   
wheel_pathrM   r   r   r   rh      s   



3rh   c                 C   st   t d | D ]1}t|D ]*}tj|d dkrt}nt}|r+td| t	j
  ||| |r6td qqd S )Nzwheel convertr   z.eggz{}... OK)r	   r   r$   r%   splitextr    rh   printr)   sysstdoutflush)filesrA   verbosepat	installerconvr   r   r   convert   s   

r   )os.pathr$   rer3   r   r+   r.   	distutilsr   globr   r   	wheelfiler   r   r   r	   compileVERBOSEr'   r
   r    rb   rh   r   r   r   r   r   <module>   s&    6GZ