
(h                  @   s  d  Z  d d l m Z d d l m 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 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 Z e	 j d
 e	 j  j Z d Z d d   Z Gd d   d  Z d S)zWheels support.    )get_platform)logN)parse_version)sys_tags)canonicalize_name)PY3)write_requirementsz^(?P<project_name>.+?)-(?P<version>\d.*?)
    ((-(?P<build>\d.*?))?-(?P<py_version>.+?)-(?P<abi>.+?)-(?P<platform>.+?)
    )\.whl$z8__import__('pkg_resources').declare_namespace(__name__)
c             C   sL  xt  j |   D] \ } } } t  j j | |   } xK | D]C } t  j j | |  } t  j j | | |  } t  j | |  q; Wx| t t t |    D]b \ }	 }
 t  j j | |
  } t  j j | | |
  } t  j j	 |  s t  j | |  | |	 =q Wq Wx@ t  j |  d d D]) \ } } } | s7t
  t  j |  qWd S)zDMove everything under `src_dir` to `dst_dir`, and delete the former.topdownTN)oswalkpathrelpathjoinrenamesreversedlist	enumerateexistsAssertionErrorrmdir)src_dirZdst_dirdirpathdirnames	filenamessubdirfsrcdstnd r    6/tmp/pip-build-kmztzv_d/setuptools/setuptools/wheel.pyunpack"   s    %%r"   c               @   s   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d d   Z d d   Z	 e
 d d    Z e
 d d    Z e
 d d    Z d S)Wheelc             C   st   t  t j j |   } | d  k r4 t d |   | |  _ x0 | j   j   D] \ } } t |  | |  qP Wd  S)Nzinvalid wheel name: %r)	
WHEEL_NAMEr
   r   basename
ValueErrorfilename	groupdictitemssetattr)selfr'   matchkvr    r    r!   __init__:   s    	zWheel.__init__c             C   s7   t  j |  j j d  |  j j d  |  j j d   S)z>List tags (py_version, abi, platform) supported by this wheel..)	itertoolsproduct
py_versionsplitabiplatform)r+   r    r    r!   tagsB   s    z
Wheel.tagsc                sB   t  d d   t   D    t   f d d   |  j   D d  S)z5Is the wheel is compatible with the current platform?c             s   s'   |  ] } | j  | j | j f Vq d  S)N)Zinterpreterr5   r6   ).0tr    r    r!   	<genexpr>M   s    z&Wheel.is_compatible.<locals>.<genexpr>c             3   s!   |  ] } |   k r d  Vq d S)TNr    )r8   r9   )supported_tagsr    r!   r:   N   s    F)setr   nextr7   )r+   r    )r;   r!   is_compatibleJ   s    zWheel.is_compatiblec             C   sD   t  j d |  j d |  j d |  j d k r0 d  n t    j   d S)Nproject_nameversionr6   anyz.egg)pkg_resourcesDistributionr?   r@   r6   r   egg_name)r+   r    r    r!   rD   P   s    	$zWheel.egg_namec             C   sg   xT | j    D]F } t j |  } | j d  r t |  j t |  j   r | Sq Wt d   d  S)Nz
.dist-infoz.unsupported wheel format. .dist-info not found)namelist	posixpathdirnameendswithr   
startswithr?   r&   )r+   zfmemberrG   r    r    r!   get_dist_infoV   s    zWheel.get_dist_infoc          
   C   s0   t  j |  j   } |  j | |  Wd QRXd S)z"Install wheel as an egg directory.N)zipfileZipFiler'   _install_as_egg)r+   destination_eggdirrJ   r    r    r!   install_as_egg`   s    zWheel.install_as_eggc             C   s~   d |  j  |  j f } |  j |  } d | } t j j | d  } |  j | | | |  |  j | |  |  j | |  d  S)Nz%s-%sz%s.datazEGG-INFO)	r?   r@   rL   r
   r   r   _convert_metadata_move_data_entries_fix_namespace_packages)r+   rP   rJ   Zdist_basename	dist_info	dist_dataegg_infor    r    r!   rO   e   s    
