%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib64/python3.9/site-packages/numpy/testing/_private/__pycache__/
Upload File :
Create Path :
Current File : //lib64/python3.9/site-packages/numpy/testing/_private/__pycache__/extbuild.cpython-39.pyc

a

z[yc��@s�dZddlZddlZddlZddlZddgZddgdd�dd�Zggfdd�Zd	d
�Zdd�Z	d
d�Z
gggfdd�Zdd�Zdd�Z
dS)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
Cs�ddlm}|t||�}d}|s,t�d�}|r@|d7}||7}|d7}t|||�}	zt||||	�}
Wn6|y�}ztd|�d��|�WYd	}~n
d	}~00dd	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;zcould not compile in �:N)Zdistutils.errorsr	�
_make_methods�pathlib�Path�_make_sourcer�RuntimeError�importlib.util�util�spec_from_file_location�module_from_spec�loader�exec_module)�modname�	functionsrrrrr	�body�init�
source_stringZmod_so�e�	importlib�specZfoo�r�E/usr/lib64/python3.9/site-packages/numpy/testing/_private/extbuild.pyrs*'
�(c	CsR|�d�d}||}|jdd�t||�}|t�d�g}t||||ggd�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_okZ	INCLUDEPY)�outputfilenamer�	libraries�library_dirs)�split�mkdir�_convert_str_to_file�	sysconfig�get_config_var�
_c_compile)	�nameZbuilddirrrr$r%r�dirname�cfilerrr rPs
�cCsD|d}|�d��}|�t|��Wd�n1s60Y|S)zHelper function to create a file ``source.c`` in `dirname` that contains
    the string in `source`. Returns the file name
    zsource.c�wN)�open�write�str)�sourcer-�filename�frrr r(qs,r(cCs�g}g}|D]V\}}}d||f}d|vr0d}nd}|�d|||f�dj|||d�}	|�|	�qd�|�d	td�|�|d
�}
|
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
    z%s_%sZ
METH_KEYWORDSz2(PyObject *self, PyObject *args, PyObject *kwargs)z (PyObject *self, PyObject *args)z{"%s", (PyCFunction)%s, %s},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)rrZ
methods_tableZcodes�funcname�flagsr8r6r7Z	func_coderrrr r{s$��
�
rcCsdt|||d�}|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
    }
    )r,rr)r>)r,rrr8rrr r�s	��rc
CsXtjdkr(dg}dtj�tjd�g}n"tj�d�rBgd�}d}nd}}tjdkr^|dg}tjdkr�d	D]X}|d
|vr�tj�|d
�r�|�|d
�|d|vrltj�|d�rl|�|d�ql|�	t
��}tj��}zDt
|||||||�W|��D]"\}	}
tj�|	�|
kr�|
tj|	<q�n2|��D]&\}	}
tj�|	�|
k�r*|
tj|	<�q*0|S)N�win32z/we4013z	/LIBPATH:ZlibsZlinux)z-O0z-gz%-Werror=implicit-function-declarationz-fPICz/DEBUG�darwin)z/sw/z/opt/local/Zinclude�lib)�sys�platform�os�pathr=�base_prefix�
startswith�existsr;�with_suffix�
get_so_suffix�environ�copy�build�items�get)r.r#rr$r%�
compile_extra�
link_extra�sZ
saved_environ�key�valuerrr r+�s@



�
��r+c	s�ddlm}|ddd�}|�d�g}	t��}
t��j�z<|jt�j	�g||d�}|	�fdd	�|D�7}	Wt�|
�nt�|
�0|j
|	t|�|||d
�dS)z@cd into the directory where the cfile is, use distutils to buildr)�new_compiler��)�force�verboser)r�
extra_preargscsg|]}t�j|��qSr)r2�parent)�.0�r�r.rr �
<listcomp>��zbuild.<locals>.<listcomp>)r$r\r%N)Znumpy.distutils.ccompilerrWZ	customizerF�getcwd�chdirr]�compiler2r,Zlink_shared_object)r.r#rRrSrr$r%rWZcompilerZobjects�old�resrr`r rO�s(

��rOcCst�d�}|sJ�|S)NZ
EXT_SUFFIX)r)r*)�retrrr rL�s
rL)�__doc__rFr
rDr)�__all__rrr(rrr+rOrLrrrr �<module>s$�C�
!
(�
'

Zerion Mini Shell 1.0