o
    cÃaƒJ  ã                   @   sr  d 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 ddlmZ dd	lmZ dd
lmZm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% ej&dk r„ddl'm(Z) nddl'm)Z) ej*Z*ej+Z+dZ,dd„ Z-dd„ Z.d'dd„Z/dd„ Z0dd „ Z1d!d"„ Z2d#d$„ Z3G d%d&„ d&eƒZ4dS )(zI
Create a wheel (.whl) distribution.

A wheel is a built archive format.
é    N)ÚOrderedDict)ÚCommand)Úlog)ÚBytesIO)Úiglob)Úrmtree)Úget_config_var)ÚZIP_DEFLATEDÚ
ZIP_STOREDé   )Úwrite_pkg_info)Úcalculate_macosx_platform_tag)Úpkginfo_to_metadata)Útags)Ú	WheelFile)Ú__version__©é   )Ú	Generator)ÚBytesGeneratorzcp3\dc                   C   s   d  tjd ¡S )Nzpy{}r   )ÚformatÚsysÚversion_info© r   r   ú3/usr/lib/python3/dist-packages/wheel/bdist_wheel.pyÚ
python_tag+   ó   r   c                 C   s@   t j ¡ }| d¡r| durt| |ƒ}|dkrtjdkrd}|S )z0Return our platform name 'win32', 'linux_x86_64'ÚmacosxNÚlinux_x86_64éÿÿÿÚ
linux_i686)Ú	distutilsÚutilÚget_platformÚ
startswithr   r   Úmaxsize)Úarchive_rootÚresultr   r   r   r#   /   s   

r#   Tc                 C   s4   t | ƒ}|du r|rt d | ¡td¡ |S ||kS )zfUse a fallback value for determining SOABI flags if the needed config
    var is unset or unavailable.Nz?Config variable '{0}' is unset, Python ABI tag may be incorrecté   )r   ÚwarningsÚwarnr   ÚRuntimeWarning)ÚvarÚfallbackÚexpectedr*   Úvalr   r   r   Úget_flag;   s   
ÿr0   c                  C   sN  t dƒ} t ¡ }| sd|dv rdttdƒrdd}d}d}tdttdƒ|dkd�r'd	}td
|dk|dko4tjdk d�r>tjdk r>d}tdtjdkd|dkoMtjdk d�rWtjdk rWd}d|t ¡ |||f }|S | rv|  	d¡rvd|  
d¡d  }|S | r•|  	d¡r•d |  
d¡dd… ¡}| dd¡ dd¡}|S | r£|  dd¡ dd¡}|S d}|S )zXReturn the ABI tag based on SOABI (if available) or emulate SOABI
    (CPython 2, PyPy).ÚSOABI)ÚcpÚppÚ
