Ë
    ¡ehª  ã                   óŠ   — d 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gZddg ddœd„Zg g fd„Z	d	„ Z
d
„ Zd„ Zg g g fd„Zd„ Zd„ Zy)zb
Build a c-extension module on-the-fly in tests.
See build_and_import_extensions for usage hints

é    NÚbuild_and_import_extensionÚcompile_extension_moduleÚ )ÚprologueÚ	build_dirÚinclude_dirsÚ	more_initc                óž  — |t        || «      z   }d}|st        j                  d«      }|r
|dz  }||z  }|dz  }t        | ||«      }	 t	        | |||«      }	ddl}|j                  j                  | |	«      }|j                  j                  |«      }|j                  j                  |«       |S # t
        $ r}
t        d|› d�«      |
‚d}
~
ww xY w)	a  
    Build and imports a c-extension module `modname` from a list of function
    fragments `functions`.


    Parameters
    ----------
    functions : list of fragments
        Each fragment is a sequence of func_name, calling convention, snippet.
    prologue : string
        Code to precede the rest, usually extra ``#include`` or ``#define``
        macros.
    build_dir : pathlib.Path
        Where to build the module, usually a temporary directory
    include_dirs : list
        Extra directories to find include files when compiling
    more_init : string
        Code to appear in the module PyMODINIT_FUNC

    Returns
    -------
    out: module
        The module will have been loaded and is ready for use

    Examples
    --------
    >>> functions = [("test_bytes", "METH_O", """
        if ( !PyBytesCheck(args)) {
            Py_RETURN_FALSE;
        }
        Py_RETURN_TRUE;
    """)]
    >>> mod = build_and_import_extension("testme", functions)
    >>> assert not mod.test_bytes('abc')
    >>> assert mod.test_bytes(b'abc')
    z›
    PyObject *mod = PyModule_Create(&moduledef);
    #ifdef Py_GIL_DISABLED
    PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED);
    #endif
           ú.z.#define INITERROR return NULL
                z
return mod;zcould not compile in ú:Nr   )Ú_make_methodsÚpathlibÚPathÚ_make_sourcer   Ú	ExceptionÚRuntimeErrorÚimportlib.utilÚutilÚspec_from_file_locationÚmodule_from_specÚloaderÚexec_module)ÚmodnameÚ	functionsr   r   r   r	   ÚbodyÚinitÚsource_stringÚmod_soÚeÚ	importlibÚspecÚfoos                 ú]/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/numpy/testing/_private/extbuild.pyr   r      sî   € ðN ”m I¨wÓ7Ñ7€Dð€Dñ Ü—L‘L Ó%ˆ	ÙØð ñ 	ˆà�	ÑˆØˆOÑ€DÜ  ¨$°Ó5€MðHÜ)Ø�Y ¨mó=ˆó
 Ø�>‰>×1Ñ1°'¸6ÓB€DØ
�.‰.×
)Ñ
)¨$Ó
/€CØ‡K�K×Ñ˜CÔ Ø€Jøô ò HäÐ2°9°+¸QÐ?Ó@ÀaÐGûðHús   ÁB. Â.	CÂ7CÃCc                 óÈ   — | j                  d«      d   }|| z  }|j                  d¬«       t        ||«      }|t        j                  d«      gz   }t        |||z  |g g ¬«      S )aH  
    Build an extension module and return the filename of the resulting
    native code file.

    Parameters
    ----------
    name : string
        name of the module, possibly including dots if it is a module inside a
        package.
    builddir : pathlib.Path
        Where to build the module, usually a temporary directory
    include_dirs : list
        Extra directories to find include files when compiling
    libraries : list
        Libraries to link into the extension module
    library_dirs: list
        Where to find the libraries, ``-L`` passed to the linker
    r   éÿÿÿÿT©Úexist_okÚ	INCLUDEPY)Úoutputfilenamer   Ú	librariesÚlibrary_dirs)ÚsplitÚmkdirÚ_convert_str_to_fileÚ	sysconfigÚget_config_varÚ
