module documentation

Build a c-extension module on-the-fly in tests. See build_and_import_extensions for usage hints
Function ​_c​_compile Undocumented
Function ​_convert​_str​_to​_file Helper function to create a file source.c in dirname that contains the string in source. Returns the file name
Function ​_make​_methods No summary
Function ​_make​_source Combines the code fragments into source code ready to be compiled
Function build cd into the directory where the cfile is, use distutils to build
Function build​_and​_import​_extension Build and imports a c-extension module modname from a list of function fragments functions.
Function compile​_extension​_module Build an extension module and return the filename of the resulting native code file.
Function get​_so​_suffix Undocumented
def _c_compile(cfile, outputfilename, include_dirs=[], libraries=[], library_dirs=[]):

Undocumented

def _convert_str_to_file(source, dirname):
Helper function to create a file source.c in dirname that contains the string in source. Returns the file name
def _make_methods(functions, modname):
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
def _make_source(name, init, body):
Combines the code fragments into source code ready to be compiled
def build(cfile, outputfilename, compile_extra, link_extra, include_dirs, libraries, library_dirs):
cd into the directory where the cfile is, use distutils to build
def build_and_import_extension(modname, functions, *, prologue='', build_dir=None, include_dirs=[], more_init=''):

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 preceed 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')
def compile_extension_module(name, builddir, include_dirs, source_string, libraries=[], library_dirs=[]):

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
def get_so_suffix():

Undocumented