maxunicodeÚ ÚPy_DEBUGÚgettotalrefcountr2   )r*   ÚdÚWITH_PYMALLOC)r   é   ÚmÚPy_UNICODE_SIZEiÿÿ é   )r   r   )r.   r*   Úuz
%s%s%s%s%szcpython-ú-r   zpypy-Nr(   Ú.Ú_)r   r   Úinterpreter_nameÚhasattrr   r0   r   r4   Úinterpreter_versionr$   ÚsplitÚjoinÚreplace)ÚsoabiÚimplr8   r;   r>   Úabir   r   r   Úget_abi_tagG   sP   þý
ü
ö	øüÿrK   c                 C   ó   t | ƒ dd¡S ©Nr?   rA   )Ú	safe_namerG   )Únamer   r   r   Ú
safer_nameo   r   rP   c                 C   rL   rM   )Úsafe_versionrG   )Úversionr   r   r   Úsafer_versions   r   rS   c                 C   s*   t t|d ƒƒ t |tj¡ | |ƒ d S )Nr   )ÚprintÚstrÚosÚchmodÚstatÚS_IWRITE)ÚfuncÚpathÚexcinfor   r   r   Úremove_readonlyw   s   r]   c                   @   sÒ   e Zd ZdZedefdefgƒZddddedƒ fd	d
dddddddd 	d 
e¡¡fdddeƒ  fddgZg d¢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ÚstoredÚdeflated)z
bdist-dir=Úbz1temporary directory for creating the distributionz
plat-name=Úpz;platform name to embed in generated filenames (default: %s)N)ú	keep-tempÚkzPkeep the pseudo-installation tree around after creating the distribution archive)z	dist-dir=r8   z-directory to put final built distributions in)ú
skip-buildNz2skip rebuilding everything (for testing/debugging))ÚrelativeNz7build the archive using relative paths (default: false))zowner=r>   z@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compression=z6zipfile compression (one of: {}) (default: 'deflated')z, zpython-tag=z7Python implementation compatibility tag (default: '%s'))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))rc   re   rf   rh   c                 C   sx   d | _ d | _d | _d | _d| _d| _d | _d | _d | _d | _	d| _
d | _d | _d| _d| _tƒ | _d | _d| _d| _d S )NÚzipFr`   )Ú	bdist_dirÚdata_dirÚ	plat_nameÚplat_tagr   Ú	keep_tempÚdist_dirÚegginfo_dirÚroot_is_pureÚ
skip_buildrf   ÚownerÚgrouprh   Úcompressionr   Úbuild_numberÚpy_limited_apiÚplat_name_supplied)Úselfr   r   r   Úinitialize_options°   s&   
zbdist_wheel.initialize_optionsc                 C   s0  | j d u r|  d¡j}tj |d¡| _ | jd | _| jd u| _	z	| j
| j | _W n ty7   td | j¡ƒ‚w d}| jdgt||ƒ¢R Ž  | j ¡ pO| j ¡  | _| jrbt t| j¡sbtdt ƒ‚| j d¡}d|v r‚t d¡ |d d	  ¡ }| ¡ d
v r‚d| _| jd ur”| jd d	…   ¡ s–tdƒ‚d S d S )NÚbdistÚwheelz.datazUnsupported compression: {})ro   rl   rr   zpy-limited-api must match '%s'rh   z=The [wheel] section is deprecated. Use [bdist_wheel] instead.r   )Ú1ÚtrueÚyesTz1Build tag (build-number) must start with a digit.)!rj   Úget_finalized_commandÚ
bdist_baserV   r[   rF   Úwheel_dist_namerk   rl   rx   Úsupported_compressionsru   ÚKeyErrorÚ
ValueErrorr   Úset_undefined_optionsri   ÚdistributionÚhas_ext_modulesÚhas_c_librariesrq   rw   ÚreÚmatchÚPY_LIMITED_API_PATTERNÚget_option_dictÚloggerr*   ÚstripÚlowerrh   rv   Úisdigit)ry   r�   Úneed_optionsr|   r/   r   r   r   Úfinalize_optionsÅ   s8   
ÿÿ
ÿ
ÿ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?   )rP   r‡   Úget_namerS   Úget_versionrv   rF   )ry   Ú
componentsr   r   r   r‚   é   s   ÿ
zbdist_wheel.wheel_dist_namec                    s  | j r| j‰ n#| jrd‰ n| jr| j d¡s| j‰ nt| jƒ‰ ˆ dv r*tjdkr*d‰ ˆ  ¡  	dd¡ 	dd¡‰ | jrI| j
r?d	}n| j}|d
ˆ f}|S t ¡ }t ¡ }|| }| jre||  d¡re| j}d}nttƒ ƒ ¡ }||ˆ f}‡ fdd„t ¡ D ƒ}||v s‡J d |¡ƒ‚|S )NÚanyr   )zlinux-x86_64r   r   r    r?   rA   r@   zpy2.py3ÚnoneÚcp3Úabi3c                    s   g | ]	}|j |jˆ f‘qS r   )ÚinterpreterrJ   )Ú.0Út©rl   r   r   Ú
<listcomp>  s    ÿz'bdist_wheel.get_tag.<locals>.<listcomp>z)would build wheel with unsupported tag {})rx   rl   rq   r$   r#   rj   r   r%   r�   rG   rh   r   r   rB   rD   rw   rU   rK   Úsys_tagsr   )ry   rI   ÚtagÚ	impl_nameÚimpl_verÚabi_tagÚsupported_tagsr   rž   r   Úget_tagò   s:   

ò

ÿzbdist_wheel.get_tagc                 C   sX  |   d¡}d|_d|_|   d¡}d|_| js|  d¡ | j ddd�}| j|_d|_| j|_d|_	|   d	¡}d|_
d
D ]}t|d| tj | j|¡ƒ q:d}tjdkrdtj tj | jd¡¡}| | _| _t|| jrkd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| j*ƒ�}| +|¡ W d   ƒ n1 söw   Y  t,| jdg ƒ -ddjt.j/d d… Ž |f¡ | j0�s(t d| j¡ | j1�s*t2| jt3d� d S d S d S )NÚbuild_scriptsÚpythonTÚ	build_extFÚbuildÚinstall)Úreinit_subcommandsÚinstall_scripts)ÚheadersÚscriptsÚdataÚpurelibÚplatlibÚinstall_r5   Úntz..Úinstall_purelibÚinstall_platlibzinstalling to %sz{}-{}-{}-{}Úinstall_egg_info)Útargetrp   z{}-{}.dist-infoz.whlÚwÚ
dist_filesr^   z{}.{}r(   zremoving %s)Úonerror)4Úreinitialize_commandÚ
executableÚforceÚinplacerr   Úrun_commandrj   ÚrootÚcompileÚwarn_dirÚno_epÚsetattrrV   r[   rF   rk   rO   ÚnormpathÚinstall_libbaseÚinstall_librq   rŽ   Úinfor¦   r   r‚   rf   Ú_ensure_relativeÚinstall_baser†   rP   r‡   r”   rS   r•   Úegg2distrp   Úwrite_wheelfileÚexistsro   Úmakedirsr   ru   Úwrite_filesÚgetattrÚappendr   r   rn   Údry_runr   r]   )ry   r§   r©   r«   r­   ÚkeyÚbasedir_observedÚimpl_tagr¤   rm   Úarchive_basenamer&   Údistinfo_dirnameÚdistinfo_dirÚ
wheel_pathÚwfr   r   r   Úrun"  s‚   


ÿ
þ
þ

þþ
ÿþÿýzbdist_wheel.runzbdist_wheel (ú)c                 C   s0  ddl m} tjdk rt|tƒs| d¡}|ƒ }d|d< ||d< t| jƒ ¡ |d< | j	d ur3| j	|d	< |  
¡ \}}}| d
¡D ]}| d
¡D ]}	| d
¡D ]}
d ||	|
f¡|d< qMqFq?tj |d¡}t d|¡ tƒ }t|dd� |¡ t|dƒ�}| | ¡  dd¡¡ W d   ƒ d S 1 s‘w   Y  d S )Nr   )ÚMessager   zutf-8z1.0zWheel-Versionr   zRoot-Is-PurelibÚBuildr@   r?   ÚTagÚWHEELzcreating %s)ÚmaxheaderlenÚwbs   
ó   )Úemail.messagerÞ   r   r   Ú
isinstancerU   Úencoderq   r�   rv   r¦   rE   rF   rV   r[   rŽ   rÉ   r   r   ÚflattenÚopenÚwriteÚgetvaluerG   )ry   Úwheelfile_baseÚ	generatorrÞ   ÚmsgrÖ   r¤   rm   rI   rJ   ÚplatÚwheelfile_pathÚbufferÚfr   r   r   rÍ   v  s.   


ÿÿ"ÿzbdist_wheel.write_wheelfilec                 C   s6   t j |¡\}}|dd… t jkr||dd …  }|S )Nr   r   )rV   r[   Ú
splitdriveÚsep)ry   r[   Údriver   r   r   rÊ   ’  s   zbdist_wheel._ensure_relativec                 C   sÎ   | j  d¡}tƒ }tdd„ | dd¡d  ¡ D ƒƒ}d|v r-t dt¡ | 	|d d ¡ d|vr7d|vr7d	}|D ]+}t
|ƒD ]$}| d
¡rMt d|¡ q?||vrctj |¡rct d||¡ | 	|¡ q?q9|S )NÚmetadatac                 S   s   h | ]}|’qS r   r   )rœ   Úoptionr   r   r   Ú	<setcomp>�  s    ÿz,bdist_wheel.license_paths.<locals>.<setcomp>Úlicense_files)r5   r5   r   Úlicense_filezEThe "license_file" option is deprecated. Use "license_files" instead.)zLICEN[CS]E*zCOPYING*zNOTICE*zAUTHORS*ú~z4ignoring license file "%s" as it looks like a backupz/adding license file "%s" (matched pattern "%s"))r‡   r�   ÚsetÚsortedÚgetrE   r)   r*   ÚDeprecationWarningÚaddr   ÚendswithrŽ   ÚdebugrV   r[   ÚisfilerÉ   )ry   rö   ÚfilesÚpatternsÚpatternr[   r   r   r   Úlicense_paths™  s.   ÿÿ

€ù	zbdist_wheel.license_pathsc                 C   sh  dd„ }||ƒ t j |¡s<ddl}t j t j |¡d¡}| |¡}d|f }|r8t j |d ¡}|d|f 7 }t|ƒ‚t j |¡rO|}	t	||ƒ}
t  
|¡ n>t j |d¡}	t	||	ƒ}
tj||d	d
„ d� t j |d¡}t|dƒ�}| ¡  ¡ }W d  ƒ n1 s‚w   Y  |s�||ƒ tt j |d¡|
ƒ | jD ]}t j |¡}t |t j ||¡¡ qš||ƒ dS )z:Convert an .egg-info directory into a .dist-info directoryc                 S   sP   t j | ¡rt j | ¡st j | ¡rt | ¡ dS t j | ¡r&t  | ¡ dS dS )z-Appropriately delete directory, file or link.N)rV   r[   rÎ   ÚislinkÚisdirÚshutilr   Úunlink)rb   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?)úPKG-INFOc                 S   s   h d£S )N>   úSOURCES.txtúnot-zip-safeúrequires.txtr  r   )ÚxÚyr   r   r   Ú<lambda>Û  s    z&bdist_wheel.egg2dist.<locals>.<lambda>)Úignorezdependency_links.txtÚrÚMETADATA)rV   r[   rÎ   ÚglobrF   ÚdirnameÚbasenamer…   r  r   Úmkdirr
  Úcopytreeré   Úreadr�   r   r  Úcopy)ry   Úegginfo_pathÚdistinfo_pathr  r  ÚpatÚpossibleÚerrÚaltÚpkginfo_pathÚpkg_infoÚdependency_links_pathÚdependency_links_fileÚdependency_linksÚlicense_pathÚfilenamer   r   r   rÌ   µ  s>   



ÿÿ
zbdist_wheel.egg2dist)Ú__name__Ú
__module__Ú__qualname__Údescriptionr   r
   r	   rƒ   r#   r   rF   r   Úuser_optionsÚboolean_optionsrz   r“   Úpropertyr‚   r¦   rÜ   Úwheel_versionrÍ   rÊ   r  rÌ   r   r   r   r   r^   }   sV    þÿÿýÿÿÝ($
0T
r^   )TT)5Ú__doc__r!   rV   r
  rX   r   rŠ   r)   Úcollectionsr   Údistutils.corer   r   rŽ   Úior   r  r   r   Ú	sysconfigr   Úzipfiler	   r
   Úpkg_resourcesÚpkginfor   Úmacosx_libfiler   rö   r   Úvendored.packagingr   Ú	wheelfiler   r5   r   r2  r   Úemail.generatorr   r   rN   rQ   rŒ   r   r#   r0   rK   rP   rS   r]   r^   r   r   r   r   Ú<module>   sJ    

(