
    pg\jV                         S r SSKrSSKrSSKrSSKrSSKrSSKJr  SS/rSSSSS.S	 jr	 SS
 jr
S rS rS rS rS rS rg)zb
Build a c-extension module on-the-fly in tests.
See build_and_import_extensions for usage hints

    N   )run_subprocessbuild_and_import_extensioncompile_extension_module )prologue	build_dirinclude_dirs	more_initc                n   Uc  / nU[        X5      -   nSnU(       d  [        R                  " S5      nU(       a	  US-  nXu-  nUS-  n[        XU5      n[	        XXH5      n	SSKn
U
R                  R                  X	5      nU
R                  R                  U5      nUR                  R                  U5        U$ )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')
Nz
    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;r   )_make_methodspathlibPath_make_sourcer   importlib.utilutilspec_from_file_locationmodule_from_specloaderexec_module)modname	functionsr   r	   r
   r   bodyinitsource_stringmod_so	importlibspecfoos                Z/home/edenadmin/noVNC/venv/lib/python3.13/site-packages/numpy/testing/_private/extbuild.pyr   r      s    N mI77DD LL%	  	OD 5M%L9F>>11'BD
..
)
)$
/CKKC J    c                     U R                  S5      S   nX-  nUR                  SS9  [        X75      nU=(       d    / nU=(       d    / nU=(       d    / n[        XU-  X$US9$ )a  
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)outputfilenamer
   	librarieslibrary_dirs)splitmkdir_convert_str_to_file
_c_compile)	namebuilddirr
   r   r(   r)   r   dirnamecfiles	            r!   r   r   S   sm    * jjob!GoGMM4M  8E%2LRI%2L/!!
 
r"   c                     US-  nUR                  S5       nUR                  [        U 5      5        SSS5        U$ ! , (       d  f       U$ = f)zwHelper 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)sourcer0   filenamefs       r!   r,   r,   w   sD     #H	s	q	F 
O 
	Os	   <
Ac           
         / n/ nU  HO  u  pEnU SU 3nSU;   a  SnOSnUR                  SU SU SU S35        S	U U S
U S3n	UR                  U	5        MQ     SR                  U5      n
SR                  U5      SU
 SU S3-   nU$ )zTurns 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* z
        {
        z
        }
        
z*
    static PyMethodDef methods[] = {
    zi
    { NULL }
    };
    static struct PyModuleDef moduledef = {
        PyModuleDef_HEAD_INIT,
        "z",    /* m_name */
        NULL,           /* m_doc */
        -1,             /* m_size */
        methods,        /* m_methods */
    };
    )appendjoin)r   r   methods_tablecodesfuncnameflagscode	cfuncname	signature	func_codemethods_strr   s               r!   r   r      s     ME!*iq
+	e#LI:Is8*,<YKr%PSTU#YK 0		 		 	Y "+ ))M*K99U #M 

   D Kr"   c                     SU SU  SU S3nU$ )zFCombines the code fragments into source code ready to be compiled
    z
    #include <Python.h>

    z 

    PyMODINIT_FUNC
    PyInit_z(void) {
    z
    }
     )r.   r   r   rD   s       r!   r   r      s7     
F  6 	F 	D Kr"   c           	          / n[         R                  S:X  a  S/nUR                  S5        O+[         R                  R                  S5      (       a  / SQnO/ n[	        XXeX#U5      $ )Nwin32z/we4013z/DEBUGlinux)z-O0z-gz%-Werror=implicit-function-declarationz-fPIC)sysplatformr>   
startswithbuild)r1   r'   r
   r(   r)   
link_extracompile_extras          r!   r-   r-      sd    J
||w"(#		 	 	)	)K / /r"   c                    U R                   S-  n[        R                  " USS9  [        U R                   S-  S5       nU V	s/ s H  n	SU	-   PM
     n
n	UR	                  [
        R                  " SUR                  S    S	U R                  S    S
U SU
 SU S35      5        SSS5        U R                   S-  n[        US5       nUR	                  [
        R                  " S[        R                   S35      5        SSS5        [        R                  S:X  a  [        / SQU5        O([        SSSSS[        R                  " U5       3/U5        UR                  S   [        5       -   n[        SS/U5        [        R                  " [        X|-  5      U R                   U-  5        U R                   U-  $ s  sn	f ! , (       d  f       GN = f! , (       d  f       N= f)zuse meson to buildrQ   Tr%   zmeson.buildwtz-Lz            project('foo', 'c')
            py = import('python').find_installation(pure: false)
            py.extension_module(
                'r$   z',
                'z',
                c_args: z,
                link_args: z',
                include_directories: z,
            )
        Nz.mesonpy-native-file.iniz-            [binaries]
            python = 'z
'
        rL   )mesonsetupz--buildtype=release--vsenv..rV   rW   rX   rY   z--native-file=compile)parentosmakedirsr4   r5   textwrapdedentpartsrN   
executablerO   r   fspathget_so_suffixrenamer6   )r1   r'   rS   rR   r
   r(   r)   r	   fidd	link_dirsnative_file_nameso_names                r!   rQ   rQ      s    w&IKK	D)	ell]*D	1S'34|!TAX|	4		(// ' !&&r*+ ,++b/" #& (%; '&&2^ 4	
# 
 
	 
2 ||&@@		%		(// '~~& '	#  	 
&
 ||w ) !	"
 	)ryy9I/J.KLN 	" ""2&8GGY'3IIc)%&w(>?<<'!!? 5 
2	1 
&	%s*   F<F7AF<8G7F<<
G
Gc                  D    [         R                  " S5      n U (       d   eU $ )N
EXT_SUFFIX)	sysconfigget_config_var)rets    r!   rc   rc      s    

"
"<
0CJ3Jr"   )NN)__doc__r\   r   rN   rl   r^   utilsr   __all__r   r   r,   r   r   r-   rQ   rc   rJ   r"   r!   <module>rr      sf    
  
   !')C
D )+dR>F 59!
H%P /$&"Rr"   