U
    ui<Q                  
   @  sH  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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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ddhZ%ddddddddddh
Z&ddhZ'dZ(e(ddide)*e&e'B ded dd!ed"d#d$id%ed&ddd'ed(dddd)d*d+d#diid,ed-ddd.d/ed0d1d2d3Z+e
jd4kred5d6d7d8e+d9< d:d; Z,d<d= Z-ej.d>d?d@dA Z/ej.dBdC Z0dDdE Z1dFdG Z2dHZ3dIdJ Z4dKdL Z5dMdN Z6ej78dOdPdQdRe(9dSdTfgdUdV Z:dWdX Z;dYdZ Z<d[d\ Z=d]Z>d^Z?ej7@d_d`da ZAdbdc ZBej7j8ddeCejDE eCejDdedfdg ZFdhdi ZGdjdk ZHdldm ZIdndo ZJdpdq ZKdrds ZLdtdu ZMdvdw ZNdxdy ZOdzd{ ZPej78d|d}d~gej7jQeR dkdddd ZSddddZTdd ZUdS )    )annotationsN)suppress)cleandoc)Mock)ZipFile)tags)bdist_wheelget_abi_tagremove_readonlyremove_readonly_exc)Distribution)SetuptoolsDeprecationWarning)	run_setupz&dummy_dist-1.0.dist-info/top_level.txt!dummy_dist-1.0.dist-info/METADATAzdummy_dist-1.0.dist-info/WHEELdummy_dist-1.0.dist-info/RECORDLICENSEzLICENSE.txtZLICENCEzLICENCE.txtZCOPYINGz
COPYING.mdZNOTICEz
NOTICE.rstZAUTHORSzAUTHORS.txtzLICENSE~zAUTHORS~zQfrom setuptools import setup

setup(
    name='dummy_dist',
    version='1.0',
)
	DUMMYFILE )setup.pyZlicensesu  
            from setuptools import setup

            setup(
                name="simple.dist",
                version="0.1",
                description="A testing distribution ☃",
                extras_require={"voting": ["beaglevote"]},
            )
            )r   Z
simpledistui  
            from setuptools import setup

            setup(
                name="complex-dist",
                version="0.1",
                description="Another testing distribution ☃",
                long_description="Another testing distribution ☃",
                author="Illustrious Author",
                author_email="illustrious@example.org",
                url="http://example.org/exemplary",
                packages=["complexdist"],
                setup_requires=["setuptools"],
                install_requires=["quux", "splort"],
                extras_require={"simple": ["simple.dist"]},
                entry_points={
                    "console_scripts": [
                        "complex-dist=complexdist:main",
                        "complex-dist2=complexdist:main",
                    ],
                },
            )
            __init__.pyzdef main(): return)r   Zcomplexdistz
            from setuptools import setup

            setup(
                name="headers.dist",
                version="0.1",
                description="A distribution with headers",
                headers=["header.h"],
            )
            )r   zheadersdist.pyzheader.hak  
            from setuptools import setup

            setup(
                name="testrepo",
                version="0.1",
                packages=["mypackage"],
                description="A test package with commas in file names",
                include_package_data=True,
                package_data={"mypackage.data": ["*"]},
            )
            )r   z	1,2,3.txt)r   data	mypackage)r   r   ztestrepo-0.1.0u  
            from setuptools import setup

            setup(
                name="unicode.dist",
                version="0.1",
                description="A testing distribution ☃",
                packages=["unicodedist"],
                zip_safe=True,
            )
            )r      åäö_日本語.py)r   Zunicodedistu   
            [metadata]
            name = utf8-metadata-dist
            version = 42
            author_email = "John X. Ãørçeč" <john@utf8.org>, Γαμα קּ 東 <gama@utf8.org>
            long_description = file: README.rst
               UTF-8 描述 説明)	setup.cfgz
README.rst)
dummy-distzsimple-distzcomplex-distzheaders-distzcommasinfilenames-distzunicode-distzutf8-metadata-distwin32u  
            from setuptools import Extension, setup

            setup(
                name="extension.dist",
                version="0.1",
                description="A testing distribution ☃",
                ext_modules=[
                    Extension(
                        name="extension", sources=["extension.c"], py_limited_api=True
                    )
                ],
            )
            z![bdist_wheel]
py_limited_api=cp32z5#define Py_LIMITED_API 0x03020000
#include <Python.h>)r   r   extension.czabi3extension-distc                  K  s^   t jdrtdddn
tddi}|  t|}|  D ]\}}t||| q<|	  |S )zHRun command in the same process so that it is easier to collect coverager   init)
stop_afterscript_namez%%build_meta%%)
ospathexistsr   r   parse_config_filesr   itemssetattrfinalize_options)kwargsZdist_objcmdattrvalue r,   E/tmp/pip-unpacked-wheel-9osl9suo/setuptools/tests/test_bdist_wheel.pybdist_wheel_cmd   s    

r.   c                 C  s&   |  |}tjjt| t|d |S )N)prefix)mktempjaracor"   buildEXAMPLESstr)tmp_path_factorynamebasedirr,   r,   r-   	mkexample   s    
r8   session)Zscopec              
   C  s|   |  d}|  d}tD ]J}t| |}|| }tj | tt|t|d	  W 5 Q R X qt
dd |dD S )Nr2   dist	bdist_dirdist_dirc                 s  s   | ]}t |V  qd S Nr4   .0fnamer,   r,   r-   	<genexpr>   s     zwheel_paths.<locals>.<genexpr>z*.whl)r0   r3   r8   r1   r"   ZDirectoryStackcontextr.   r4   runsortedglob)r5   
build_baser=   r6   Zexample_dir	build_dirr,   r,   r-   wheel_paths   s    


$rJ   c                 C  s
   t | dS )Nr   )r8   )r5   r,   r,   r-   
dummy_dist   s    rK   c                 C  s6   t dd | D }t| D ]}d|jkstqdS )z0Make sure entry point scripts are not generated.c                 s  s   | ]}d |kr|V  qdS )Zcomplex_distNr,   rA   r"   r,   r,   r-   rC      s      z"test_no_scripts.<locals>.<genexpr>z.data/scripts/N)nextr   infolistfilenameAssertionError)rJ   r"   entryr,   r,   r-   test_no_scripts   s    rR   c              	   C  sD   t dd | D }t|}|d}W 5 Q R X d |ks@td S )Nc                 s  s   | ]}d |kr|V  qdS )Zunicode_distNr,   rL   r,   r,   r-   rC      s      z&test_unicode_record.<locals>.<genexpr>z!unicode_dist-0.1.dist-info/RECORDr   )rM   r   readencoderP   )rJ   r"   zfrecordr,   r,   r-   test_unicode_record   s    
rW   u   Metadata-Version: 2.1
Name: helloworld
Version: 42
Author-email: "John X. Ãørçeč" <john@utf8.org>, Γαμα קּ 東 <gama@utf8.org>


UTF-8 描述 説明
c                 C  s   |  | |d }|d }|  |d jtdd |d   G dd dt}| }||| |d	 jdd}d
|ks~td|kstd|kstd S )Nzdummy_dist.egg-infodummy_dist.dist-infozPKG-INFOutf-8encodingzdependency_links.txtc                   @  s$   e Zd ZdZdd Zedd ZdS )z;test_preserve_unicode_metadata.<locals>.simpler_bdist_wheelz1Avoid messing with setuptools/distutils internalsc                 S  s   d S r>   r,   selfr,   r,   r-   __init__  s    zDtest_preserve_unicode_metadata.<locals>.simpler_bdist_wheel.__init__c                 S  s   g S r>   r,   r\   r,   r,   r-   license_paths   s    zItest_preserve_unicode_metadata.<locals>.simpler_bdist_wheel.license_pathsN)__name__
__module____qualname____doc__r^   propertyr_   r,   r,   r,   r-   simpler_bdist_wheel  s   re   METADATAu"   Author-email: "John X. Ãørçeč"u   Γαμα קּ 東 r   )	chdirmkdir
write_textUTF8_PKG_INFOtouchr   Zegg2dist	read_textrP   )monkeypatchtmp_pathZegginfodistinfore   cmd_objmetadatar,   r,   r-   test_preserve_unicode_metadata  s    

rr   c              	   C  sZ   | |  tt|d  td,}dd tD }t| t|B ksLt	W 5 Q R X d S )Nr<   $dist/dummy_dist-1.0-py3-none-any.whlc                 S  s   h | ]}d | qS zdummy_dist-1.0.dist-info/r,   r@   r,   r,   r-   	<setcomp>1  s    z(test_licenses_default.<locals>.<setcomp>)
rg   r.   r4   rE   r   DEFAULT_LICENSE_FILESsetnamelistDEFAULT_FILESrP   rK   rm   rn   wflicense_filesr,   r,   r-   test_licenses_default-  s    

r~   c              	   C  sf   |  djddd ||  tt|d  td$}dh}t| t	|B ksXt
W 5 Q R X d S )Nr   z*[metadata]
license_file=licenses/DUMMYFILErY   rZ   rs   rt   z"dummy_dist-1.0.dist-info/DUMMYFILEjoinpathri   rg   r.   r4   rE   r   rx   ry   rz   rP   r{   r,   r,   r-   test_licenses_deprecated7  s    
 

r   zconfig_file, config)r   z-[metadata]
license_files=licenses/*
  LICENSE)r   z,[metadata]
license_files=licenses/*, LICENSEr   )z2  license_files=['licenses/DUMMYFILE', 'LICENSE'])c              	   C  sn   |  |j|dd ||  tt|d  td,}dd dD }t| t	|B ks`t
W 5 Q R X d S )NrY   rZ   rs   rt   c                 S  s   h | ]}d | qS ru   r,   r@   r,   r,   r-   rv   V  s    z)test_licenses_override.<locals>.<setcomp>>   r   r   r   )rK   rm   rn   config_fileconfigr|   r}   r,   r,   r-   test_licenses_overrideD  s    

