o
    DxMgT                     @  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	Z	ddl
Z
ddlmZmZ ddlmZ ddlmZ ddlmZ ddlmZmZmZmZmZ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) ddl*m+Z+ erddl,Z,ze-d W n e.y   ddlm/Z/ e/0  Y nw dBddZ1dCddZ2e3ej 4dd Z5dZ6dDdd Z7dEd!d"Z8dFd%d&Z9	'dGdHd,d-Z:dId.d/Z;dBd0d1Z<dCd2d3Z=dJd:d;Z>dKd>d?Z?G d@dA dAeZ@dS )LzI
Create a wheel (.whl) distribution.

A wheel is a built archive format.
    )annotationsN)BytesGenerator	Generator)EmailPolicy)iglob)rmtree)TYPE_CHECKINGCallableIterableLiteralSequencecast)ZIP_DEFLATED
ZIP_STORED)Command   )__version__)pkginfo_to_metadata)log)tagsversion)	WheelFilezsetuptools.logging)_setuptools_loggingnamestrreturnc                 C  s   t dd| S )zConvert an arbitrary string to a standard distribution name
    Any runs of non-alphanumeric/. characters are replaced with a single '-'.
    [^A-Za-z0-9.]+-)resubr    r"   2lib/python3.10/site-packages/wheel/_bdist_wheel.py	safe_name/   s   r$   r   c                 C  s@   zt t| W S  tjy   | dd} tdd|  Y S w )zB
    Convert an arbitrary string to a standard version string
     .r   r   )r   _packaging_versionZVersionZInvalidVersionreplacer   r    r   r"   r"   r#   safe_version6   s   r)   r&   zcp3\dboolc                   C  s   t ddkS )NP   )structcalcsizer"   r"   r"   r#   _is_32bit_interpreterG   s   r/   c                   C  s   dt jd  S )Npyr   )sysversion_infor"   r"   r"   r#   
python_tagK      r3   archive_root
str | Nonec                 C  s^   t  }|dr| durddlm} || |}nt r)|dkr#d}n|dkr)d}|d	d
S )z0Return our platform name 'win32', 'linux_x86_64'macosxNr   )calculate_macosx_platform_taglinux-x86_64z
linux-i686linux-aarch64zlinux-armv7lr   _)	sysconfigget_platform
startswithZmacosx_libfiler8   r/   r(   )r5   resultr8   r"   r"   r#   r=   O   s   r=   Tvarfallbackexpectedwarnc                 C  s:   t | }|du r|rtjd|  dtdd |S ||kS )zfUse a fallback value for determining SOABI flags if the needed config
    var is unset or unavailable.NzConfig variable 'z+' is unset, Python ABI tag may be incorrect   
stacklevel)r<   get_config_varwarningsrC   RuntimeWarning)r@   rA   rB   rC   valr"   r"   r#   get_flagc   s   

rK   c                  C  s  t d} t }| sO|dv rOttdrOd}d}d}tdttd|dkdr(d	}td
|dk|dko5tjdk dr?tjdk r?d}| t  | | | }|S | re|dkre| 	dred| 
dd  }|S | ry|dkry| 	dry| 
dd }|S | r|dkrd| 
ddd }|dddd}|S | r|dkrd| 
ddd }|dddd}|S | r| dddd}|S d}|S )zJReturn the ABI tag based on SOABI (if available) or emulate SOABI (PyPy2).ZSOABI)cppp
maxunicode ZPy_DEBUGZgettotalrefcountrL   )rC   dZWITH_PYMALLOC)      mZcpythonr   r   r   rM   NrD   r&   r;   ZgraalpyrQ   )r<   rG   r   interpreter_namehasattrr1   rK   r2   interpreter_versionr>   splitjoinr(   )ZsoabiimplrP   rS   uabir"   r"   r#   get_abi_tagt   sH   

	r\   c                 C     t | ddS Nr   r;   )r$   r(   r!   r"   r"   r#   
safer_name   r4   r_   c                 C  r]   r^   )r)   r(   r   r"   r"   r#   safer_version   r4   r`   funcCallable[..., object]pathexcinfo6tuple[type[Exception], Exception, types.TracebackType]Nonec                 C  s   t | ||d  d S )Nr   )remove_readonly_exc)ra   rc   rd   r"   r"   r#   remove_readonly   s   rh   exc	Exceptionc                 C  s   t |tj | | d S )N)oschmodstatS_IWRITE)ra   rc   ri   r"   r"   r#   rg      s   rg   c                   @  s   e Zd ZdZeedZdddded dfd	d
ddddddddd	efddde
  dfddgZg dZdd Zdd Zedd Zd5d!d"Zd#d$ Zd%e dfd6d)d*Zd7d,d-Zed8d/d0Zd9d3d4ZdS ):bdist_wheelzcreate a wheel distribution)Zstoreddeflated)z
bdist-dir=bz1temporary directory for creating the distributionz
plat-name=pz8platform name to embed in generated filenames (default: N))	keep-tempkzPkeep the pseudo-installation tree around after creating the distribution archive)z	dist-dir=rP   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=rZ   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=z3Python implementation compatibility tag (default: 'z'))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))rt   rv   rw   ry   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zipFrp   )	bdist_dirdata_dir	plat_nameplat_tagformat	keep_tempdist_diregginfo_dirroot_is_pure
skip_buildrw   ownergroupry   compressionr3   build_numberpy_limited_apiplat_name_supplied)selfr"   r"   r#   initialize_options   s&   
zbdist_wheel.initialize_optionsc                 C  sJ  | j d u r| dj}tj|d| _ | jd}|  | j	d | _
| jd u| _z	| j| j | _W n tyB   td| j d w d}| jdgt||R   | j pZ| j  | _| jrott| jsotdt d| jd}d	|v rtd
 |d	 d  }| dv rd| _| j d ur| j d d ! stdd S d S )NZbdistwheelegg_infoz.datazUnsupported compression: )r   r}   r   zpy-limited-api must match ''ry   z=The [wheel] section is deprecated. Use [bdist_wheel] instead.r   )1trueZyesTz1Build tag (build-number) must start with a digit.)"r{   Zget_finalized_command
