module documentation

Build a c-extension module on-the-fly in tests. See build_and_import_extensions for usage hints

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
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 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...
Function _make_source Combines the code fragments into source code ready to be compiled
def build(cfile, outputfilename, compile_extra, link_extra, include_dirs, libraries, library_dirs): (source)

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=''): (source)

Build and imports a c-extension module modname from a list of function fragments functions.

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')
Parameters
modnameUndocumented
functions:list of fragmentsEach fragment is a sequence of func_name, calling convention, snippet.
prologue:stringCode to precede the rest, usually extra #include or #define macros.
build_dir:pathlib.PathWhere to build the module, usually a temporary directory
include_dirs:listExtra directories to find include files when compiling
more_init:stringCode to appear in the module PyMODINIT_FUNC
Returns
moduleout - The module will have been loaded and is ready for use
def compile_extension_module(name, builddir, include_dirs, source_string, libraries=[], library_dirs=[]): (source)

Build an extension module and return the filename of the resulting native code file.

Parameters
name:stringname of the module, possibly including dots if it is a module inside a package.
builddir:pathlib.PathWhere to build the module, usually a temporary directory
include_dirs:listExtra directories to find include files when compiling
source_stringUndocumented
libraries:listLibraries to link into the extension module
library_dirs:listWhere to find the libraries, -L passed to the linker
def get_so_suffix(): (source)

Undocumented

def _c_compile(cfile, outputfilename, include_dirs=[], libraries=[], library_dirs=[]): (source)

Undocumented

def _convert_str_to_file(source, dirname): (source)

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): (source)

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): (source)

Combines the code fragments into source code ready to be compiled