_c_compile)	ÚnameÚbuilddirr   r   r*   r+   r   ÚdirnameÚcfiles	            r#   r   r   T   so   € ð* �j‰j˜‹o˜bÑ!€GØ˜‰o€GØ‡M�M˜4€MÔ Ü  °Ó8€EØ¤9×#;Ñ#;¸KÓ#HÐ"IÑI€LäØ˜g¨Ñ/Ø!¨R¸bô
ð 
ó    c                 ó’   — |dz  }|j                  d«      5 }|j                  t        | «      «       ddd«       |S # 1 sw Y   |S xY w)zHelper function to create a file ``source.c`` in `dirname` that contains
    the string in `source`. Returns the file name
    zsource.cÚwN)ÚopenÚwriteÚstr)Úsourcer4   ÚfilenameÚfs       r#   r.   r.   u   sF   € ð ˜Ñ#€HØ	�‰�sÓ	ð ˜qØ	�‰”�F“Ô÷à€O÷à€Oús	   —<¼Ac           
      ó&  — g }g }| D ]V  \  }}}|›d|›�}d|v rd}nd}|j                  d|›d|›d|›d�«       d	j                  |||¬
«      }	|j                  |	«       ŒX dj                  |«      dt        dj                  |«      |¬«      z  z   }
|
S )zõ Turns the name, signature, code in functions into complete functions
    and lists them in a methods_table. Then turns the methods_table into a
    ``PyMethodDef`` structure and returns the resulting code fragment ready
    for compilation
    Ú_ÚMETH_KEYWORDSz2(PyObject *self, PyObject *args, PyObject *kwargs)z (PyObject *self, PyObject *args)z{"z", (PyCFunction)z, z},z^
        static PyObject* {cfuncname}{signature}
        {{
        {code}
        }}
        )Ú	cfuncnameÚ	signatureÚcodeú
a6  
    static PyMethodDef methods[] = {
    %(methods)s
    { NULL }
    };
    static struct PyModuleDef moduledef = {
        PyModuleDef_HEAD_INIT,
        "%(modname)s",  /* m_name */
        NULL,           /* m_doc */
        -1,             /* m_size */
        methods,        /* m_methods */
    };
    )Úmethodsr   )ÚappendÚformatÚjoinÚdict)r   r   Úmethods_tableÚcodesÚfuncnameÚflagsrD   rB   rC   Ú	func_coder   s              r#   r   r      sÀ   € ð €MØ€EØ!*ò  Ñˆ�%˜Ú&©Ð1ˆ	Ø˜eÑ#ØL‰Ià:ˆIØ×ÒÚ08º)ÂUÐKô	Mð÷
 ‰F˜Y°)À$ˆFÓGð 	ð 	�‰�YÕð ð  �9‰9�UÓð ô �t—y‘y Ó/¸Ô
AñBñ B€Dð €Kr6   c                 ó(   — dt        | ||¬«      z  }|S )zG Combines the code fragments into source code ready to be compiled
    zn
    #include <Python.h>

    %(body)s

    PyMODINIT_FUNC
    PyInit_%(name)s(void) {
    %(init)s
    }
    )r2   r   r   )rJ   )r2   r   r   rD   s       r#   r   r   §   s&   € ð	ô Ø˜ 4ôñ€Dð €Kr6   c           	      ó   — t         j                  dk(  r6dg}dt        j                  j	                  t         j
                  d«      z   g}n+t         j                  j                  d«      rg d¢}g }ng x}}	 t         j                  dk(  r|dgz   }t         j                  dk(  rƒd	D ]~  }|d