zWheel._install_as_eggc                s    f d d   } | d  } t  | j d   } t  d  | k oY t  d  k  n } | st t d |   t j |   j |  t j j |    t j	 j
 |  d t j |     d	 d
    t t t    j           f d d     j D } t j  |  t j t j j | d  t j j | d   t j	 d t d  d |   }	 t j j }
 t j t j  z, t |	 j d  d  t j j | d   Wd  t j |
  Xd  S)Nc          	      sf    j  t j   |    D } t r9 | j   j d  n	 | j   } t j j   j	 |  SWd  QRXd  S)Nzutf-8)
openrF   r   r   readdecodeemailparserParserparsestr)namefpvalue)rU   rJ   r    r!   get_metadataq   s    'z-Wheel._convert_metadata.<locals>.get_metadataWHEELzWheel-Versionz1.0z2.0dev0z$unsupported wheel format version: %smetadatac             S   s   d  |  _  t |   S)N)markerstr)reqr    r    r!   raw_req   s    	z(Wheel._convert_metadata.<locals>.raw_reqc                sG   i  |  ]= } t   f d  d   t    j | f   D  |  q S)c             3   s!   |  ] } |   k r | Vq d  S)Nr    )r8   rg   )install_requiresr    r!   r:      s   z5Wheel._convert_metadata.<locals>.<dictcomp>.<genexpr>)sortedmaprequires)r8   extra)distri   rh   r    r!   
<dictcomp>   s   	z+Wheel._convert_metadata.<locals>.<dictcomp>METADATAzPKG-INFOattrsri   extras_requirerW   zrequires.txt)r   getr&   r
   mkdir
extractallr   r   rB   rC   from_locationPathMetadatar   rj   rk   rl   extrasrename
setuptoolsdictr   _global_log	thresholdset_thresholdWARNr   get_command_obj)rJ   rP   rU   rW   rb   Zwheel_metadatawheel_versionZwheel_v1rr   Z
setup_distZlog_thresholdr    )rn   rU   ri   rh   rJ   r!   rR   o   sB    (		!	zWheel._convert_metadatac                sG  t  j j |       t  j j   d  } t  j j |  r t  j j |  d d  } t  j |  xs t  j |  D]b } | j d  r t  j t  j j | |   qq t  j t  j j | |  t  j j | |   qq Wt  j	 |  x= t
 t  j j   f d d   d D  D] } t | |   qWt  j j    rCt  j	    d
 S)z,Move data entries to their correct location.scriptszEGG-INFOz.pycc             3   s$   |  ] } t  j j   |  Vq d  S)N)r
   r   r   )r8   r   )rV   r    r!   r:      s   z+Wheel._move_data_entries.<locals>.<genexpr>dataheaderspurelibplatlibN)zdatazheaderszpurelibzplatlib)r
   r   r   r   rt   listdirrH   unlinkry   r   filterr"   )rP   rV   Zdist_data_scriptsZegg_info_scriptsentryr   r    )rV   r!   rS      s&    	zWheel._move_data_entriesc             C   s   t  j j |  d  } t  j j |  r t |   } | j   j   } Wd  QRXx | D] } t  j j | | j d   } t  j j | d  } t  j j |  s t  j |  t  j j |  sV t | d   } | j t	  Wd  QRXqV Wd  S)Nznamespace_packages.txtr0   z__init__.pyw)
r
   r   r   r   rX   rY   r4   rt   writeNAMESPACE_PACKAGE_INIT)rW   rP   Znamespace_packagesr`   modZmod_dirZmod_initr    r    r!   rT      s    	zWheel._fix_namespace_packagesN)__name__
__module____qualname__r/   r7   r>   rD   rL   rQ   rO   staticmethodrR   rS   rT   r    r    r    r!   r#   8   s   

@r#   )__doc__distutils.utilr   	distutilsr   r[   r1   r
   rF   rerM   rB   rz   r   Z setuptools.extern.packaging.tagsr   Z!setuptools.extern.packaging.utilsr   Zsetuptools.extern.sixr   Zsetuptools.command.egg_infor   typeZ__metaclass__compileVERBOSEr,   r$   r   r"   r#   r    r    r    r!   <module>   s,   