§
    €Ûgˆ  ã                   ó|   — d 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dS )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                ó¼  — ddl m} |t          || ¦  «        z   }d}|st          j        d¦  «        }|r
|dz  }||z  }|dz  }t          | ||¦  «        }		 t          | |||	¦  «        }
n!# |$ r}t          d|› d�¦  «        |‚d	}~ww xY wdd	l}|j	         
                    | |
¦  «        }|j	                             |¦  «        }|j                             |¦  «         |S )
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(u'abc')
    >>> assert mod.test_bytes(b'abc')
    r   )ÚCompileErrorz8PyObject *mod = PyModule_Create(&moduledef);
           ú.z.#define INITERROR return NULL
                z
return mod;zcould not compile in ú:N)Údistutils.errorsr   Ú_make_methodsÚpathlibÚPathÚ_make_sourcer   ÚRuntimeErrorÚimportlib.utilÚutilÚspec_from_file_locationÚmodule_from_specÚloaderÚexec_module)ÚmodnameÚ	functionsr   r   r   r	   r   ÚbodyÚinitÚsource_stringÚmod_soÚeÚ	importlibÚspecÚfoos                  úU/granary/edev/quantum/lib/python3.11/site-packages/numpy/testing/_private/extbuild.pyr   r      s9  € ðN .Ð-Ð-Ð-Ð-Ð-à•m I¨wÑ7Ô7Ñ7€Dð€Dàð &Ý”L Ñ%Ô%ˆ	Øð Øð ñ 	ˆà�	ÑˆØˆOÑ€DÝ  ¨$°Ñ5Ô5€MðHÝ)Ø�Y ¨mñ=ô =ˆˆøàð Hð Hð HåÐ?°9Ð?Ð?Ð?Ñ@Ô@ÀaÐGøøøøðHøøøð ÐÐÐØŒ>×1Ò1°'¸6ÑBÔB€DØ
Œ.×
)Ò
)¨$Ñ
/Ô
/€CØ„K×Ò˜CÑ Ô Ð Ø€Js   ÁA( Á(BÁ-BÂBc                 óì   — |                       d¦  «        d         }|| z  }|                     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   P   s„   € ð* �jŠj˜‰oŒo˜bÔ!€GØ˜‰o€GØ‡M‚M˜4€MÑ Ô Ð Ý  °Ñ8Ô8€EØ¥9Ô#;¸KÑ#HÔ#HÐ"IÑI€LåØ˜g¨Ñ/Ø!¨R¸bð
ñ 
ô 
ð 
ó    c                 ó®   — |dz  }|                      d¦  «        5 }|                     t          | ¦  «        ¦  «         ddd¦  «         n# 1 swxY w Y   |S )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.   q   s�   € ð ˜Ñ#€HØ	�Š�sÑ	Ô	ð ˜qØ	�Š•�F‘”ÑÔÐðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð à€Os   ›#A
Á
AÁAc           
      óR  — g }g }| D ]b\  }}}|›d|›�}d|v rd}nd}|                      d|›d|›d|›d�¦  «         d	                     |||¬
¦  «        }	|                      |	¦  «         Œcd                     |¦  «        dt          d                     |¦  «        |¬¦  «        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Ø!*ð  ð  Ñˆ�%˜Ø&˜w˜w¨¨Ð1ˆ	Ø˜eÐ#Ð#ØLˆIˆIà:ˆIØ×ÒÐØ08°°¸)¸)¸)ÀUÀUÀUÐKñ	Mô 	Mð 	Mð÷
 ŠF˜Y°)À$ˆFÑGÔGð 	ð 	�Š�YÑÔÐÐà�9Š9�UÑÔð õ �t—y’y Ñ/Ô/¸Ð
