3
h`b                 @   s   d 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	m
Z
mZm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jZdZdd ZG dd deZdS )zWheels support.    )get_platformN)DistributionPathMetadataparse_version)canonicalize_name)PY3)r   )
pep425tags)write_requirementsz^(?P<project_name>.+?)-(?P<version>\d.*?)
    ((-(?P<build>\d.*?))?-(?P<py_version>.+?)-(?P<abi>.+?)-(?P<platform>.+?)
    )\.whl$ztry:
    __import__('pkg_resources').declare_namespace(__name__)
except ImportError:
    __path__ = __import__('pkgutil').extend_path(__path__, __name__)
c             C   s   xt j| D ]\}}}t jj|| }x6|D ].}t jj||}t jj|||}t j|| q*W xXttt|D ]D\}	}
t jj||
}t jj|||
}t jj	|snt j|| ||	= qnW qW x0t j| ddD ]\}}}| st
t j| qW dS )zDMove everything under `src_dir` to `dst_dir`, and delete the former.T)topdownN)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-ikjamrr1/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S )Wheelc             C   sT   t tjj|}|d kr$td| || _x$|j j D ]\}}t| || q8W d S )Nzinvalid wheel name: %r)	
WHEEL_NAMEr   r   basename
ValueErrorfilename	groupdictitemssetattr)selfr(   matchkvr!   r!   r"   __init__9   s    zWheel.__init__c             C   s&   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"   tagsA   s    
z
Wheel.tagsc                s$   t j  t fdd| j D dS )z5Is the wheel is compatible with the current platform?c             3   s   | ]}| krd V  qdS )TNr!   ).0t)supported_tagsr!   r"   	<genexpr>J   s    z&Wheel.is_compatible.<locals>.<genexpr>F)r   get_supportednextr8   )r,   r!   )r;   r"   is_compatibleG   s    zWheel.is_compatiblec             C   s*   t | j| j| jdkrd nt dj d S )Nany)project_nameversionr7   z.egg)r   rA   rB   r7   r   egg_name)r,   r!   r!   r"   rC   L   s    zWheel.egg_namec             C   sJ   x<|j  D ]0}tj|}|jdr
t|jt| jr
|S q
W tdd S )Nz
.dist-infoz.unsupported wheel format. .dist-info not found)namelist	posixpathdirnameendswithr   
startswithrA   r'   )r,   zfmemberrF   r!   r!   r"   get_dist_infoR   s    

zWheel.get_dist_infoc                s  t j| jd| j| jf }| jd| fdd}|d}|d}t|jd}td|  koxtd	k n  std
| t	j
| j| t	jj|tj|t|d dd ttt j  fdd jD }t	jj|d}t	j| t	jt	jj|dt	jj|d tt|dd}	t|	jddt	jj|d t	jj|t	jjd}
t	jj|
rt	jj|dd}t	j
| xVt	j|
D ]H}|jdrt	jt	jj|
| n t	jt	jj|
|t	jj|| qW t	j|
 x0t t	jjfddd#D D ]}t!|| q$W t	jjrPt	j t	jj|d}t	jj|r t"|}|j# j$ }W dQ R X xr|D ]j}t	jj|f|j$d  }t	jj|d!}t	jj|rt	jj| rt"|d"}|j%t& W dQ R X qW W dQ R X dS )$z"Install wheel as an egg directory.z%s-%sz%s.datac          	      sH   j tj | ,}tr&|j jdn|j }tjj j	|S Q R X d S )Nzutf-8)
openrE   r   r   readdecodeemailparserParserparsestr)namefpvalue)	dist_inforI   r!   r"   get_metadatab   s    z*Wheel.install_as_egg.<locals>.get_metadataWHEELMETADATAzWheel-Versionz1.0z2.0dev0z$unsupported wheel format version: %s)metadatac             S   s   d | _ t| S )N)markerstr)reqr!   r!   r"   raw_reqx   s    z%Wheel.install_as_egg.<locals>.raw_reqc          	      s6   i | ].}t tfd dt j|fD |qS )c             3   s   | ]}| kr|V  qd S )Nr!   )r9   r]   )install_requiresr!   r"   r<   ~   s   z2Wheel.install_as_egg.<locals>.<dictcomp>.<genexpr>)r   sortedmaprequires)r9   extra)distr_   r^   r!   r"   
<dictcomp>|   s   z(Wheel.install_as_egg.<locals>.<dictcomp>zEGG-INFOzPKG-INFO)r_   extras_require)attrsegg_infoNzrequires.txtscriptsz.pycc             3   s   | ]}t jj |V  qd S )N)r   r   r   )r9   r    )	dist_datar!   r"   r<      s   z'Wheel.install_as_egg.<locals>.<genexpr>dataheaderspurelibplatlibznamespace_packages.txtr1   z__init__.pyw)rk   rl   rm   rn   )'zipfileZipFiler(   rA   rB   rK   r   getr'   r   mkdir
extractallr   r   r   from_locationr   r   r`   ra   rb   extrasrenameSetuptoolsDistributiondictr	   get_command_objr   listdirrG   unlinkr   filterr#   rL   rM   r5   writeNAMESPACE_PACKAGE_INIT)r,   Zdestination_eggdirZdist_basenamerW   Zwheel_metadataZdist_metadatawheel_versionrf   rh   Z
setup_distZdist_data_scriptsZegg_info_scriptsentryr   Znamespace_packagesrT   modZmod_dirZmod_initr!   )rd   rj   rV   r_   r^   rI   r"   install_as_egg\   sr    
 










zWheel.install_as_eggN)	__name__
__module____qualname__r0   r8   r?   rC   rK   r   r!   r!   r!   r"   r$   7   s   
r$   )__doc__distutils.utilr   rO   r2   r   rE   rerp   pkg_resourcesr   r   r   Z!setuptools.extern.packaging.utilsr   Zsetuptools.extern.sixr   
setuptoolsrx   r   Zsetuptools.command.egg_infor	   compileVERBOSEr-   r%   r   r#   objectr$   r!   r!   r!   r"   <module>   s&   
