
    ϶vg('                         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 )    N)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        \/var/www/pixelcanvas.ch/venv/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_override9   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%r@   )script_namer%   package_dir)r	   r   buildr   )r   filesr?   ext2rA   s        r   dist_with_examplezTestBuildExt.dist_with_exampleY   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 )Nr3   .mp3&setuptools.command.build_ext.use_stubsFr   /c                 N    g | ]"}|                     t          j        d           #S rK   replacer7   sep).0xs     r   
<listcomp>z1TestBuildExt.test_get_outputs.<locals>.<listcomp>t   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 rM   rN   rQ   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setattrrG   get_command_objeditable_modeensure_finalized	build_librO   r7   rP   get_outputsget_output_mappingreinitialize_commanditems)r   
tmpdir_cwdmonkeypatchr   r   re   outputsmappings           r   test_get_outputszTestBuildExt.test_get_outputsj   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 )Nr3   rI   rJ   Tr   _needs_stubrK   c                     i | ]D\  }}|                     t          j        d           |                     t          j        d           ES rM   rN   rX   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 wayrK   )_compiled_file_namerO   r7   rP   )files    r   Cz9TestBuildExt.test_get_output_mapping_with_stub.<locals>.C   s"    &t,,44RVSAAAr   z/ext3.pyzsrc/ext3.pyrT   r]   z/mypkg/ext1.pyzsrc/mypkg/ext1.pyrU   r^   z/mypkg/subpkg/ext2.pyzsrc/mypkg/subpkg/ext2.pyrV   r_   z/mypkg/__pycache__/ext1z.pyc)r`   ra   rG   rb   rc   rd   
extensionsre   rO   r7   rP   rg   ri   
startswithr,   )
r   rj   rk   r   r   r9   re   rm   ru   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   r0   r;   rG   rn   ry    r   r   r   r      sp          ! ! !*4 4 4@  "
 
 
@'- '- '- '- '-r   r   c                   0    e Zd ZdedefdZd Zd Zd ZdS )TestBuildExtInplaceoptionalreturnc                 .   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)re   
build_tempr}   )
r   rD   r	   r   r*   rB   r   varsupdaterd   )r   r   optsrE   r/   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}   )rQ   msgs     r   	<genexpr>z4TestBuildExtInplace.test_optional.<locals>.<genexpr>   s6       
 
 ?
 
 
 
 
 
r   N)r   runanyr   )r   rj   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   rj   r   s      r   test_non_optionalz%TestBuildExtInplace.test_non_optional   s    $$eT$BB]<(( 	 	GGIII	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAN)	rz   r{   r|   boolr   r   r   r   r   r}   r   r   r   r      sf        $ 9    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	|z              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.cfgrD   )r      )r   data_streamr   z
STDOUT:
%s
STDERR:
%s)r   r   rD   r   run_setup_py)rj   rE   codeoutputs       r   test_build_ext_config_handlingr      s    	
 	
 (*
 *
V 
 
m< <Ez 	Ju+I  LD& 19992V;99999r   )r7   r-   importlib.utilr   rs   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_namesr6   r   r   r   r}   r   r   <module>r      sh   				 



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