bundles / numpy 2.4.3 / numpy / testing / _private / extbuild / build_and_import_extension
function
numpy.testing._private.extbuild:build_and_import_extension
Signature
def build_and_import_extension(modname, functions, *, prologue = '', build_dir = None, include_dirs = None, more_init = '')Summary
Build and imports a c-extension module modname from a list of function fragments functions.
Parameters
functions: list of fragmentsEach fragment is a sequence of func_name, calling convention, snippet.
prologue: stringCode to precede the rest, usually extra
#includeor#definemacros.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
: out: moduleThe module will have been loaded and is ready for use
Examples
functions = [("test_bytes", "METH_O", """ mod = build_and_import_extension("testme", functions) assert not mod.test_bytes('abc') assert mod.test_bytes(b'abc')
Aliases
numpy.testing.extbuild.build_and_import_extension