3
ÕZð]¥9  ã               @   s  d 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 ddlmZ dd	lmZ ddlZd
dlmZ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"Z"ej#Z#dZ$dd„ Z%dd„ Z&G dd„ deƒZ'dS )zI
Create a wheel (.whl) distribution.

A wheel is a built archive format.
é    N)Ú	Generator)ÚCommand)Úget_python_version)Úlog)Úiglob)Úrmtree)Úwarné   )Úget_abbr_implÚget_impl_verÚget_abi_tagÚget_platform)Úwrite_pkg_info)Úpkginfo_to_metadata)Ú	WheelFile)Ú
pep425tags)Ú__version__zcp3\dc             C   s   t | ƒjddƒS )Nú-Ú_)Ú	safe_nameÚreplace)Úname© r   ú2/tmp/pip-build-uspjrw0y/wheel/wheel/bdist_wheel.pyÚ
safer_name#   s    r   c             C   s   t | ƒjddƒS )Nr   r   )Úsafe_versionr   )Úversionr   r   r   Úsafer_version'   s    r   c               @   s°   e Zd ZdZd7dddeƒ  fd9d:d;d<d=d>d?dddeƒ d  fd@dAgZddddgZd#d$„ Zd%d&„ Z	e
d'd(„ ƒZd)d*„ Zd+d,„ Zd-e d. fd/d0„Zd1d2„ Ze
d3d4„ ƒZd5d6„ ZdS )BÚbdist_wheelzcreate a wheel distributionú
bdist-dir=Úbú1temporary directory for creating the distributionz
plat-name=Úpz;platform name to embed in generated filenames (default: %s)ú	keep-tempÚkz/keep the pseudo-installation tree around after z!creating the distribution archiveú	dist-dir=Údú-directory to put final built distributions inú
skip-buildNú2skip rebuilding everything (for testing/debugging)Úrelativeú7build the archive using relative paths (default: false)úowner=Úuú@Owner name used when creating a tar file [default: current user]úgroup=ÚgúAGroup name used when creating a tar file [default: current group]Ú	universalú'make a universal wheel (default: false)zpython-tag=z7Python implementation compatibility tag (default: py%s)r   úbuild-number=úqBuild number for this particular version. As specified in PEP-0427, this must start with a digit. [default: None]úpy-limited-api=ú?Python tag (cp32|cp33|cpNN) for abi3 wheel tag (default: false)c             C   sz   d | _ d | _d | _d | _d| _d| _d | _d | _d | _d | _	d| _
d | _d | _d| _dtƒ d  | _d | _d| _d| _d S )NÚzipFÚpyr   )Ú	bdist_dirÚdata_dirÚ	plat_nameÚplat_tagÚformatÚ	keep_tempÚdist_dirÚegginfo_dirÚroot_is_pureÚ
skip_buildr*   ÚownerÚgroupr2   r   Ú
python_tagÚbuild_numberÚpy_limited_apiÚplat_name_supplied)Úselfr   r   r   Úinitialize_optionsU   s$    zbdist_wheel.initialize_optionsc             C   sü   | j d kr&| jdƒj}tjj|dƒ| _ | jd | _| jd k	| _	d}| j
dt||ƒžŽ  | jjƒ ph| jjƒ  | _| jr�tjt| jƒ r�tdt ƒ‚| jjdƒ}d|krÐtjd	ƒ |d d
 jƒ }|jƒ dkrÐd| _| jd k	oì| jd d
… jƒ  � røtdƒ‚d S )NÚbdistÚwheelz.datar@   r<   rC   zpy-limited-api must match '%s'r2   z=The [wheel] section is deprecated. Use [bdist_wheel] instead.r	   Ú1ÚtrueÚyesTz1Build tag (build-number) must start with a digit.)r@   r<   rC   )rL   )rN   rO   rP   )r:   Úget_finalized_commandÚ
bdist_baseÚosÚpathÚjoinÚwheel_dist_namer;   r<   rI   Úset_undefined_optionsr8   ÚdistributionÚhas_ext_modulesÚhas_c_librariesrB   rH   ÚreÚmatchÚPY_LIMITED_API_PATTERNÚ
ValueErrorÚget_option_dictÚloggerr   ÚstripÚlowerr2   rG   Úisdigit)rJ   rR   Zneed_optionsrM   Úvalr   r   r   Úfinalize_optionsi   s(    


 zbdist_wheel.finalize_optionsc             C   s8   t | jjƒ ƒt| jjƒ ƒf}| jr.|| jf7 }dj|ƒS )z4Return distribution full name with - replaced with _r   )r   rX   Úget_namer   Úget_versionrG   rU   )rJ   Ú