z   |vr6t        j                  j                  |d
z   «      r|j                  |d
z   «       |dz   |vsŒHt        j                  j                  |dz   «      sŒk|j                  |dz   «       Œ€ |j                  t        «       «      }t        | ||||||«       |S )NÚwin32z/we4013z	/LIBPATH:ÚlibsÚlinux)z-O0z-gz%-Werror=implicit-function-declarationz-fPICz/DEBUGÚdarwin)z/sw/z/opt/local/ÚincludeÚlib)ÚsysÚplatformÚosÚpathrI   Úbase_prefixÚ
startswithÚexistsrG   Úwith_suffixÚget_so_suffixÚbuild)r5   r)   r   r*   r+   Úcompile_extraÚ
link_extraÚss           r#   r1   r1   ¹   s,  € ä
‡|�|�wÒØ"˜ˆØ!¤B§G¡G§L¡L´·±À&Ó$IÑIÐJ‰
Ü	�‰×	 Ñ	  Ô	)òKˆà‰
à%'Ð'ˆ˜
ØÜ
‡|�|�wÒØ 8 *Ñ,ˆ
Ü
‡|�|�xÒà(ò 	/ˆAØ�I‘ \Ñ1ÜŸ™Ÿ™ q¨9¡}Ô5Ø×#Ñ# A¨	¡MÔ2Ø�5‰y Ò,´·±·±ÀÀEÁ	Õ1JØ×#Ñ# A¨¡IÕ.ð	/ð $×/Ñ/´³Ó@€NÜ	Øˆ~Ø�zØ�i ô/ð Ðr6   c                 óÖ  — | j                   dz  }t        j                  |d¬«       |j                  d   }t	        | j                   dz  d«      5 }	|D �
cg c]  }
d|
z   ‘Œ	 }}
|D �
cg c]  }
d|
z   ‘Œ	 }}
|	j                  t        j                  d	|› d
| j                  d   › d|› d|› d|› d|› d|› d�«      «       ddd«       t        j                  dk(  rt        j                  g d¢|¬«       nt        j                  g d¢|¬«       t        j                  ddg|¬«       t        j                  t        ||z  «      dz   | j                   |z  «       yc c}
w c c}
w # 1 sw Y   Œ¥xY w)zuse meson to buildra   Tr&   r%   zmeson.buildÚwtz-Iz-Lz;            project('foo', 'c')
            shared_module('z', 'z',
                c_args: z + z,
                link_args: z,
                link_with: z_,
                name_prefix: '',
                name_suffix: 'dummy',
            )
        NrR   )ÚmesonÚsetupz--buildtype=releaseú--vsenvú..)Úcwd)rg   rh   ri   rj   rg   Úcompilez.dummy)ÚparentrZ   ÚmakedirsÚpartsr9   r:   ÚtextwrapÚdedentrX   rY   Ú
subprocessÚ
check_callÚrenamer;   )r5   r)   rb   rc   r   r*   r+   r   Úso_nameÚfidÚdÚincludesÚ	link_dirss                r#   ra   ra   Ø   sm  € ð —‘˜wÑ&€IÜ‡K�K�	 DÕ)Ø×"Ñ" 2Ñ&€GÜ	ˆe�l‰l˜]Ñ*¨DÓ	1ð °SØ&2Ö3 �D˜1“HÐ3ˆÐ3Ø'3Ö4 !�T˜A“XÐ4ˆ	Ð4Ø�	‰	”(—/‘/ð 'à#˜9 D¨¯©°R©Ð(9ð :Ø!˜
 # m _ð 5Ø%˜; c¨*¨ð 6Ø%˜;ð '	ð	#ó 	ô 		÷ô ‡|�|�wÒÜ×Ñò 0ð #,ö	 ô 	×ÑÒAØ"+õ	 ô ×Ñ˜7 IÐ.°IÕ>Ü‡I�IŒc�)˜gÑ%Ó&¨Ñ1°5·<±<À'Ñ3IÕJùò/ 4ùÚ4÷ð ús+   ÁEÁEÁ EÁ&EÁ2A	EÅ
EÅE(c                  ó8   — t        j                  d«      } | sJ ‚| S )NÚ
EXT_SUFFIX)r/   r0   )Úrets    r#   r`   r`   ù   s   € Ü
×
"Ñ
" <Ó
0€CÙ€Jˆ3Ø€Jr6   )Ú__doc__rZ   r   rr   rX   r/   rp   Ú__all__r   r   r.   r   r   r1   ra   r`   © r6   r#   ú<module>r€      st   ðñó 
Û Û Û 
Û Û à'Ð)CÐ
D€ð )+°dØ 2ô@ðJ "$°"ó
òBò%òPð$ 46ÀØóò>KóBr6   