bdist_baserk   rc   rX   distributionZget_command_objZensure_finalizedwheel_dist_namer|   r}   r   supported_compressionsr   KeyError
ValueErrorset_undefined_optionsrz   Zhas_ext_modulesZhas_c_librariesr   r   r   matchPY_LIMITED_API_PATTERNget_option_dictr   Zwarningstriplowerry   r   isdigit)r   r   r   Zneed_optionsr   rJ   r"   r"   r#   finalize_options
  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_   r   get_namer`   get_versionr   rX   )r   
componentsr"   r"   r#   r   5  s   
zbdist_wheel.wheel_dist_namer   tuple[str, str, str]c                   s(  | j r
tt| j n'| jrd n!| jr| jds| j nt| j t r1 dv r+d  dv r1d  	 
dd
d	d
d
d | jrT| jrJd}n| j}|d f}|S t }t }|| }| jrp|| drp| j}d}ntt 	 }|| f} fddt D }||v sJ d| |S )Nanyr7   )r9   Zlinux_x86_64Z
linux_i686)r:   Zlinux_aarch64Zlinux_armv7lr   r;   r&   r%   zpy2.py3ZnoneZcp3Zabi3c                   s   g | ]	}|j |j fqS r"   )Zinterpreterr[   ).0tr}   r"   r#   
<listcomp>r  s    z'bdist_wheel.get_tag.<locals>.<listcomp>z'would build wheel with unsupported tag )r   r   r   r}   r   r>   r=   r{   r/   r   r(   ry   r3   r   rT   rV   r   r\   Zsys_tags)r   rY   tagZ	impl_nameZimpl_verabi_tagZsupported_tagsr"   r   r#   get_tag@  sF   




zbdist_wheel.get_tagc                 C  s  |  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 |  \}}}	| j d| d| d|	 }
| js| j}ntj| j| |j}| dd t| j  dt | j!  d}tj| j|}| "| j#| | $| tj%| j&st'| j& tj| j&|
d }t(|d| j)}|*| W d    n1 sw   Y  t+| jdg ,ddj-t.j/d d  |f | j0sBtd| j  | j1sDt.j/dk r9t2| jt3d d S t2| jt4d d S d S d S ) Nbuild_scriptsZpythonT	build_extFZbuildinstall)Zreinit_subcommandsinstall_scripts)ZheadersZscriptsdataZpurelibZplatlibZinstall_rO   ntz..Zinstall_purelibZinstall_platlibzinstalling to r   Zinstall_egg_info)targetr   z
.dist-infoz.whlwZ
dist_filesro   z{}.{}rD   z	removing )rQ      )onerror)Zonexc)5Zreinitialize_command
executableforceZinplacer   Zrun_commandr{   rootcompileZwarn_dirZno_epsetattrrk   rc   rX   r|   r   normpathZinstall_libbaseZinstall_libr   r   infor   r   rw   _ensure_relativeZinstall_baser   r_   r   r   r`   r   egg2distr   write_wheelfileexistsr   makedirsr   r   Zwrite_filesgetattrappendr   r1   r2   r   dry_runr   rh   rg   )r   r   r   r   r   keyZbasedir_observedimpl_tagr   r~   Zarchive_basenamer5   Zdistinfo_dirnameZdistinfo_dirZ
wheel_pathZwfr"   r"   r#   runz  s|   






