î
!dÝV1  ã               @   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 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 e j d e j ƒ Z d d	 „  Z e j j d
 d „ Z d d „  Z e d k rü e ƒ  n  d S)é    N)Úmake_archive)Úrmtree)Úarchive_wheelfile)ÚArgumentParser)ÚiglobzX(^|/)(?P<name>[^/]+?)-(?P<ver>.+?)
    (-(?P<pyver>.+?))?(-(?P<arch>.+?))?.egg-info(/|$)c       
   	   C   sF  d } | r: t  j | ƒ } | s: t d | f ƒ ‚ q: n  |  j d ƒ \ } } } | sn t d |  f ƒ ‚ n  | d d … } | j d ƒ \ } } } | rÆ | j d ƒ rÆ | } | j d d ƒ } n d	 } | j d ƒ \ } } }	 | s t d |  f ƒ ‚ n  | r'| j d
 ƒ } | j d ƒ } n  t d
 | d | d |	 d | ƒ S)ax  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 validú-z"Installer filename %s is not validé   ÚpyÚ.Ú zpy2.py3ÚnameÚverÚarchÚpyveréüÿÿÿ)	Úegg_info_reÚsearchÚ
ValueErrorÚ	partitionÚ
rpartitionÚ
startswithÚreplaceÚgroupÚdict)
Zwininfo_nameÚegginfo_nameZegginfoZw_nameÚsepÚrestZrest2Zw_pyverZw_verZw_arch© r   ú4/tmp/pip-build-0jahl3lb/wheel/wheel/wininst2wheel.pyÚ
parse_info   s0    !r   c             C   s+  t  j |  ƒ } d  } x* | j ƒ  D] } d | k r" | } Pq" q" Wt t j j |  ƒ | ƒ } d } x0 | j ƒ  D]" } | j j	 d ƒ rp d } Pqp qp W| r¬ i d d 6} n i d d 6} d | }	 d	 |	 }
 g  } d } x| j ƒ  D]ó } | j j
 d
 d ƒ \ } } | j ƒ  } | j | d  ƒ } | d  k rH|
 | j ƒ  d
 } n  | j } | | } | | _ | j | =| | j | <| r‘| j | ƒ n  | sæ | j d ƒ r¯| } qÙd | k rÙ| j d
 ƒ \ } } } qÙqæ qæ Wt j d d ƒ } | j | | ƒ d } | d } | d pd j d d ƒ j d d ƒ } | rFd } n  | d k rg| j d d ƒ } n  d j |	 | | | f ƒ } t j j t j j ƒ  ƒ } | | _ t j j | d |	 ƒ } | j t j j | | ƒ | ƒ | j | d d ƒ| j | | ƒ t t j j | | ƒ | ƒ t  | ƒ d  S)Nz	.egg-infoTZPLATLIBFr   ÚpurelibÚplatlibz%(name)s-%(ver)sz%s.data/ú/é   z
.egg-info/ÚsuffixZ_b2wÚnoner   r   Úanyr
   Ú_r   r	   Úcpz%s.dist-infoÚ	generatorZwininst2wheel)!ÚzipfileÚZipFileÚnamelistr   ÚosÚpathÚbasenameÚinfolistÚfilenamer   ÚsplitÚlowerÚgetÚ
NameToInfoÚappendÚendswithr   ÚtempfileÚmkdtempÚ
extractallr   ÚjoinÚwheelÚbdist_wheelÚ	distutilsÚdistÚDistributionÚroot_is_purelibZegg2distZwrite_wheelfileZwrite_recordr   r   )r.   Údest_dirZbdwr   r1   ÚinforA   ÚzipinfoÚpathsZ	dist_infoÚdatadirÚmembersÚkeyr/   ZbasepathZoldnameZnewnamer   r'   ÚdirÚabir   r   Ú
wheel_nameZbwZdist_info_dirr   r   r   Úbdist_wininst2wheelZ   sv    

	
	
	"
(		rL   c              C   sæ   t  ƒ  }  |  j d d d d d ƒ|  j d d d t j j d d	 ƒ|  j d
 d d d ƒ|  j ƒ  } xy | j D]n } xe t | ƒ D]W } | j r® t	 j
 j d j | ƒ ƒ n  t | | j ƒ | j rƒ t	 j
 j d ƒ qƒ qƒ Wqp Wd  S)NÚ
installersÚnargsÚ*ÚhelpzInstallers to convertz
--dest-dirz-dÚdefaultz/Directory to store wheels (default %(default)s)z	--verbosez-vÚactionÚ
store_truez{0}... zOK
)r   Úadd_argumentr-   r.   ÚcurdirÚ
parse_argsrM   r   ÚverboseÚsysÚstdoutÚwriteÚformatrL   rB   )ÚparserÚargsÚpatÚ	installerr   r   r   Úmain«   s    			r`   Ú__main__)Úos.pathr-   ÚrerX   r8   r*   Zwheel.bdist_wheelr<   Údistutils.distr>   Zdistutils.archive_utilr   Úshutilr   Zwheel.archiver   Úargparser   Úglobr   ÚcompileÚVERBOSEr   r   r.   rU   rL   r`   Ú__name__r   r   r   r   Ú<module>   s$   HQ