o
    5h@I                     @  s  U 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ZddlZddl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 ddlmZ de fddddddddfddddddddfddddddddfdddd d!d"d#dffZ!ej"j#d$e!d%d& e!D d'd(d) Z$ej%dd*d+Z&d,d- Z'd.d/ Z(d0d1 Z)d2d3 Z*G d4d5 d5Z+e,d6d7d8d9iie,d7gd:e(d;g d<d8gd=id>e,d?e,d@dAdBe,dCdDedEie,dFdDgfgdGe(d;g d<dDgdHid>e,dIdJedKie,e+dLdIdJgdMgdNe(dOdPdQg d<igid>e,dRdSedTie,dSgdUe(d;dSdQg d<igid>e,dVedWedXdYe,dZd[gd\e(d;dQd]d^d_d`dadZd[gigiid>e,dbdce(d;dQg ddiiededfe,dgdhe
j-diedjdke,dldme
j-dndoe,dpdqdrdsiedtdue,dvdrdwe
j-dxidyedz d{e,d|d}drd~ieddue,dd7dd8d9iiie,d7gdgde(d;ddQg did7d8dd8gigigid>e,ddd8diie,dgdgde(d;ddQg didd8gigid>e,dd7d9dDedidie,d7gddgfgde(d;g d<d8dFdDgigd=id>fZ.de/d< ej"j#de.dd& e.D d'dd Z0dd Z1dd Z2dd Z3dS )zwheel tests    )annotationsN)Anypath	parse_tag)metadata)Wheel   )tempdir)DALS)get_config_var)get_platformzinvalid.whlz&simplewheel-2.0-1-py2.py3-none-any.whlZsimplewheelz2.01zpy2.py3Znoneany)project_nameversionbuild
py_versionabiplatformz$simple.dist-0.1-py2.py3-none-any.whlzsimple.distz0.1z example_pkg_a-1-py3-none-any.whlZexample_pkg_aZpy3z9PyQt5-5.9-5.9.1-cp35.cp36.cp37-abi3-manylinux1_x86_64.whlZPyQt5z5.9z5.9.1zcp35.cp36.cp37Zabi3Zmanylinux1_x86_64filenameinfoc                 C     g | ]}|d  qS )r    .0tr   r   ;lib/python3.10/site-packages/setuptools/tests/test_wheel.py
<listcomp>P       r    )Zidsc                   sl   t |r!t| t|  W d    d S 1 sw   Y  d S t|   fdd| D |ks4J d S )Nc                   s   i | ]}|t  |qS r   )getattr)r   kwr   r   
<dictcomp>X   s    z#test_wheel_info.<locals>.<dictcomp>)inspectZisclasspytestraisesr	   keysr   r   r$   r   test_wheel_infoO   s   


"r+   c                 k  s    dt d| di}| r||  t )}t|| tjtj	dddf|d t

tj|ddd	 V  W d    d S 1 sBw   Y  d S )
Nsetup.pyz
            # -*- coding: utf-8 -*-
            from setuptools import setup
            import setuptools
            setup(**%r)
            utf-8-qbdist_wheelcwddist*.whlr   )r   encodeupdater   r   r   
subprocess
check_callsys
executableglobosjoin)extra_file_defskwargs	file_defs
source_dirr   r   r   build_wheel[   s$   	
"rA   c              
   C  sH   t  }t| D ]\}}}|D ]}|tjtj|| | qq|S N)setr;   walkaddr   r<   relpath)rootcontentsdirpathdirnames	filenamesr   r   r   r   tree_sett   s    rL   c                   sr   t  }|  D ]/\ }t|trt|}|D ]}t|tr+| fddt|D O }q|tj | qq|S )z8Flatten nested dicts and lists into a full list of pathsc                   s   h | ]	}t j |qS r   )r;   r   r<   )r   valZnoder   r   	<setcomp>   s    zflatten_tree.<locals>.<setcomp>)	rC   items
isinstancedictflatten_treerE   r;   r   r<   )treeoutputrH   elemr   rN   r   rS   |   s   

