Skip to content

Commit 3d2bc7d

Browse files
committed
Add failing test
1 parent 9d49270 commit 3d2bc7d

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
python_add_library(example MODULE example/example.c WITH_SOABI)
10+
11+
install(TARGETS example DESTINATION example/)
12+
file(WRITE "${CMAKE_BINARY_DIR}/testfile" "This is the file")
13+
install(FILES "${CMAKE_BINARY_DIR}/testfile" DESTINATION example/)

tests/packages/importlib_editable/example/__init__.py

Whitespace-only changes.
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 example_methods[] = {
16+
{"square", square_wrapper, METH_VARARGS, "Square function"},
17+
{NULL, NULL, 0, NULL}};
18+
19+
static struct PyModuleDef example_module = {PyModuleDef_HEAD_INIT, "example",
20+
NULL, -1, example_methods};
21+
22+
/* name here must match extension name, with PyInit_ prefix */
23+
PyMODINIT_FUNC PyInit_example(void) {
24+
return PyModule_Create(&example_module);
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[build-system]
2+
requires = ["scikit-build-core"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "example"
7+
version = "0.0.1"
8+
9+
[tool.scikit-build]
10+
build-dir = "build/{wheel_tag}"

tests/test_editable.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
from pathlib import Path
3+
import textwrap
34

45
import pytest
56
from conftest import PackageInfo, process_package
@@ -105,3 +106,58 @@ def test_cython_pxd(monkeypatch, tmp_path, editable, editable_mode, isolated):
105106
*editable_flag,
106107
".",
107108
)
109+
110+
111+
@pytest.mark.compile()
112+
@pytest.mark.configure()
113+
@pytest.mark.integration()
114+
@pytest.mark.parametrize(
115+
("editable", "editable_mode"), [(False, ""), (True, "redirect"), (True, "inplace")]
116+
)
117+
def test_importlib_resources(monkeypatch, tmp_path, editable, editable_mode, isolated):
118+
editable_flag = ["-e"] if editable else []
119+
120+
config_mode_flags = []
121+
if editable:
122+
config_mode_flags.append(f"--config-settings=editable.mode={editable_mode}")
123+
if editable_mode != "inplace":
124+
config_mode_flags.append("--config-settings=build-dir=build/{wheel_tag}")
125+
126+
# Use a context so that we only change into the directory up until the point where
127+
# we run the editable install. We do not want to be in that directory when importing
128+
# to avoid importing the source directory instead of the installed package.
129+
with monkeypatch.context() as m:
130+
package1 = PackageInfo(
131+
"importlib_editable",
132+
)
133+
process_package(package1, tmp_path, m)
134+
135+
ninja = [
136+
"ninja" for f in isolated.wheelhouse.iterdir() if f.name.startswith("ninja-")
137+
]
138+
cmake = [
139+
"cmake" for f in isolated.wheelhouse.iterdir() if f.name.startswith("cmake-")
140+
]
141+
142+
isolated.install("pip>23")
143+
isolated.install("scikit-build-core", *ninja, *cmake)
144+
145+
isolated.install(
146+
"-v",
147+
*config_mode_flags,
148+
"--no-build-isolation",
149+
*editable_flag,
150+
".",
151+
)
152+
153+
value = isolated.execute(
154+
textwrap.dedent(
155+
"""
156+
import importlib.resources
157+
import example
158+
root = importlib.resources.files(example)
159+
print(any('testfile' in str(x) for x in root.iterdir()))
160+
"""
161+
)
162+
)
163+
assert value == "True"

0 commit comments

Comments
 (0)