B
    ˜#Y]¥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 | ƒ dd¡S )Nú-Ú_)Ú	safe_nameÚreplace)Úname© r   ú0lib/python3.7/site-packages/wheel/bdist_wheel.pyÚ
safer_name#   s    r   c             C   s   t | ƒ dd¡S )Nr   r   )Úsafe_versionr   )Úversionr   r   r   Úsafer_version'   s    r   c               @   s°   e Zd ZdZddddeƒ  fdddd	d
dddddeƒ d  fddg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#d$„Zd%d&„ Ze
d'd(„ ƒZd)d*„ ZdS )+Úbdist_wheelzcreate a wheel distribution)z
bdist-dir=Úbz1temporary directory for creating the distributionz
plat-name=Úpz;platform name to embed in generated filenames (default: %s))z	keep-tempÚkzPkeep the pseudo-installation tree around after creating the distribution archive)z	dist-dir=Údz-directory to put final built distributions in)z
skip-buildNz2skip rebuilding everything (for testing/debugging))ÚrelativeNz7build the archive using relative paths (default: false))zowner=Úuz@Owner name used when creating a tar file [default: current user])zgroup=ÚgzAGroup name used when creating a tar file [default: current group])Ú	universalNz'make a universal wheel (default: false)zpython-tag=Nz7Python implementation compatibility tag (default: py%s)r   )zbuild-number=NzqBuild number for this particular version. As specified in PEP-0427, this must start with a digit. [default: None])zpy-limited-api=Nz?Python tag (cp32|cp33|cpNN) for abi3 wheel tag (default: false)z	keep-tempz
skip-buildr#   r&   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Úgroupr&   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&|  d¡j}tj |d¡| _ | jd | _| jd k	| _	d}| j
dt||ƒžŽ  | j ¡ ph| j ¡  | _| jrŽt t| j¡sŽtdt ƒ‚| j d¡}d|krÎt d¡ |d d  ¡ }| ¡ d	krÎd
| _| jd k	rò| jd d…  ¡ sòtdƒ‚d S )NÚbdistÚwheelz.data)r/   r+   r2   zpy-limited-api must match '%s'r&   z=The [wheel] section is deprecated. Use [bdist_wheel] instead.r	   )Ú1ÚtrueZyesTz1Build tag (build-number) must start with a digit.)r;   )r)   Zget_finalized_commandÚ
bdist_baseÚosÚpathÚjoinÚwheel_dist_namer*   r+   r8   Úset_undefined_optionsr'   ÚdistributionZhas_ext_modulesZhas_c_librariesr1   r7   ÚreÚmatchÚPY_LIMITED_API_PATTERNÚ
ValueErrorÚget_option_dictÚloggerr   ÚstripÚlowerr&   r6   Úisdigit)r9   r?   Zneed_optionsr<   Úvalr   r   r   Úfinalize_optionsi   s(    


zbdist_wheel.finalize_optionsc             C   s8   t | j ¡ ƒt| j ¡ ƒf}| jr.|| jf7 }d |¡S )z4Return distribution full name with - replaced with _r   )r   rE   Úget_namer   Úget_versionr6   rB   )r9   Z
componentsr   r   r   rC   ˆ   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}| dd¡ dd¡}| jrt| jrbd}n| j}|d	|f}n t	ƒ }t
ƒ }|| }| jr¨||  d
¡r¨| j}d}nttƒ ƒ ¡ }|||f}tj| j rÎ|nd d}| jsü||d ksütd||d f ƒ‚||kstd |¡ƒ‚|S )NÚany)zlinux-x86_64Zlinux_x86_64iÿÿÿZ
linux_i686r   r   Ú.zpy2.py3ZnoneZcp3Zabi3)Zsupplied_platformr   z%s != %sz)would build wheel with unsupported tag {})r8   r+   r1   r   ÚsysÚmaxsizer   r&   r5   r
   r   r7   Ú
startswithÚstrr   rM   r   Zget_supportedÚAssertionErrorr-   )r9   r+   ÚimplÚtagZ	impl_nameZimpl_verÚabi_tagZsupported_tagsr   r   r   Úget_tag‘   s6    
 zbdist_wheel.get_tagc          	   C   s.  |   d¡}d|_d|_|   d¡}d|_| js6|  d¡ | j ddd}| j|_d|_| j|_d|_	|   d	¡}d|_