rS   c                 C  s   dd | D S )Nc                 S  s.   h | ]}|j t t td ptddqS )Z
EXT_SUFFIXZSO)r   r   Z	shlib_ext)format	sysconfigZget_python_versionr   r   )r   xr   r   r   rO      s    z&format_install_tree.<locals>.<setcomp>r   )rT   r   r   r   format_install_tree   s   rZ   c                 C  s   t | }tj|| }|| |d ur)t|}t|}	||	s)J ||	 t	j
j|gd\}
|
j	d |ks;J |
j	d |ksDJ |
d|ksMJ d S )Nr   NameZVersionrequires.txt)r	   r;   r   r<   egg_nameZinstall_as_eggrZ   rL   issubsetr   ZDistributionZdiscover	read_text)r   install_dirZinstall_tree_includesr   r   requires_txtr%   Zegg_pathinstall_treeZexpr2   r   r   r   _check_wheel_install   s   
rc   c                   @  s   e Zd Zdd ZdddZdS )	Recordc                 K  s   || _ || _d S rB   Z_id_fields)selfidr>   r   r   r   __init__   s   
zRecord.__init__returnstrc                 C  s   | j  d| jdS )Nz(**)re   )rg   r   r   r   __repr__   s   zRecord.__repr__N)rj   rk   )__name__
__module____qualname__ri   rm   r   r   r   r   rd      s    rd   Zbasicfoo__init__.py )packagesfoo-1.0-py{py_version}.egg)PKG-INFORECORDWHEELtop_level.txt)EGG-INFOrq   rh   r?   setup_kwargsrb   r-   u   Description accentuée)description)rh   r|   datazdata.txtz.
                Some data...
                data_dir)
data_files)rz   r   	extensionzextension.can  
                #include "Python.h"

                #if PY_MAJOR_VERSION >= 3

                static struct PyModuleDef moduledef = {
                        PyModuleDef_HEAD_INIT,
                        "extension",
                        NULL,
                        0,
                        NULL,
                        NULL,
                        NULL,
                        NULL,
                        NULL
                };

                #define INITERROR return NULL

                PyMODINIT_FUNC PyInit_extension(void)

                #else

                #define INITERROR return

                void initextension(void)

                #endif
                {
                #if PY_MAJOR_VERSION >= 3
                    PyObject *module = PyModule_Create(&moduledef);
                #else
                    PyObject *module = Py_InitModule("extension", NULL);
                #endif
                    if (module == NULL)
                        INITERROR;
                #if PY_MAJOR_VERSION >= 3
                    return module;
                #endif
                }
                zsetuptools.Extension)nameZsources)Zext_modulesz%foo-1.0-py{py_version}-{platform}.eggzextension{shlib_ext}rz   headerzheader.hz
                )ZheadersscriptX
                #/usr/bin/python
                print('hello world!')
                N
                #/bin/sh
                echo 'hello world!'
                	script.py	script.shr   r   scriptsrv   rw   rx   ry   r   Z	requires1zfoobar==2.0)rv   rw   rx   r\   ry   z%
            foobar==2.0
            )rh   install_requiresrb   ra   Z	requires2z
        bar
        foo<=2.0; z in sys_platform
        z2
            bar
            foo<=2.0
            )rh   r   ra   Z	requires3z
        bar; z != sys_platform
        )rh   r   Z	requires4z
        foo
        Zextrazfoobar>3zG
            foo

            [extra]
            foobar>3
            )rh   r   extras_requirera   Z	requires5zfoobar; z != sys_platform
z!
            [extra]
            )rh   r   ra   Zrequires_ensure_orderz9
        foo
        bar
        baz
        qux
        za
            foobar>3
            barbaz>4
            bazqux>5
            quxzap>6
            z
            foo
            bar
            baz
            qux

            [extra]
            foobar>3
            barbaz>4
            bazqux>5
            quxzap>6
            Znamespace_packageZbarzfoo.bar)Znamespace_packagesrt   z foo-1.0-py{py_version}-nspkg.pth)rv   rw   rx   znamespace_packages.txtry   Zempty_namespace_packageZfoobarz7__import__('pkg_resources').declare_namespace(__name__)Zdata_in_packagez>
                        Some data...
                        )rr   r   zfoo/data_dirzfoo/data_dir/data.txt)rt   r   ztuple[dict[str, Any], ...]WHEEL_INSTALL_TESTSparamsc                 C  r   )rh   r   )r   r   r   r   r   r    (  r!   c              	   C  s   |  dd}|  dd}|  dg }|  di }|  dd }|  d}|  d	i }|  d
