You are viewing an older version (2.4.3). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.4.3 / numpy / testing / _private / extbuild / build_and_import_extension

function

numpy.testing._private.extbuild:build_and_import_extension

source: /numpy/testing/_private/extbuild.py :17

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 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", """
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