Skip to content

Commit 56ee6eb

Browse files
committed
Add full set of new tests
1 parent e903ec9 commit 56ee6eb

File tree

23 files changed

+390
-0
lines changed

23 files changed

+390
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.15...3.26)
2+
project(${SKBUILD_PROJECT_NAME} LANGUAGES C)
3+
4+
find_package(
5+
Python
6+
COMPONENTS Interpreter Development.Module
7+
REQUIRED)
8+
9+
add_subdirectory(pkg)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
python_add_library(pkg MODULE pkg.c WITH_SOABI)
2+
3+
install(TARGETS pkg DESTINATION pkg/)
4+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file")
5+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/)
6+
7+
add_subdirectory(subpkg1)
8+
add_subdirectory(subpkg2)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import pure, subpkg1, subpkg2
2+
3+
__all__ = ["pure", "subpkg1", "subpkg2"]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#define PY_SSIZE_T_CLEAN
2+
#include <Python.h>
3+
4+
float square(float x) { return x * x; }
5+
6+
static PyObject *square_wrapper(PyObject *self, PyObject *args) {
7+
float input, result;
8+
if (!PyArg_ParseTuple(args, "f", &input)) {
9+
return NULL;
10+
}
11+
result = square(input);
12+
return PyFloat_FromDouble(result);
13+
}
14+
15+
static PyMethodDef pkg_methods[] = {
16+
{"square", square_wrapper, METH_VARARGS, "Square function"},
17+
{NULL, NULL, 0, NULL}};
18+
19+
static struct PyModuleDef pkg_module = {PyModuleDef_HEAD_INIT, "pkg",
20+
NULL, -1, pkg_methods};
21+
22+
/* name here must match extension name, with PyInit_ prefix */
23+
PyMODINIT_FUNC PyInit_pkg(void) {
24+
return PyModule_Create(&pkg_module);
25+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def square(x):
2+
return x * x
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
python_add_library(subpkg1 MODULE subpkg1.c WITH_SOABI)
2+
3+
install(TARGETS subpkg1 DESTINATION pkg/subpkg1)
4+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file")
5+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/subpkg1)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import pure
2+
3+
__all__ = ["pure"]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def square(x):
2+
return x * x
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#define PY_SSIZE_T_CLEAN
2+
#include <Python.h>
3+
4+
float square(float x) { return x * x; }
5+
6+
static PyObject *square_wrapper(PyObject *self, PyObject *args) {
7+
float input, result;
8+
if (!PyArg_ParseTuple(args, "f", &input)) {
9+
return NULL;
10+
}
11+
result = square(input);
12+
return PyFloat_FromDouble(result);
13+
}
14+
15+
static PyMethodDef subpkg1_methods[] = {
16+
{"square", square_wrapper, METH_VARARGS, "Square function"},
17+
{NULL, NULL, 0, NULL}};
18+
19+
static struct PyModuleDef subpkg1_module = {PyModuleDef_HEAD_INIT, "subpkg1",
20+
NULL, -1, subpkg1_methods};
21+
22+
/* name here must match extension name, with PyInit_ prefix */
23+
PyMODINIT_FUNC PyInit_subpkg1(void) {
24+
return PyModule_Create(&subpkg1_module);
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
python_add_library(subpkg2 MODULE subpkg2.c WITH_SOABI)
2+
3+
install(TARGETS subpkg2 DESTINATION pkg/subpkg2)
4+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file")
5+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/subpkg2)
6+
7+
add_subdirectory(subsubpkg1)
8+
add_subdirectory(subsubpkg2)

0 commit comments

Comments
 (0)