o
    !gU                     @  sd  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
mZmZ ddlmZ ddlmZ ddlmZmZ ddlmZmZ dd	lmZmZ dd
lm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dZ(e)e*dd Z+dZ,d0ddZ-d1ddZ.d2d d!Z/	"d3d4d'd(Z0d5d)d*Z1d/d+d,Z2G d-d. d.eZ3dS )6zI
Create a wheel (.whl) distribution.

A wheel is a built archive format.
    )annotationsN)IterableSequence)BytesGenerator)iglob)Literalcast)ZIP_DEFLATED
ZIP_STORED)tagsversion)	WheelFile   )Command__version___shutil)
safer_name)SetuptoolsDeprecationWarning   )egg_info)logr   strreturnc                 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
     .z[^A-Za-z0-9.]+-)r   _packaging_versionVersionInvalidVersionreplaceresubr    r#   ]/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/command/bdist_wheel.pysafe_version!   s   r%   r   zcp3\dboolc                   C  s   t ddkS )NP   )structcalcsizer#   r#   r#   r$   _is_32bit_interpreter2      r+   c                   C  s   dt jj S )Npy)sysversion_infomajorr#   r#   r#   r$   
python_tag6   r,   r1   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
startswithwheel.macosx_libfiler5   r+   r   )r2   resultr5   r#   r#   r$   r:   :   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 incorrectr   
stacklevel)r9   get_config_varwarningsrA   RuntimeWarning)r>   r?   r@   rA   valr#   r#   r$   get_flagN   s   

rH   c                  C  sj  t d} t }| s4|dv r4ttdr4d}d}tdttd|dkdr&d	}| t  | | }|S | rJ|dkrJ| d
rJd| 	dd  }|S | rg|dkrg| drg| 	dd }ttdre|d	7 }|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).SOABI)cppp
maxunicode Py_DEBUGgettotalrefcountrJ   )rA   dcpythonr   r   r   rK   Nr   r   r8   graalpy   )r9   rD   r   interpreter_namehasattrr.   rH   interpreter_versionr;   splitjoinr   )soabiimplrP   uabir#   r#   r$   get_abi_tag_   s<   

	r]   c                 C  s   t | ddS )Nr   r8   )r%   r   r"   r#   r#   r$   safer_version   s   r^   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 dfddde	  dfdddgZ
g dZd>ddZd>dd Zd>d!d"Zed?d$d%Zd@d'd(Zd)d* Zd+e d,fdAd/d0ZdBd2d3ZedCd5d6ZdDd9d:ZdEd<d=ZdS )Fbdist_wheelzcreate a wheel distribution)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=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])	universalNz4*DEPRECATED* make a universal wheel [default: false]zcompression=zzipfile compression (one of: z, z) [default: 'deflated']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])zdist-info-dir=Nzdirectory where a pre-generated dist-info can be found (e.g. as a result of calling the PEP517 'prepare_metadata_for_build_wheel' method))re   rg   rh   rj   r   Nonec                 C  s~   d | _ d| _d | _d | _d| _d| _d | _d | _d | _d | _	d| _
d| _d | _d | _d| _d| _t | _d | _d| _d| _d S )NrM   zipFra   )	bdist_dirdata_dir	plat_nameplat_tagformat	keep_tempdist_dirdist_info_diregginfo_dirroot_is_pure
skip_buildrh   ownergrouprj   compressionr1   build_numberpy_limited_apiplat_name_suppliedselfr#   r#   r$   initialize_options   s(   
zbdist_wheel.initialize_optionsc                 C  s  | j s| dj}tj|d| _ | jd u r#tt| j	
d}|  | jd | _t| j| _d}| jdgt||R   | j	 pF| j	  | _|   | j	d}d|v rmtd |d d  }| d	v rmd
| _| jrxtjdddd | jd ur| jd d   st!dd S d S )Nbdistwheelr   z.data)rs   ro   rw   rj   z=The [wheel] section is deprecated. Use [bdist_wheel] instead.r   )1trueyesTz#bdist_wheel.universal is deprecatedaj  
                With Python 2.7 end-of-life, support for building universal wheels
                (i.e., wheels that support both Python 2 and Python 3)
                is being obviated.
                Please discontinue using this option, or if you still need it,
                file an issue with pypa/setuptools describing your use case.
                )i        )due_datez1Build tag (build-number) must start with a digit.)"rm   get_finalized_command
bdist_baseospathrX   rt   r   egg_info_clsdistributionget_command_objensure_finalizedwheel_dist_namern   r&   ro   r}   set_undefined_optionsrl   has_ext_moduleshas_c_librariesrv   _validate_py_limited_apiget_option_dictr   rA   striplowerrj   r   emitr{   isdigit
ValueError)r   r   r   need_optionsr   rG   r#   r#   r$   finalize_options   s8   

