-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add python
limited_api
tests for find_installation
and `de…
…pendency` Check that extension_modules and dependencies inherit the installation's limited_api value by default but can override it. Also test the end-to-end case of compiling a library and linking it with an extension, both compiled against the Limited API. This is similar to how nanobind is used.
- Loading branch information
Showing
6 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
test cases/python/11 extmodule limited api lib/meson.build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Test that we can build a library that uses the limited API | ||
# and link it to an extension module. | ||
|
||
project('Python limited api lib', 'c', | ||
default_options : ['buildtype=release', 'werror=true']) | ||
|
||
py_mod = import('python') | ||
py = py_mod.find_installation(limited_api: '3.7') | ||
py_dep = py.dependency(required: true) | ||
|
||
nanolib = static_library( | ||
'nanolib', | ||
'nanolib.c', | ||
dependencies: [py_dep], | ||
) | ||
|
||
ext_mod = py.extension_module('mymodule', | ||
'module.c', | ||
install: true, | ||
link_with: [nanolib], | ||
) | ||
|
||
test('load-test', | ||
py, | ||
args: [files('test_module.py')], | ||
env: { 'PYTHONPATH': meson.current_build_dir() }, | ||
workdir: meson.current_source_dir() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <Python.h> | ||
|
||
#ifndef Py_LIMITED_API | ||
#error Py_LIMITED_API must be defined. | ||
#elif Py_LIMITED_API != 0x03070000 | ||
#error Wrong value for Py_LIMITED_API | ||
#endif | ||
|
||
PyObject * | ||
hello(PyObject * Py_UNUSED(self), PyObject * Py_UNUSED(args)); | ||
|
||
static struct PyMethodDef methods[] = { | ||
{ "hello", hello, METH_NOARGS, NULL }, | ||
{ NULL, NULL, 0, NULL }, | ||
}; | ||
|
||
static struct PyModuleDef mymodule = { | ||
PyModuleDef_HEAD_INIT, | ||
"mymodule", | ||
NULL, | ||
-1, | ||
methods | ||
}; | ||
|
||
PyMODINIT_FUNC PyInit_mymodule(void) { | ||
return PyModule_Create(&mymodule); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <Python.h> | ||
|
||
#ifndef Py_LIMITED_API | ||
#error Py_LIMITED_API must be defined. | ||
#elif Py_LIMITED_API != 0x03070000 | ||
#error Wrong value for Py_LIMITED_API | ||
#endif | ||
|
||
PyObject * | ||
hello(PyObject * Py_UNUSED(self), PyObject * Py_UNUSED(args)) { | ||
return PyUnicode_FromString("hello world"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"installed": [ | ||
{"type": "python_limited_lib", "file": "usr/@PYTHON_PLATLIB@/mymodule"}, | ||
{"type": "py_limited_implib", "file": "usr/@PYTHON_PLATLIB@/mymodule"} | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
test cases/python/11 extmodule limited api lib/test_module.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from mymodule import hello | ||
|
||
def test_hello(): | ||
assert hello() == "hello world" | ||
|
||
test_hello() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters