
    5hs'                        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	 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 d	dlmZ d dlmc mZ d dlmZ dej        v Z G d d          Z G d d          Zd Z dS )    )annotationsN)cache_from_source)path)	build_extget_abi3_suffix)Distribution)CompileError)	Extension   )environment)DALS)get_config_var__pypy__c                  2    e Zd Zd Zd Zd Zd Zd Zd ZdS )TestBuildExtc                    t                      }t          |          }d|j        d<   |                    d          }t          j                            |d          }||k    sJ dS )z
        Setuptools needs to give back the same
        result as distutils, even if the fullname
        is not in ext_map.
         zfoo/barfooN)r   r   ext_mapget_ext_filenameorig)selfdistcmdreswanteds        ?lib/python3.11/site-packages/setuptools/tests/test_build_ext.pytest_get_ext_filenamez"TestBuildExt.test_get_ext_filename   s_     ~~oo!#I""5))00e<<f}}}}}}    c                   t          t                                 t          ddgd          }t          t	          |g                    }t          |          }|                                 d|j        v sJ |                    d          }t                      s&|	                    t          d                    sJ d
S t          j        dk    r|	                    d          sJ d
S d	|v sJ d
S )z}
        Filename needs to be loadable by several versions
        of Python 3 if 'is_abi3' is truthy on Extension()
        	spam.eggseggs.cTpy_limited_apiext_modules
EXT_SUFFIXwin32zeggs.pydabi3N)printr   r
   r   dictr   finalize_optionsr   r   endswithr   sysplatform)r   	extensionr   r   r   s        r   test_abi3_filenamezTestBuildExt.test_abi3_filename&   s    
 	o   kH:dKKK	Di[999::oock))))"";//   	!<<| < <=======\W$$<<
+++++++S======r   c                   t                      }t          |          }t          ddgd          x|j        d<   }d|_        t
          s|                    d          }nd}	 dt          j        d<   |                    d	          }d
|k    sJ |                    d          }||k    sJ 	 t          j        d= dS # t          j        d= w xY w)zd
        SETUPTOOLS_EXT_SUFFIX variable always overrides
        default extension options.
        for_abi3zs.cTr#   Fzfor_abi3.test-suffixz.test-suffixSETUPTOOLS_EXT_SUFFIXnormalznormal.test-suffixN)	r   r   r
   r   _links_to_dynamicIS_PYPYr   osenviron)r   r   r   extexpectr   s         r   test_ext_suffix_overridez%TestBuildExt.test_ext_suffix_override;   s    
 ~~oo(1G	)
 )
 )
 	
J# !& 	,))*55FF ,F	42@BJ./&&x00C'3....&&z22CS=====
2333
233333s   "A	B; ;C
c                    ddddiiidddiid}t          dd	g          }t          d
dg          }t          ddg          }t          j        |           t          d|||gddid          S )Nmypkgsubpkgzext2.cr   ext1zmain.c)srczc-extensionsz
mypkg.ext1zc-extensions/ext1/main.czmypkg.subpkg.ext2zsrc/mypkg/subpkg/ext2.cext3zc-extension/ext3.cz%test%rA   )script_namer&   package_dir)r
   r   buildr   )r   filesr@   ext2rB   s        r   dist_with_examplezTestBuildExt.dist_with_example[   s    h278#h^4
 

 (B'CDD,/H.IJJ"6!788
5# $-;
 
   	r   c                   |                     dd           |                    dd           |                                 }|                    d          }d|_         |j                     |j                            t          j	        d          }d  |j
                    D             }|| d| d	| d
gk    sJ  |j                    i k    sJ |                    d           d|_         |j                     d  |j                                                    D             }|| dd| d	d| d
dik    sJ d S )Nr4   .mp3&setuptools.command.build_ext.use_stubsFr   /c                N    g | ]"}|                     t          j        d           #S rL   replacer8   sep).0xs     r   
<listcomp>z1TestBuildExt.test_get_outputs.<locals>.<listcomp>v   s(    KKKa199RVS))KKKr   	/ext3.mp3/mypkg/ext1.mp3/mypkg/subpkg/ext2.mp3Tc                    i | ]D\  }}|                     t          j        d           |                     t          j        d           ES rN   rO   rR   kvs      r   
<dictcomp>z1TestBuildExt.test_get_outputs.<locals>.<dictcomp>   N     
 
 
1 IIbfc""AIIbfc$:$:
 
 
r   src/ext3.mp3src/mypkg/ext1.mp3src/mypkg/subpkg/ext2.mp3)setenvsetattrrH   get_command_objeditable_modeensure_finalized	build_librP   r8   rQ   get_outputsget_output_mappingreinitialize_commanditems)r   
tmpdir_cwdmonkeypatchr   r   rf   outputsmappings           r   test_get_outputszTestBuildExt.test_get_outputsl   s   2F;;;DeLLL%%'' ((55	"'	"	"$$$'//<<	KK3H93H3J3JKKK###)))000
 
 
 
 

 ,y+--3333 	!!+..."&	"	"$$$
 
4	466<<>>
 
 
 ###^)))+?0002M
 
 
 
 
 
 
r   c                *   |                     dd           |                    dd           |                                 }|                    d          }d|_         |j                     |j        D ]}|                    |dd           |j                            t          j
        d          }d  |j                                                    D             }d	 }| || d
           |d          | dd || d           |d          | dd || d           |d          | ddik    sJ | d|vsJ | d|vsJ  || d          }	|	|v sJ |	                    | d          sJ |	                    d          sJ d S )Nr4   rJ   rK   Tr   _needs_stubrL   c                    i | ]D\  }}|                     t          j        d           |                     t          j        d           ES rN   rO   rY   s      r   r\   zBTestBuildExt.test_get_output_mapping_with_stub.<locals>.<dictcomp>   r]   r   c                \    t          |                               t          j        d          S )zDMake it possible to do comparisons and tests in a OS-independent wayrL   )_compiled_file_namerP   r8   rQ   )files    r   Cz9TestBuildExt.test_get_output_mapping_with_stub.<locals>.C   s"    &t,,44RVSAAAr   z/ext3.pyzsrc/ext3.pyrU   r^   z/mypkg/ext1.pyzsrc/mypkg/ext1.pyrV   r_   z/mypkg/subpkg/ext2.pyzsrc/mypkg/subpkg/ext2.pyrW   r`   z/mypkg/__pycache__/ext1z.pyc)ra   rb   rH   rc   rd   re   
extensionsrf   rP   r8   rQ   rh   rj   
startswithr-   )
r   rk   rl   r   r   r:   rf   rn   rv   example_stubs
             r   !test_get_output_mapping_with_stubz.TestBuildExt.test_get_output_mapping_with_stub   sS   2F;;;DdKKK%%'' ((55	"&	"	"$$$' 	: 	:C]D9999'//<<	
 
4	466<<>>
 
 

	B 	B 	B A$$$%%qq'7'7###^A***++QQ/B-C-C)))+?A11122AA6P4Q4Q0002M
 
 
 
 
 +++7::::222'AAAA qI55566w&&&&&&)'L'L'LMMMMM$$V,,,,,,,r   N)	__name__
__module____qualname__r   r1   r<   rH   ro   rz    r   r   r   r      sp          ! ! !*4 4 4@  "
 
 
@'- '- '- '- '-r   r   c                  (    e Zd Zd
dZd Zd Zd Zd	S )TestBuildExtInplaceoptionalboolreturnr   c                .   di i dd}t          j        |           t          ddg|          }t          t	          |g                    }d|_        t          |          } t          |          j        dd	d
d| |	                                 |S )Nz#include missingheader.h
)libtmp)r"   z.buildr!   r"   )r   r%   setup.pyz
.build/libz
.build/tmp)rf   
build_tempr~   )
r   rE   r
   r   r+   rC   r   varsupdatere   )r   r   optsrF   r0   r   r   s          r   get_build_ext_cmdz%TestBuildExtInplace.get_build_ext_cmd   s    2 ,,=
 =
 	
5kH:III	Di[999::%ooS		Q<LQQDQQQ
r   c                    |                                 }|j                                        |j                                        z   |j        z   S )z
        Historically, distutils "logged" by printing to sys.std*.
        Later versions adopted the logging framework. Grab
        messages regardless of how they were captured.
        )
readouterrout
splitlineserrmessages)r   caplogcapsysstds       r   get_log_messagesz$TestBuildExtInplace.get_log_messages   sC     !!w!!##cg&8&8&:&::V_LLr   c                    |                      dd          }|                                 t          d |                     ||          D                       sJ dS )z
        If optional extensions fail to build, setuptools should show the error
        in the logs but not fail to build
        Tr   inplacec              3     K   | ]}d V  dS )z0build_ext: building extension "spam.eggs" failedNr~   )rR   msgs     r   	<genexpr>z4TestBuildExtInplace.test_optional.<locals>.<genexpr>   s6       
 
 ?
 
 
 
 
 
r   N)r   runanyr   )r   rk   r   r   r   s        r   test_optionalz!TestBuildExtInplace.test_optional   s{    
 $$dD$AA			 
 
,,VV<<
 
 
 
 
 	
 	
 
 	
 	
r   c                    |                      dd          }t          j        t                    5  |                                 d d d            d S # 1 swxY w Y   d S )NFTr   )r   pytestraisesr	   r   )r   rk   r   s      r   test_non_optionalz%TestBuildExtInplace.test_non_optional   s    $$eT$BB]<(( 	 	GGIII	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAN)r   r   r   r   )r{   r|   r}   r   r   r   r   r~   r   r   r   r      sX           M M M

 

 

    r   r   c                    t          d          t          d          t          d          d}t          j        |           t          j        dgd          \  }\  }}|dk    sJ d	| d
|             d S )Nz
            from setuptools import Extension, setup
            setup(
                name='foo',
                version='0.0.0',
                ext_modules=[Extension('foo', ['foo.c'])],
            )
            a  
            #include "Python.h"

            #if PY_MAJOR_VERSION >= 3

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

            #define INITERROR return NULL

            PyMODINIT_FUNC PyInit_foo(void)

            #else

            #define INITERROR return

            void initfoo(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
            }
            zD
            [build]
            build_base = foo_build
            )r   zfoo.cz	setup.cfgrE   )r      )r   data_streamr   z	
STDOUT:
z	
STDERR:
)r   r   rE   r   run_setup_py)rk   rF   codestdoutstderrs        r   test_build_ext_config_handlingr      s    	
 	
 (*
 *
V 
 
m< <Ez 	Ju(5I  D
66 1999?F??v??99999r   )!
__future__r   r8   r.   importlib.utilr   rt   r   jaracor   setuptools.command.build_extr   r   setuptools.distr   setuptools.errorsr	   setuptools.extensionr
   r   r   textwrapr   distutils.command.build_extcommandr   distutils.sysconfigr   builtin_module_namesr7   r   r   r   r~   r   r   <module>r      s   " " " " " " 				 



 C C C C C C        C C C C C C C C ( ( ( ( ( ( * * * * * * * * * * * *             * * * * * * * * * . . . . . .
0
0[- [- [- [- [- [- [- [-|) ) ) ) ) ) ) )XC@ C@ C@ C@ C@r   