r   c              	   C  s\   |  djddd ||  tt|d  td}t| t	ksNt
W 5 Q R X d S )Nr   z[metadata]
license_files=
rY   rZ   rs   rt   r   )rK   rm   rn   r|   r,   r,   r-   test_licenses_disabled\  s    
 

r   c              	   C  sZ   | |  tt|dd  td*}t| }d|ks@td|ksLtW 5 Q R X d S )N2r<   build_numberz&dist/dummy_dist-1.0-2-py3-none-any.whlr   r   )rg   r.   r4   rE   r   rx   ry   rP   )rK   rm   rn   r|   	filenamesr,   r,   r-   test_build_numberf  s    

r   c              	   C  sL   | |  tjtdd tt|dd  W 5 Q R X tj	dsHt
d S )Nz.*universal is deprecatedmatchT)r<   	universalz(dist/dummy_dist-1.0-py2.py3-none-any.whl)rg   pytestZwarnsr   r.   r4   rE   r!   r"   r#   rP   )rK   rm   rn   r,   r,   r-   test_universal_deprecatedo  s    
r   a&  #include <Python.h>

static PyMethodDef methods[] = {
  { NULL, NULL, 0, NULL }
};

static struct PyModuleDef module_def = {
  PyModuleDef_HEAD_INIT,
  "extension",
  "Dummy extension module",
  -1,
  methods
};