zbdist_wheel.finalize_optionsc                 C  sH   | j sd S tt| j stdt dtdr"td| j dd S )Nzpy-limited-api must match ''Py_GIL_DISABLEDz`py_limited_api=z` not supported. `Py_LIMITED_API` is currently incompatible with `Py_GIL_DISABLED`.See https://github.com/python/cpython/issues/111506.)r|   r    matchPY_LIMITED_API_PATTERNr   r9   rD   r~   r#   r#   r$   r     s   
z$bdist_wheel._validate_py_limited_apir   c                 C  s8   t | j t| j g}| jr|| j d|S )z4Return distribution full name with - replaced with _r   )r   r   get_namer^   get_versionr{   appendrX   )r   
componentsr#   r#   r$   r   #  s   
zbdist_wheel.wheel_dist_nametuple[str, str, str]c                   s(  | j r
| jr
| 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anyr4   )r6   linux_x86_64
linux_i686)r7   linux_aarch64linux_armv7lr   r8   r   r   zpy2.py3nonecp3abi3c                   s   g | ]	}|j |j fqS r#   )interpreterr\   ).0tro   r#   r$   
<listcomp>`  s    z'bdist_wheel.get_tag.<locals>.<listcomp>z'would build wheel with unsupported tag )r}   ro   rv   r;   r:   rm   r+   r   r   rj   r1   r   rT   rV   r|   r   r]   sys_tags)r   rZ   tag	impl_nameimpl_verabi_tag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"rt#d| j"  t$%| j"| t&'| j( n| )| j(| | *| tj+| j,st-| j, tj| j,|
d }t.|d| / }|0| W d    n	1 sw   Y  t1| jdg 2dt3j4j5 dt3j4j6 |f | j7sOtd| j  | j8sQt&'| j d S d S d S )Nbuild_scriptspythonT	build_extFbuildinstall)reinit_subcommandsinstall_scripts)headersscriptsdatapurelibplatlibinstall_rM   ntz..install_purelibinstall_platlibzinstalling to r   install_egg_info)targetru   z
.dist-infozreusing z.whlw
dist_filesr_   r   z	removing )9reinitialize_command
executableforceinplacerw   run_commandrm   rootcompilewarn_dirno_epsetattrr   r   rX   rn   namenormpathinstall_libbaseinstall_librv   r   infor   r   rh   _ensure_relativeinstall_baser   r   r   r   r^   r   rt   debugshutilcopytreer   rmtreeru   egg2distwrite_wheelfileexistsrs   makedirsr   _zip_compressionwrite_filesgetattrr   r.   r/   r0   minorrr   dry_run)r   r   r   r   r   keybasedir_observedimpl_tagr   rp   archive_basenamer2   distinfo_dirnamedistinfo_dir
wheel_pathwfr#   r#   r$   runh  s~   






zbdist_wheel.runzsetuptools ()wheelfile_base	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-Version	GeneratorzRoot-Is-PurelibBuildr   r   TagWHEELz	creating wb)maxheaderlen)email.messager   r   rv   r   r{   r   rW   rX   r   r   r   r   openr   flatten)r   r   r   r   msgr   r   rp   rZ   r\   platwheelfile_pathfr#   r#   r$   r     s&   

"zbdist_wheel.write_wheelfiler   c                 C  s6   t j|\}}|dd t jkr||dd   }|S )Nr   r   )r   r   
splitdrivesep)r   r   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t  }| jd}t dkr%ttt | jjj}nd|v r2|d d 	 }nd}d|v rIt
jdtd	d
 ||d d  |sT|sTt|tsTd}|D ]3}t|D ],}|drmtd| d q\||vrtj|rtd| d| d || q\qV|S )N9   r#   metadata*   license_filesr   license_filezEThe "license_file" option is deprecated. Use "license_files" instead.r   rB   )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   rE   rA   DeprecationWarningadd
isinstancelistr   endswithr   r   r   r   isfiler   )r   filesr  patternspatternr   r#   r#   r$   license_paths  sB   



zbdist_wheel.license_pathsegginfo_pathdistinfo_pathc                 C  sF  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|d}	tj	||dd d t j|d}
t
|
dd}|  }W d   n1 snw   Y  |sy||
 t j|d}t|	| | jD ]}t j|}t|t j|| q|| dS )z:Convert an .egg-info directory into a .dist-info directoryrc   r   r   rk   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)r   r   r   islinkisdirr   r   unlink)rc   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>   SOURCES.txtnot-zip-saferequires.txtr#  r#   )xyr#   r#   r$   <lambda>5  s    z&bdist_wheel.egg2dist.<locals>.<lambda>)ignorezdependency_links.txtzutf-8)encodingMETADATA)rc   r   r   rk   )r   r   r   globrX   dirnamebasenamer   r   r   r  readr   copyr  )r   r  r  r"  r-  patpossibleerraltpkginfo_pathdependency_links_pathdependency_links_filedependency_linksmetadata_pathlicense_pathfilenamer#   r#   r$   r     s:   


zbdist_wheel.egg2distintc                 C  sP   t | jtr| j| j v r| jS | jt| j}|d ur |S td| j)NzUnsupported compression: )r  rz   r=  supported_compressionsvaluesgetr   r   )r   rz   r#   r#   r$   r   M  s   
zbdist_wheel._zip_compression)r   rk   r   r   )r   r   )r   r   r   r   r   rk   )r   r   r   r   )r   r
  )r  r   r  r   r   rk   )r   r=  )__name__
__module____qualname__descriptionr
   r	   r>  r:   rX   r1   user_optionsboolean_optionsr   r   r   propertyr   r   r   r   r   r   r  r   r   r#   r#   r#   r$   r_      s\    ?


/

:
_

,;r_   )r   r   r   r   )r   r&   rA  )r2   r3   r   r   )TT)
r>   r   r?   r&   r@   r&   rA   r&   r   r&   )r   r3   )4__doc__
__future__r   r   r    r   r)   r.   r9   rE   collections.abcr   r   email.generatorr   r-  r   typingr   r   zipfiler	   r
   	packagingr   r   r   wheel.wheelfiler   rM   r   r   r   _normalizationr   r   r   r   	distutilsr   r%   r=  rW   r  r   r+   r1   r:   rH   r]   r^   r_   r#   r#   r#   r$   <module>   s@    





#