B
    ˜#Y]%  ã               @   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 k	r| jS t | ¡S d S )N)Úfull_tag_suppliedÚfull_tagr   Úget_tag)Úself© r   ú0lib/python3.7/site-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 
| ¡rjt | ¡}| |¡ W d Q R X nRxPt  | ¡D ]B}t j | |¡}t j 
|¡r¢t ||¡ qvt |t j ||¡¡ qvW |d }	|	rÜ|	 dd¡ }	|d< |d pæd dd	¡ d
d	¡}
|
dkrd|	dd …  nd}|d d k}|r6tt ¡ ƒ}ntt ¡ ƒ}||_|	|_d|_|d p`d|_|s|d|_|	||
f|_t j |djf |Ž¡}| t j |d¡|¡ |j|dd dj||
f|Ž}t t j ||¡dƒ}| !|¡ W d Q R X t "|¡ d S )NzInvalid egg file name: {}Z_e2w)ÚsuffixÚpyverÚ.Ú ÚarchÚanyÚ_ú-Úcpr   ÚnoneTz{name}-{ver}.dist-infozEGG-INFOÚ	egg2wheel)Ú	generatorz{name}-{ver}-{pyver}-{}-{}.whlÚw)#ÚosÚpathÚbasenameÚegg_info_reÚmatchr   ÚformatÚ	groupdictÚtempfileÚmkdtempÚisfileÚzipfileÚZipFileÚ
extractallÚlistdirÚjoinÚshutilZcopy2ZcopytreeÚreplacer   r   ÚDistributionr
   Úroot_is_pureÚ
python_tagÚplat_name_suppliedÚ	plat_namer   r   Úegg2distÚwrite_wheelfiler   Úwrite_filesÚrmtree)Zegg_pathÚdest_dirÚfilenamer%   Zegg_infoÚdirZeggZpthÚsrcr   r   ÚabiÚroot_is_purelibÚbwÚdist_info_dirÚ
wheel_nameÚwfr   r   r   r   %   sJ    
r   c       
      C   sÎ   d}|r$t  |¡}|s$td|f ƒ‚|  d¡\}}}|sFtd| f ƒ‚|dd… }| d¡\}}}|r‚| d¡r‚|}| dd¡}nd	}| d¡\}}}	|s¨t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)rG   rH   r   r   )r$   ÚsearchÚ
ValueErrorÚ	partitionÚ
rpartitionÚ
startswithr1   Úgroup)
Zwininfo_nameÚegginfo_nameZegginfoZw_nameÚsepÚrestZrest2Zw_pyverZw_verZw_archr   r   r   Úparse_wininst_info[   s*    !


rR   c          	   C   s˜  t  | ¡^}d }x| ¡ D ]}d|kr|}P qW ttj | ¡|ƒ}d}x"| ¡ D ]}|j 	d¡rRd}P qRW |rzddi}nddi}d| }	d	|	 }
g }d}x²| ¡ D ]¦}|j 
d
d¡\}}| ¡ }| |d ¡}|d kræ|
| ¡  d
 }|j}|| }||_|j|= ||j|< |r| |¡ |s¤| d¡r2|}q¤d|kr¤| d
¡\}}}q¤W tjdd}| ||¡ W d Q R X d}|d }|d pˆd dd¡ dd¡}|r¤d}|dkrº| dd¡}d |	|||f¡}|ràt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 Q R X t$ %|¡ d S )Nz	.egg-infoTZPLATLIBFZpurelibr   Zplatlibz%(name)s-%(ver)sz%s.data/ú/r   z
.egg-info/Z_b2w)r   r   r   r   r   r   r   r   rF   r   z%s.dist-infoÚwininst2wheel)r   r    )&r+   r,   ZnamelistrR   r!   r"   r#   Zinfolistr<   rM   ÚsplitÚlowerÚgetZ
NameToInfoÚappendÚendswithrL   r(   r)   r-   r1   r/   r   r   r2   r
   r3   r4   r5   r6   r   r   r7   r8   r   r9   r0   r:   )r"   r;   ZbdwrO   r<   Úinfor@   ZzipinfoÚpathsZ	dist_infoZdatadirÚmembersÚkeyr#   ZbasepathZoldnameZnewnamerP   r   r=   r?   r   r   rC   rA   rB   Z
wheel_pathrD   r   r   r   rT   ¢   s€    



rT   c             C   s|   t dƒ xn| D ]f}x`t|ƒD ]T}tj |¡d dkr:t}nt}|rZtd |¡ƒ t	j
 ¡  |||ƒ |rtdƒ qW qW d S )Nzwheel convertr   z.eggz{}... ZOK)r	   r   r!   r"   Úsplitextr   rT   Úprintr&   ÚsysÚstdoutÚflush)Úfilesr;   ÚverboseZpatZ	installerZconvr   r   r   Úconvertü   s    


re   )Úos.pathr!   Úrer0   r`   r(   r+   Z	distutilsr   Zglobr   r   Z	wheelfiler   r   r   r	   ÚcompileÚVERBOSEr$   r
   r   rR   rT   re   r   r   r   r   Ú<module>   s"   
6GZ