AÑ
AÔ
AñBñ B€Dð €Kr6   c                 ó0   — 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   £   s0   € ð	õ Ø˜ 4ðñ ô ñ€Dð €Kr6   c           	      ó   — t           j        dk    r2dg}dt          j                             t           j        d¦  «        z   g}n+t           j                             d¦  «        rg d¢}d }nd x}}	 t           j        dk    r|dgz   }t           j        dk    r‡d	D ]„}|d
z   |vr:t          j                             |d
z   ¦  «        r|                     |d
z   ¦  «         |dz   |vr:t          j                             |dz   ¦  «        r|                     |dz   ¦  «         Œ…| 	                    t          ¦   «         ¦  «        }t          j                             ¦   «         }	 t          | ||||||¦  «         |                     ¦   «         D ]7\  }	}
t          j                             |	¦  «        |
k    r|
t          j        |	<   Œ8nQ# |                     ¦   «         D ]7\  }	}
t          j                             |	¦  «        |
k    r|
t          j        |	<   Œ8w xY w|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ÚenvironÚcopyÚbuildÚitemsÚget)r5   r)   r   r*   r+   Úcompile_extraÚ
link_extraÚsÚsaved_environÚkeyÚvalues              r$   r1   r1   µ   s  € å
„|�wÒÐØ"˜ˆØ!¥B¤G§L¢Lµ´À&Ñ$IÔ$IÑIÐJˆ
ˆ
Ý	Œ×	 Ò	  Ñ	)Ô	)ð ðKð Kð Kˆàˆ
ˆ
à%)Ð)ˆ˜
ØÝ
„|�wÒÐØ 8 *Ñ,ˆ
Ý
„|�xÒÐà(ð 	/ð 	/ˆAØ�I‘ \Ð1Ð1ÝœŸš q¨9¡}Ñ5Ô5ð 2à×#Ò# A¨	¡MÑ2Ô2Ð2Ø�5‰y Ð,Ð,µ´·²ÀÀEÁ	Ñ1JÔ1JÐ,Ø×#Ò# A¨¡IÑ.Ô.Ð.øà#×/Ò/µ±´Ñ@Ô@€NÝ”J—O’OÑ%Ô%€Mð
(ÝØ�>Ø˜:Ø˜) \ñ	3ô 	3ð 	3ð (×-Ò-Ñ/Ô/ð 	(ð 	(‰JˆC�ÝŒz�~Š~˜cÑ"Ô" eÒ+Ð+Ø"'•”
˜3‘øð	(ø˜-×-Ò-Ñ/Ô/ð 	(ð 	(‰JˆC�ÝŒz�~Š~˜cÑ"Ô" eÒ+Ð+Ø"'•”
˜3‘øð	(øøøð Ðs   ÅF= Æ=AHc                 óØ  ‡ — ddl m}  |dd¬¦  «        }|                     d¦  «         g }	t          j        ¦   «         }
t          j        ‰ j        ¦  «         	 |                     t          ‰ j	        ¦  «        g||¬¦  «        }|	ˆ fd„|D ¦   «         z  }	t          j        |
¦  «         n# t          j        |
¦  «         w xY w| 
                    |	t          |¦  «        |||¬	¦  «         d
S )z@cd into the directory where the cfile is, use distutils to buildr   )Únew_compileré   é   )ÚforceÚverboser   )r   Úextra_preargsc                 ó>   •— g | ]}t          ‰j        |z  ¦  «        ‘ŒS © )r;   Úparent)Ú.0Úrr5   s     €r$   ú
<listcomp>zbuild.<locals>.<listcomp>í   s(   ø€ Ð7Ð7Ð7¨a•C˜œ qÑ(Ñ)Ô)Ð7Ð7Ð7r6   )r*   rr   r+   N)Únumpy.distutils.ccompilerrm   Ú	customizerZ   ÚgetcwdÚchdirru   Úcompiler;   r2   Úlink_shared_object)r5   r)   rf   rg   r   r*   r+   rm   ÚcompilerÚobjectsÚoldÚress   `           r$   rc   rc   Ü   s  ø€ ð 7Ð6Ð6Ð6Ð6Ð6àˆ| !¨QÐ/Ñ/Ô/€HØ×Ò�rÑÔÐØ€Gå
Œ)‰+Œ+€CÝ„HˆUŒ\ÑÔÐðØ×ÒÝ�”‰_Œ_ÐØ%Ø'ð ñ ô ˆð
 	Ð7Ð7Ð7Ð7°3Ð7Ñ7Ô7Ñ7ˆå
Œ�‰Œˆˆø�Œ�‰Œˆˆøøøà×ÒØ•�^Ñ$Ô$ØØ Ø!ð	  ñ #ô #ð #ð #ð #s   Á<B* Â*C c                  ó6   — t          j        d¦  «        } | sJ ‚| S )NÚ
EXT_SUFFIX)r/   r0   )Úrets    r$   r`   r`   ø   s    € Ý
Ô
" <Ñ
0Ô
0€CØ€J€J€JØ€Jr6   )Ú__doc__rZ   r   rX   r/   Ú__all__r   r   r.   r   r   r1   rc   r`   rt   r6   r$   ú<module>rˆ      sú   ððð ð 
€	€	€	Ø €€€Ø 
€
€
€
Ø Ð Ð Ð à'Ð)CÐ
D€ð )+°dØ 2ð>ð >ð >ð >ð >ðF "$°"ð
ð 
ð 
ð 
ðBð ð ð%ð %ð %ðPð ð ð$ 46ÀØð$ð $ð $ð $ðN#ð #ð #ð8ð ð ð ð r6   