PyMODINIT_FUNC PyInit_extension(void) {
  return PyModule_Create(&module_def);
}
u   from __future__ import annotations

from setuptools import Extension, setup

setup(
    name="extension.dist",
    version="0.1",
    description="A testing distribution ☃",
    ext_modules=[Extension(name="extension", sources=["extension.c"])],
)
zEonce:Config variable '.*' is unset.*, Python ABI tag may be incorrectc                 C  sh   | d}|d jtdd |d jtdd |d}|d}| | tt|t|d  d	S )
z=Test that building a binary wheel with the limited ABI works.Zextension_distr   rY   rZ   r   r2   r:   r;   N)	r0   ri   EXTENSION_SETUPPYEXTENSION_EXAMPLEr   rg   r.   r4   rE   )rm   rn   r5   
source_dirrI   r=   r,   r,   r-   test_limited_abi  s    



r   c                 C  sn   t |d}tt | | || t|D ],\}}}|D ]}ttj	||t
j q@q2t   d S )Ndummy)r4   r   shutilcopytreerg   r!   walkchmodr"   joinstatS_IREADr.   rE   )rK   rm   rn   r7   rootZ_dirsfilesrB   r,   r,   r-   test_build_from_readonly_tree  s    
r   zoption, compress_type)idsc              	   C  st   | |  tt||d  tdD}t| }d|ks@td|ksLt|jD ]}|j	|ksRtqRW 5 Q R X d S )N)r<   compressionrt   r   r   )
rg   r.   r4   rE   r   rx   ry   rP   filelistcompress_type)rK   rm   rn   optionr   r|   r   zinfor,   r,   r-   test_compression  s    