i }td|||||d|-}	t }
t|	|
|||| W d    n1 sTw   Y  W d    d S W d    d S 1 slw   Y  d S )Nr   rq   r   1.0r   r   ra   rb   r?   r|   r   r   r   r   r=   r   )getrA   r   rc   )r   r   r   r   r   ra   rb   r?   r|   r   r`   r   r   r   test_wheel_install%  s4   
	Pr   c               
   C  s   d} d}|  d| d}t  Q}tj||}t|d  t  &}tt	 t
||d | |d  W d    n1 s<w   Y  W d    n1 sKw   Y  W d    d S W d    d S 1 scw   Y  d S )NZ
nodistinfor   -z-py2.py3-none-any.whlr%   )r   r;   r   r<   zipfileZipFilecloser(   r)   
ValueErrorrc   )r   r   Z
wheel_namer@   Z
wheel_pathr`   r   r   r   test_wheel_no_dist_dirC  s"   "r   c                 C  s(   dd }|  d| td sJ d S )Nc                   S  s   dd t dD S )Nc                 S  s   h | ]
}|j |j|jfqS r   )Zinterpreterr   r   r   r   r   r   rO   T  s    z=test_wheel_is_compatible.<locals>.sys_tags.<locals>.<setcomp>zcp36-cp36m-manylinux1_x86_64r   r   r   r   r   sys_tagsS  s   z*test_wheel_is_compatible.<locals>.sys_tagsz$setuptools.wheel._get_supported_tagsz2onnxruntime-0.1.2-cp36-cp36m-manylinux1_x86_64.whl)setattrr	   Zis_compatible)Zmonkeypatchr   r   r   r   test_wheel_is_compatibleR  s   r   c                  C  st  t jddd} tdtdtddtddgd	td
ddddddddgigiid}|dd}|dd}|d}|di }|di }| d||g i |d|[}t ?}t|||||d  t|}	t	
||	  }
|
d d d }| s~J tjdkrtt| jdksJ W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nc                 {  s    dt d| di}| r||  t 6}t|| t|d }t	|d t
jtjdddf|d ttj|d	d
d V  W d    d S 1 sOw   Y  d S )Nr,   z
                # -*- coding: utf-8 -*-
                from setuptools import setup
                import setuptools
                setup(**%r)
                r-   r   i  r.   r/   r0   r2   r3   r   )r   r4   r5   r   r   r   pathlibPathr;   chmodr6   r7   r8   r9   r:   r<   )r=   r>   r?   r@   Zrunshr   r   r   rA   ^  s(   	
"z$test_wheel_mode.<locals>.build_wheelr   r   r   r   r   r   r   ru   rz   rv   rw   rx   ry   r   r{   r   rq   r   r   rb   r?   r|   r   win32Z0o777rB   r   )
contextlibcontextmanagerrR   r   rS   r   r   rc   r	   r   r   r]   existsr8   r   octstatS_IMODEst_mode)rA   r   r   r   rb   r?   r|   r   r`   r%   baseZ	script_shr   r   r   test_wheel_mode]  sp   
 
	
Pr   rB   )4__doc__Z
__future__r   r   r:   r'   r;   r   r   r6   r8   rX   r   typingr   r(   Zjaracor   Zpackaging.tagsr   Zsetuptools._importlibr   Zsetuptools.wheelr	   Zcontextsr   textwrapr   Zdistutils.sysconfigr   Zdistutils.utilr   r   ZWHEEL_INFO_TESTSZmarkZparametrizer+   r   rA   rL   rS   rZ   rc   rd   rR   r   r   __annotations__r   r   r   r   r   r   r   r   <module>   sh   1
	

-D

 
!
    q