x(d
D ] }t|d| tj | j|¡ƒ qvW d}tjdkrÌtj tj | jd¡¡}| | _| _t|| jrÚdnd|ƒ t d| j¡ |  d¡ |  ¡ \}}}	d | j|||	¡}
| js*| j}ntj | j|  |j¡¡}|  dd¡ d t| j  ¡ ƒt!| j "¡ ƒ¡}tj | j|¡}|  #| j$|¡ |  %|¡ tj &| j'¡s²t (| j'¡ tj | j'|
d ¡}t)|dƒ}| *|¡ W d Q R X t+| jdg ƒ ,dt-ƒ |f¡ | j.s*t d| j¡ | j/s*t0| jƒ d S )NÚbuild_scriptsZpythonTÚ	build_extFZbuildÚinstall)Zreinit_subcommandsÚinstall_scripts)ZheadersZscriptsÚdataZpurelibZplatlibZinstall_Ú Úntz..Zinstall_purelibZinstall_platlibzinstalling to %sz{}-{}-{}-{}Zinstall_egg_info)Útargetr0   z{}-{}.dist-infoz.whlÚwZ
dist_filesr   zremoving %s)1Zreinitialize_commandÚ
executableZforceZinplacer2   Zrun_commandr)   ÚrootÚcompileZwarn_dirZno_epÚsetattrr@   rA   rB   r*   r   ÚnormpathZinstall_libbaseZinstall_libr1   rK   Úinfor]   r-   rC   r#   Ú_ensure_relativeZinstall_baserD   r   rE   rQ   r   rR   Úegg2distr0   Úwrite_wheelfileÚexistsr/   Úmakedirsr   Zwrite_filesÚgetattrÚappendr   r.   Zdry_runr   )r9   r^   r_   r`   ra   ÚkeyZbasedir_observedÚimpl_tagr\   r,   Zarchive_basenameZarchive_rootZdistinfo_dirnameZdistinfo_dirZ
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ƒ ¡ |d< | jd k	rH| j|d< |  ¡ \}}}xN| d¡D ]@}x:| d¡D ],}	x&| d¡D ]}
d	 ||	|
f¡|d
< q‚W qrW qbW t	j
 |d¡}t d|¡ t|dƒ}t|dd |¡ W d Q R X d S )Nr   )ÚMessagez1.0zWheel-Versionr   zRoot-Is-PurelibZBuildrT   r   ZTagZWHEELzcreating %srf   )Zmaxheaderlen)Zemail.messagerx   rX   r1   rM   r6   r]   ÚsplitrB   r@   rA   rK   rl   Úopenr   Zflatten)r9   Zwheelfile_baseÚ	generatorrx   Úmsgru   r\   r,   rZ   ZabiZplatZwheelfile_pathÚfr   r   r   ro   	  s     

 zbdist_wheel.write_wheelfilec             C   s6   t j |¡\}}|dd… t jkr2||dd …  }|S )Nr   r	   )r@   rA   Ú
splitdriveÚsep)r9   rA   Zdriver   r   r   rm     s    zbdist_wheel._ensure_relativec             C   s¼   | j  d¡}tƒ }tdd„ | dd¡d  ¡ D ƒƒ}d|krXtdtƒ | |d d ¡ d|krld|krld	}xJ|D ]B}x<t	|ƒD ]0}||kr€t
j |¡r€t d
||¡ | |¡ q€W qrW |S )NÚmetadatac             S   s   h | ]}|’qS r   r   )Ú.0Zoptionr   r   r   ú	<setcomp>)  s   z,bdist_wheel.license_paths.<locals>.<setcomp>Zlicense_files)rc   rc   r	   Zlicense_filezEThe "license_file" option is deprecated. Use "license_files" instead.)zLICEN[CS]E*zCOPYING*zNOTICE*zAUTHORS*z/adding license file "%s" (matched pattern "%s"))rE   rJ   ÚsetÚsortedÚgetry   r   ÚDeprecationWarningÚaddr   r@   rA   ÚisfilerK   rl   )r9   r€   ÚfilesZpatternsÚpatternrA   r   r   r   Úlicense_paths%  s     
zbdist_wheel.license_pathsc          	   C   s\  dd„ }||ƒ t j |¡sxddl}t j t j |¡d¡}| |¡}d|f }|rpt j |d ¡}|d|f 7 }t|ƒ‚t j |¡rž|}	t	||ƒ}
t  
|¡ njt j |d¡}	t	||	ƒ}
tj||d	d
„ d t j |d¡}t|dƒ}| ¡  ¡ }W dQ R X |s||ƒ tt j |d¡|
ƒ x2| jD ](}t j |¡}t |t j ||¡¡ q$W ||ƒ dS )z:Convert an .egg-info directory into a .dist-info directoryc             S   sJ   t j | ¡r0t j | ¡s0t j | ¡r0t | ¡ nt j | ¡rFt  | ¡ dS )z-Appropriately delete directory, file or link.N)r@   rA   rp   Ú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ÚrZMETADATA)r@   rA   rp   ÚglobrB   ÚdirnameÚbasenamerI   rˆ   r   ÚmkdirrŽ   Zcopytreerz   ÚreadrL   r   r‹   Úcopy)r9   Zegginfo_pathZdistinfo_pathr   r–   ZpatÚpossibleÚerrZaltZpkginfo_pathZpkg_infoZdependency_links_pathZdependency_links_fileZdependency_linksZlicense_pathÚfilenamer   r   r   rn   =  s:    



zbdist_wheel.egg2dist)Ú__name__Ú
__module__Ú__qualname__Zdescriptionr   r   Zuser_optionsZboolean_optionsr:   rP   ÚpropertyrC   r]   rv   Úwheel_versionro   rm   r‹   rn   r   r   r   r   r   +   s6   	&Rr   )(Ú__doc__r@   rŽ   rU   rF   Zemail.generatorr   Zdistutils.corer   Zdistutils.sysconfigr   Z	distutilsr   rK   r–   r   r   Úwarningsr   Zpkg_resourcesr   r
   r   r   r   Zpkginfor   r€   r   Z	wheelfiler   rc   r   r£   r   r   rH   r   r   r   r   r   r   r   Ú<module>   s0   