r   c              
   C  sL   | D ]B}t |0}tdd |jD }||}d|ks<tW 5 Q R X qd S )Nc                 s  s   | ]}|j d r|V  qdS )ZWHEELN)rO   endswith)rA   fnr,   r,   r-   rC     s      z.test_wheelfile_line_endings.<locals>.<genexpr>   )r   rM   r   rS   rP   )rJ   r"   r|   Z	wheelfileZwheelfile_contentsr,   r,   r-   test_wheelfile_line_endings  s
    

r   c              	   C  s\   | dd ||  tt|dd  td }|jD ]}|jdks:tq:W 5 Q R X d S )NSOURCE_DATE_EPOCH0Z2ar   z'dist/dummy_dist-1.0-2a-py3-none-any.whl)i     r   r   r   r   )	Zsetenvrg   r.   r4   rE   r   r   	date_timerP   )rK   rm   rn   r|   r   r,   r,   r-   test_unix_epoch_timestamps  s    


r   c                 C  s   |  tddd  |  tddd  t dks2t|  tddd d	 t d
ksTt|  tddd  t dkstt| td t dkstd S )Ninterpreter_namec                   S  s   dS )Ncpr,   r,   r,   r,   r-   <lambda>      z*test_get_abi_tag_windows.<locals>.<lambda>get_config_varc                 S  s   dS )Nzcp313-win_amd64r,   xr,   r,   r-   r     r   Zcp313gettotalrefcountc                   S  s   dS )Nr   r,   r,   r,   r,   r-   r     r   FZcp313dc                 S  s   dS )Nzcp313t-win_amd64r,   r   r,   r,   r-   r     r   Zcp313tdZcp313t)r&   r   	sysconfigr	   rP   sysdelattrrm   r,   r,   r-   test_get_abi_tag_windows  s    r   c                 C  s6   |  tddd  |  tddd  t dks2td S )Nr   c                   S  s   dS Nppr,   r,   r,   r,   r-   r     r   z+test_get_abi_tag_pypy_old.<locals>.<lambda>r   c                 S  s   dS )Nzpypy36-pp73r,   r   r,   r,   r-   r     r   Zpypy36_pp73)r&   r   r   r	   rP   r   r,   r,   r-   test_get_abi_tag_pypy_old  s    r   c                 C  s6   |  tddd  |  tddd  t dks2td S )Nr   c                 S  s   dS )Nzpypy37-pp73-darwinr,   r   r,   r,   r-   r     r   z+test_get_abi_tag_pypy_new.<locals>.<lambda>r   c                   S  s   dS r   r,   r,   r,   r,   r-   r     r   Zpypy37_pp73r&   r   r   r	   rP   r   r,   r,   r-   test_get_abi_tag_pypy_new  s    r   c                 C  s6   |  tddd  |  tddd  t dks2td S )Nr   c                 S  s   dS )Nz"graalpy231-310-native-x86_64-linuxr,   r   r,   r,   r-   r     r   z*test_get_abi_tag_graalpy.<locals>.<lambda>r   c                   S  s   dS )NZgraalpyr,   r,   r,   r,   r-   r     r   Zgraalpy231_310_nativer   r   r,   r,   r-   test_get_abi_tag_graalpy  s      r   c                 C  s6   |  tddd  |  tddd  t dks2td S )Nr   c                 S  s   dS )Nzunknown-python-310r,   r   r,   r,   r-   r     r   z+test_get_abi_tag_fallback.<locals>.<lambda>r   c                   S  s   dS )Nzunknown-pythonr,   r,   r,   r,   r-   r     r   Zunknown_python_310r   r   r,   r,   r-   test_get_abi_tag_fallback  s    r   c                 C  s   | |  tdd  dS )z>Ensure building on platforms with a space in the name succeed.zisilon onefs)	plat_nameN)rg   r.   rE   )rK   rm   r,   r,   r-   test_platform_with_space  s    
r   c                 C  s   |d }|   |d}|  |tj tjdr>dnd}tj	dk rtt
td}tj||d |j|kstn&t
td}tj||d	 |j|kst| rtd
S )zVerify onerr works as expectedZwith_readonlyfile.txtwinr   r   )      )Zside_effect)onerror)ZonexcN)rh   r   rk   r   r   r   r   platform
startswithversion_infor   r
   r   rmtreeZ
call_countrP   r   is_dir)rm   rn   r<   Z	some_fileZexpected_countZcount_remove_readonlyZcount_remove_readonly_excr,   r,   r-   test_rmtree_readonly  s    