zbdist_wheel.runzbdist_wheel (wheelfile_baser   	generatorc                 C  s   ddl m} | }d|d< ||d< t| j |d< | jd ur$| j|d< |  \}}}|dD ]}|dD ]}	|dD ]}
d	||	|
f|d
< q>q7q0t	j
|d}td|  t|d}t|dd| W d    d S 1 svw   Y  d S )Nr   )Messagez1.0zWheel-Versionr   zRoot-Is-PurelibZBuildr&   r   ZTagZWHEELz	creating wb)Zmaxheaderlen)Zemail.messager   r   r   r   r   r   rW   rX   rk   rc   r   r   openr   flatten)r   r   r   r   msgr   r   r~   rY   r[   ZplatZwheelfile_pathfr"   r"   r#   r     s&   

"zbdist_wheel.write_wheelfilerc   c                 C  s6   t j|\}}|dd t jkr||dd   }|S )Nr   r   )rk   rc   
splitdrivesep)r   rc   driver"   r"   r#   r     s   zbdist_wheel._ensure_relativeIterable[str]c              	   C  s  t dkr| jjjp
dS t }| jd}t dkr#ttt | jjj}nd|v r0|d d 	 }nd}d|v rGt
jdtd	d
 ||d d  |sR|sRt|tsRd}|D ]3}t|D ],}|drktd| d qZ||vrtj|rtd| d| d || qZqT|S )N9   r"   metadata*   license_filesr   Zlicense_filezEThe "license_file" option is deprecated. Use "license_files" instead.rD   rE   )zLICEN[CS]E*zCOPYING*zNOTICE*zAUTHORS*~zignoring license file "z" as it looks like a backupzadding license file "z" (matched pattern "z"))setuptools_major_versionr   r   r   setr   r   r   r   rW   rH   rC   DeprecationWarningadd
isinstancelistr   endswithr   debugrk   rc   isfiler   )r   filesr   patternspatternrc   r"   r"   r#   license_paths  sB   


zbdist_wheel.license_pathsegginfo_pathdistinfo_pathc                 C  s  ddd}|| t j|s?ddl}t jt j|d	}||}d
| d}|r;t j|d }|d| d7 }t|t j|rPt	||}	t 
| n?t j|d}
t	||
}	tj||dd d t j|d}t|dd}|  }W d   n1 sw   Y  |s|| t j|d}tdddd}t|ddd}t||d|	 W d   n1 sw   Y  | jD ]}t j|}t|t j|| q|| dS )z:Convert an .egg-info directory into a .dist-info directoryrr   r   r   rf   c                 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)rk   rc   r   islinkisdirshutilr   unlink)rr   r"   r"   r#   adios#  s
   $z#bdist_wheel.egg2dist.<locals>.adiosr   Nz
*.egg-infozEgg metadata expected at z but not foundz (z) found - possible misnamed archive file?)PKG-INFOc                 S  s   h dS )N>   zrequires.txtznot-zip-safezSOURCES.txtr   r"   )xyr"   r"   r#   <lambda>I  s    z&bdist_wheel.egg2dist.<locals>.<lambda>)ignorezdependency_links.txtzutf-8)encodingZMETADATATF)utf8Zmangle_from_Zmax_line_lengthr   )Zpolicy)rr   r   r   rf   )rk   rc   r   globrX   dirnamebasenamer   r   r   mkdirr   copytreer   readr   r   r   r   r   copy)r   r   r   r   r   patpossibleerrZaltZpkg_infoZpkginfo_pathZdependency_links_pathZdependency_links_fileZdependency_linksZpkg_info_pathZserialization_policyoutZlicense_pathfilenamer"   r"   r#   r      sP   




zbdist_wheel.egg2dist)r   r   )r   r   r   r   )rc   r   r   r   )r   r   )r   r   r   r   )__name__
__module____qualname__descriptionr   r   r   r=   r   rX   r3   Zuser_optionsZboolean_optionsr   r   propertyr   r   r   wheel_versionr   r   r   r   r"   r"   r"   r#   ro      sZ    :+


:
[
,ro   )r   r   r   r   )r   r   r   r   )r   r*   )r   r   )r5   r6   r   r   )TT)
r@   r   rA   r*   rB   r*   rC   r*   r   r*   )r   r6   )ra   rb   rc   r   rd   re   r   rf   )ra   rb   rc   r   ri   rj   r   rf   )A__doc__Z
__future__r   rk   r   r   rm   r-   r1   r<   rH   Zemail.generatorr   r   Zemail.policyr   r   r   r   typingr   r	   r
   r   r   r   zipfiler   r   Z
setuptoolsr   rO   r   r  r   r   utilr   Zvendored.packagingr   r   r'   Z	wheelfiler   types
__import__ImportErrorr   Z	configurer$   r)   intrW   r   r   r/   r3   r=   rK   r\   r_   r`   rh   rg   ro   r"   r"   r"   r#   <module>   s^     






(


