Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests of package traversal #906

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/packages/importlib_editable/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.15...3.26)
project(${SKBUILD_PROJECT_NAME} LANGUAGES C)

find_package(
Python
COMPONENTS Interpreter Development.Module
REQUIRED)

add_subdirectory(pkg)
8 changes: 8 additions & 0 deletions tests/packages/importlib_editable/pkg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
python_add_library(pkg MODULE pkg.c WITH_SOABI)

install(TARGETS pkg DESTINATION pkg/)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/)

add_subdirectory(subpkg1)
add_subdirectory(subpkg2)
3 changes: 3 additions & 0 deletions tests/packages/importlib_editable/pkg/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import pure, subpkg1, subpkg2

__all__ = ["pure", "subpkg1", "subpkg2"]
25 changes: 25 additions & 0 deletions tests/packages/importlib_editable/pkg/pkg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>

float square(float x) { return x * x; }

static PyObject *square_wrapper(PyObject *self, PyObject *args) {
float input, result;
if (!PyArg_ParseTuple(args, "f", &input)) {
return NULL;
}
result = square(input);
return PyFloat_FromDouble(result);
}

static PyMethodDef pkg_methods[] = {
{"square", square_wrapper, METH_VARARGS, "Square function"},
{NULL, NULL, 0, NULL}};

static struct PyModuleDef pkg_module = {PyModuleDef_HEAD_INIT, "pkg",
NULL, -1, pkg_methods};

/* name here must match extension name, with PyInit_ prefix */
PyMODINIT_FUNC PyInit_pkg(void) {
return PyModule_Create(&pkg_module);
}
2 changes: 2 additions & 0 deletions tests/packages/importlib_editable/pkg/pure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def square(x):
return x * x
5 changes: 5 additions & 0 deletions tests/packages/importlib_editable/pkg/subpkg1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
python_add_library(subpkg1 MODULE subpkg1.c WITH_SOABI)

install(TARGETS subpkg1 DESTINATION pkg/subpkg1)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/subpkg1)
3 changes: 3 additions & 0 deletions tests/packages/importlib_editable/pkg/subpkg1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import pure

__all__ = ["pure"]
2 changes: 2 additions & 0 deletions tests/packages/importlib_editable/pkg/subpkg1/pure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def square(x):
return x * x
25 changes: 25 additions & 0 deletions tests/packages/importlib_editable/pkg/subpkg1/subpkg1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>

float square(float x) { return x * x; }

static PyObject *square_wrapper(PyObject *self, PyObject *args) {
float input, result;
if (!PyArg_ParseTuple(args, "f", &input)) {
return NULL;
}
result = square(input);
return PyFloat_FromDouble(result);
}

static PyMethodDef subpkg1_methods[] = {
{"square", square_wrapper, METH_VARARGS, "Square function"},
{NULL, NULL, 0, NULL}};

static struct PyModuleDef subpkg1_module = {PyModuleDef_HEAD_INIT, "subpkg1",
NULL, -1, subpkg1_methods};

/* name here must match extension name, with PyInit_ prefix */
PyMODINIT_FUNC PyInit_subpkg1(void) {
return PyModule_Create(&subpkg1_module);
}
8 changes: 8 additions & 0 deletions tests/packages/importlib_editable/pkg/subpkg2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
python_add_library(subpkg2 MODULE subpkg2.c WITH_SOABI)

install(TARGETS subpkg2 DESTINATION pkg/subpkg2)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/subpkg2)

add_subdirectory(subsubpkg1)
add_subdirectory(subsubpkg2)
3 changes: 3 additions & 0 deletions tests/packages/importlib_editable/pkg/subpkg2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import pure, subsubpkg1, subsubpkg2

__all__ = ["pure", "subsubpkg1", "subsubpkg2"]
2 changes: 2 additions & 0 deletions tests/packages/importlib_editable/pkg/subpkg2/pure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def square(x):
return x * x
25 changes: 25 additions & 0 deletions tests/packages/importlib_editable/pkg/subpkg2/subpkg2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>

float square(float x) { return x * x; }

static PyObject *square_wrapper(PyObject *self, PyObject *args) {
float input, result;
if (!PyArg_ParseTuple(args, "f", &input)) {
return NULL;
}
result = square(input);
return PyFloat_FromDouble(result);
}

static PyMethodDef subpkg2_methods[] = {
{"square", square_wrapper, METH_VARARGS, "Square function"},
{NULL, NULL, 0, NULL}};

static struct PyModuleDef subpkg2_module = {PyModuleDef_HEAD_INIT, "subpkg2",
NULL, -1, subpkg2_methods};

/* name here must match extension name, with PyInit_ prefix */
PyMODINIT_FUNC PyInit_subpkg2(void) {
return PyModule_Create(&subpkg2_module);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
python_add_library(subsubpkg1 MODULE subsubpkg1.c WITH_SOABI)

install(TARGETS subsubpkg1 DESTINATION pkg/subpkg2/subsubpkg1)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile"
DESTINATION pkg/subpkg2/subsubpkg1/)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import pure

__all__ = ["pure"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def square(x):
return x * x
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>

float square(float x) { return x * x; }

static PyObject *square_wrapper(PyObject *self, PyObject *args) {
float input, result;
if (!PyArg_ParseTuple(args, "f", &input)) {
return NULL;
}
result = square(input);
return PyFloat_FromDouble(result);
}

static PyMethodDef subsubpkg1_methods[] = {
{"square", square_wrapper, METH_VARARGS, "Square function"},
{NULL, NULL, 0, NULL}};

static struct PyModuleDef subsubpkg1_module = {PyModuleDef_HEAD_INIT, "subsubpkg1",
NULL, -1, subsubpkg1_methods};

/* name here must match extension name, with PyInit_ prefix */
PyMODINIT_FUNC PyInit_subsubpkg1(void) {
return PyModule_Create(&subsubpkg1_module);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
python_add_library(subsubpkg2 MODULE subsubpkg2.c WITH_SOABI)

install(TARGETS subsubpkg2 DESTINATION pkg/subpkg2/subsubpkg2/)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile"
DESTINATION pkg/subpkg2/subsubpkg2/)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import pure

__all__ = ["pure"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def square(x):
return x * x
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>

float square(float x) { return x * x; }

static PyObject *square_wrapper(PyObject *self, PyObject *args) {
float input, result;
if (!PyArg_ParseTuple(args, "f", &input)) {
return NULL;
}
result = square(input);
return PyFloat_FromDouble(result);
}

static PyMethodDef subsubpkg2_methods[] = {
{"square", square_wrapper, METH_VARARGS, "Square function"},
{NULL, NULL, 0, NULL}};

static struct PyModuleDef subsubpkg2_module = {PyModuleDef_HEAD_INIT, "subsubpkg2",
NULL, -2, subsubpkg2_methods};

/* name here must match extension name, with PyInit_ prefix */
PyMODINIT_FUNC PyInit_subsubpkg2(void) {
return PyModule_Create(&subsubpkg2_module);
}
10 changes: 10 additions & 0 deletions tests/packages/importlib_editable/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[build-system]
requires = ["scikit-build-core"]
build-backend = "scikit_build_core.build"

[project]
name = "pkg"
version = "0.0.1"

[tool.scikit-build]
build-dir = "build/{wheel_tag}"
Loading
Loading