r   c           
   
   C  s   |  | ddddd}| D ]0\}}t|ddd}|t| W 5 Q R X q t   d}tj	|spt
tt| }d	D ]}||kst
qd
D ]}	|	|kst
qdS )z
    Setuptools allow authors to set PEP 440's local version segments
    using ``egg_info.tag_build``. This should be reflected not only in the
    ``.whl`` file name, but also in the ``.dist-info`` and ``.data`` dirs.
    See pypa/setuptools#3997.
    z]
            from setuptools import setup
            setup(headers=["hello.h"])
            z
            [metadata]
            name = test
            version = 1.0

            [options.data_files]
            hello/world = file.txt

            [egg_info]
            tag_build = +what
            tag_date = 0
            r   )r   r   r   zhello.hwrY   rZ   z#dist/test-1.0+what-py3-none-any.whl)z"test-1.0+what.data/headers/hello.hz,test-1.0+what.data/data/hello/world/file.txtz test-1.0+what.dist-info/METADATAztest-1.0+what.dist-info/WHEEL)ztest.data/headers/hello.hz'test-1.0.data/data/hello/world/file.txtztest.dist-info/METADATAztest-1.0.dist-info/WHEELN)rg   r%   openwriter   r.   rE   r!   r"   r#   rP   rx   r   ry   )
rm   rn   r   filecontentfh
wheel_pathentriesexpectedZnot_expectedr,   r,   r-   test_data_dir_with_tag_build  s"    

r   zreported,expected)zlinux-x86_64
linux_i686)zlinux-aarch64linux_armv7lLinuxz!Only makes sense to test on Linux)reasonc                 C  sL   | tddd  t }t|}| |_d|_| \}}}||ksHtd S )Ncalcsizec                 S  s   dS )N   r,   r   r,   r,   r-   r   W  r   z'test_platform_linux32.<locals>.<lambda>F)	r&   struct
setuptoolsr   r   r   Zroot_is_pureZget_tagrP   )Zreportedr   rm   r:   r)   _actualr,   r,   r-   test_platform_linux32O  s    r   None)returnc              	   C  sz   dddd}t t | tjd W 5 Q R X | td| tjt	dd d	d l
}W 5 Q R X | tjd
 d	d l}d S )Nr4   )r6   c                 _  s(   | dkrt d|  tj| f||S )NctypeszNo module named )ModuleNotFoundError	importlib
__import__)r6   argsr(   r,   r,   r-   _fake_importa  s    z$test_no_ctypes.<locals>._fake_importzwheel.macosx_libfiler   zNo module named ctypesr   r   zsetuptools.command.bdist_wheel)r   KeyErrordelitemr   modulesr&   builtinsr   Zraisesr   Zwheel.macosx_libfilesetuptools.command.bdist_wheel)rm   r   wheelr   r,   r,   r-   test_no_ctypes`  s    
r   c              	   C  s   | |  |d }|  |d jddd |d jddd tt|t|d  d	d
h}td}t| }W 5 Q R X || t kst	dd |D rt	d S )NrX   rf   zname: helloworldrY   rZ   ZFOObar)r<   dist_info_dirzdummy_dist-1.0.dist-info/FOOr   rt   c                 S  s   g | ]}d t |kr|qS )zegg-infor?   rL   r,   r,   r-   
<listcomp>  s      z+test_dist_info_provided.<locals>.<listcomp>)
rg   rh   ri   r.   r4   rE   r   rx   ry   rP   )rK   rm   rn   ro   r   r|   Zfiles_foundr,   r,   r-   test_dist_info_providedv  s    

r   )V
__future__r   r   r   os.pathr!   r   r   r   r   r   r   
contextlibr   inspectr   Zunittest.mockr   zipfiler   Zjaraco.pathr1   r   	packagingr   r   r   r   r	   r
   r   Zsetuptools.distr   Zsetuptools.warningsr   distutils.corer   rz   rw   ZOTHER_IGNORED_FILESZSETUPPY_EXAMPLEdictfromkeysr3   r.   r8   ZfixturerJ   rK   rR   rW   rj   rr   r~   r   markZparametrizereplacer   r   r   r   r   r   filterwarningsr   r   listZsupported_compressionsr%   r   r   r   r   r   r   r   r   r   r   r   Zskipifsystemr   r   r   r,   r,   r,   r-   <module>   s0   	w




 

		

	7
 