componentsr   r   r   rV   ˆ   s
    zbdist_wheel.wheel_dist_namec             C   s  | j r| j}n.| jrd}n"| jp$tƒ }|dkr<tjdkr<d}|jddƒjddƒ}| jrt| jrbd	}n| j}|d
|f}n¤t	ƒ }t
ƒ }|| }| jr¨|| jdƒr¨| j}d}nttƒ ƒjƒ }|||f}tj| j rÎ|nd d�}| j�s ||d k�s td||d f ƒ‚||k�stdj|ƒƒ‚|S )NÚanyúlinux-x86_64Úlinux_x86_64iÿÿÿÚ
linux_i686r   r   Ú.zpy2.py3ÚnoneZcp3Zabi3)Zsupplied_platformr   z%s != %sz)would build wheel with unsupported tag {})rj   rk   )rI   r<   rB   r   ÚsysÚmaxsizer   r2   rF   r
   r   rH   Ú
startswithÚstrr   rb   r   Úget_supportedÚAssertionErrorr>   )rJ   r<   ÚimplÚtagZ	impl_nameÚimpl_verÚabi_tagÚsupported_tagsr   r   r   Úget_tag‘   s6    
"zbdist_wheel.get_tagc             C   s.  | j dƒ}d|_d|_| j dƒ}d|_| js6| jdƒ | j ddd�}| j|_d|_| j|_d|_	| j d	ƒ}d|_
x(d D ] }t|d| tjj| j|ƒƒ qvW d}tjdkrÌtjjtjj| jdƒƒ}| | _| _t|| jrÚdnd|ƒ tjd| jƒ | jdƒ | jƒ \}}}	dj| j|||	ƒ}
| j�s*| j}ntjj| j| j|jƒƒ}| jdd!ƒ djt| jj ƒ ƒt!| jj"ƒ ƒƒ}tjj| j|ƒ}| j#| j$|ƒ | j%|ƒ tjj&| j'ƒ�s²tj(| j'ƒ tjj| j'|
d ƒ}t)|dƒ�}|j*|ƒ W d Q R X t+| jdg ƒj,dt-ƒ |fƒ | j.�s*tjd| jƒ | j/�s*t0| jƒ d S )"NÚbuild_scriptsÚpythonTÚ	build_extFÚbuildÚinstall)Úreinit_subcommandsÚinstall_scriptsÚheadersÚscriptsÚdataÚpurelibÚplatlibÚinstall_Ú Úntz..Úinstall_purelibÚinstall_platlibzinstalling to %sz{}-{}-{}-{}Úinstall_egg_infoÚtargetrA   z{}-{}.dist-infoz.whlÚwÚ
dist_filesr   zremoving %s)r‚   rƒ   r„   r…   r†   )r�   rA   )1Úreinitialize_commandÚ
executableÚforceZinplacerC   Úrun_commandr:   ÚrootÚcompileÚwarn_dirZno_epÚsetattrrS   rT   rU   r;   r   ÚnormpathÚinstall_libbaseÚinstall_librB   r`   Úinforz   r>   rV   r*   Ú_ensure_relativeÚinstall_baserW   r   rX   rf   r   rg   Úegg2distrA   Úwrite_wheelfileÚexistsr@   Úmakedirsr   Zwrite_filesÚgetattrÚappendr   r?   Údry_runr   )rJ   r{   r}   r   r�   ÚkeyZbasedir_observedÚimpl_tagrx   r=   Zarchive_basenameZarchive_rootZdistinfo_dirnameZdistinfo_dirÚ
wheel_pathZwfr   r   r   Úrun·   sj    







zbdist_wheel.runzbdist_wheel (ú)c             C   sì   ddl m} |ƒ }d|d< ||d< t| jƒjƒ |d< | jd k	rH| j|d< | jƒ \}}}xN|jdƒD ]@}x:|jdƒD ],}	x&|jdƒD ]}
d	j||	|
fƒ|d
< q‚W qrW qbW t	j
j|dƒ}tjd|ƒ t|dƒ�}t|dd�j|ƒ W d Q R X d S )Nr   )ÚMessagez1.0zWheel-Versionr   zRoot-Is-PurelibZBuildrm   r   ZTagÚWHEELzcreating %srŽ   )Úmaxheaderlen)Úemail.messagerª   rr   rB   rb   rG   rz   ÚsplitrU   rS   rT   r`   r›   Úopenr   Úflatten)rJ   Zwheelfile_baseÚ	generatorrª   Úmsgr¦   rx   r=   ru   ÚabiÚplatZwheelfile_pathÚfr   r   r   rŸ   	  s     

 zbdist_wheel.write_wheelfilec             C   s6   t jj|ƒ\}}|dd… t jkr2||dd …  }|S )Nr   r	   )rS   rT   Ú
splitdriveÚsep)rJ   rT   Údriver   r   r   rœ     s    zbdist_wheel._ensure_relativec             C   s¼   | j jdƒ}tƒ }tdd„ |jddƒd jƒ D ƒƒ}d|krXtdtƒ |j|d d ƒ d|krld|krld}xJ|D ]B}x<t	|ƒD ]0}||kr€t
jj|ƒr€tjd||ƒ |j|ƒ q€W qrW |S )NÚmetadatac             S   s   h | ]}|’qS r   r   )Ú.0Úoptionr   r   r   ú	<setcomp>)  s   z,bdist_wheel.license_paths.<locals>.<setcomp>Zlicense_filesrˆ   r	   Zlicense_filezEThe "license_file" option is deprecated. Use "license_files" instead.úLICEN[CS]E*úCOPYING*úNOTICE*úAUTHORS*z/adding license file "%s" (matched pattern "%s"))rˆ   rˆ   )r½   r¾   r¿   rÀ   )rX   r_   ÚsetÚsortedÚgetr®   r   ÚDeprecationWarningÚaddr   rS   rT   Úisfiler`   r›   )rJ   r¹   ÚfilesÚpatternsÚpatternrT   r   r   r   Úlicense_paths%  s     
zbdist_wheel.license_pathsc             C   s\  dd„ }||ƒ t jj|ƒsxddl}t jjt jj|ƒdƒ}|j|ƒ}d|f }|rpt jj|d ƒ}|d|f 7 }t|ƒ‚t jj|ƒrž|}	t	||ƒ}
t j
|ƒ njt jj|dƒ}	t	||	ƒ}
tj||d	d
„ d� t jj|dƒ}t|dƒ�}|jƒ jƒ }W dQ R X |�s||ƒ tt jj|dƒ|
ƒ x2| jD ](}t jj|ƒ}tj|t jj||ƒƒ �q$W ||ƒ dS )z:Convert an .egg-info directory into a .dist-info directoryc             S   sL   t jj| ƒr2t jj| ƒ r2t jj| ƒr2tj| ƒ nt jj| ƒrHt j| ƒ dS )z-Appropriately delete directory, file or link.N)rS   rT   r    ÚislinkÚisdirÚshutilr   Úunlink)r"   r   r   r   Úadios?  s    &z#bdist_wheel.egg2dist.<locals>.adiosr   Nz
*.egg-infoz)Egg metadata expected at %s but not foundz- (%s found - possible misnamed archive file?)zPKG-INFOc             S   s   ddddhS )NzPKG-INFOzrequires.txtzSOURCES.txtznot-zip-safer   )ÚxÚyr   r   r   Ú<lambda>c  s   z&bdist_wheel.egg2dist.<locals>.<lambda>)Úignorezdependency_links.txtÚrÚMETADATA)rS   rT   r    ÚglobrU   ÚdirnameÚbasenamer^   rÆ   r   ÚmkdirrÍ   Úcopytreer¯   Úreadra   r   rÊ   Úcopy)rJ   Zegginfo_pathZdistinfo_pathrÏ   rÖ   ÚpatÚpossibleÚerrZaltZpkginfo_pathÚpkg_infoZdependency_links_pathZdependency_links_fileÚdependency_linksZlicense_pathÚfilenamer   r   r   rž   =  s:    



zbdist_wheel.egg2dist)r   r    r!   úPkeep the pseudo-installation tree around after creating the distribution archive)r#   r$   rã   )r%   r&   r'   )r(   Nr)   )r*   Nr+   )r,   r-   r.   )r/   r0   r1   )r2   Nr3   )r4   Nr5   )r6   Nr7   )Ú__name__Ú
__module__Ú__qualname__Údescriptionr   r   Úuser_optionsÚboolean_optionsrK   re   ÚpropertyrV   rz   r¨   Úwheel_versionrŸ   rœ   rÊ   rž   r   r   r   r   r   +   sL              	&Rr   )(Ú__doc__rS   rÍ   ro   r[   Úemail.generatorr   Údistutils.corer   Údistutils.sysconfigr   Ú	distutilsr   r`   rÖ   r   r   Úwarningsr   Úpkg_resourcesr   r
   r   r   r   Zpkginfor   r¹   r   Z	wheelfiler   rˆ   r   rë   r   r   r]   r   r   r   r   r   r   r   Ú<module>   s0   