From 56ee6eb4fffc4ab2e6c5c2906a3f54788f714f72 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Fri, 12 Jul 2024 16:48:23 -0700 Subject: [PATCH 1/9] Add full set of new tests --- .../importlib_editable/CMakeLists.txt | 9 + .../importlib_editable/pkg/CMakeLists.txt | 8 + .../importlib_editable/pkg/__init__.py | 3 + tests/packages/importlib_editable/pkg/pkg.c | 25 +++ tests/packages/importlib_editable/pkg/pure.py | 2 + .../pkg/subpkg1/CMakeLists.txt | 5 + .../pkg/subpkg1/__init__.py | 3 + .../importlib_editable/pkg/subpkg1/pure.py | 2 + .../importlib_editable/pkg/subpkg1/subpkg1.c | 25 +++ .../pkg/subpkg2/CMakeLists.txt | 8 + .../pkg/subpkg2/__init__.py | 3 + .../importlib_editable/pkg/subpkg2/pure.py | 2 + .../importlib_editable/pkg/subpkg2/subpkg2.c | 25 +++ .../pkg/subpkg2/subsubpkg1/CMakeLists.txt | 6 + .../pkg/subpkg2/subsubpkg1/__init__.py | 3 + .../pkg/subpkg2/subsubpkg1/pure.py | 2 + .../pkg/subpkg2/subsubpkg1/subsubpkg1.c | 25 +++ .../pkg/subpkg2/subsubpkg2/CMakeLists.txt | 6 + .../pkg/subpkg2/subsubpkg2/__init__.py | 3 + .../pkg/subpkg2/subsubpkg2/pure.py | 2 + .../pkg/subpkg2/subsubpkg2/subsubpkg2.c | 25 +++ .../importlib_editable/pyproject.toml | 10 + tests/test_editable.py | 188 ++++++++++++++++++ 23 files changed, 390 insertions(+) create mode 100644 tests/packages/importlib_editable/CMakeLists.txt create mode 100644 tests/packages/importlib_editable/pkg/CMakeLists.txt create mode 100644 tests/packages/importlib_editable/pkg/__init__.py create mode 100644 tests/packages/importlib_editable/pkg/pkg.c create mode 100644 tests/packages/importlib_editable/pkg/pure.py create mode 100644 tests/packages/importlib_editable/pkg/subpkg1/CMakeLists.txt create mode 100644 tests/packages/importlib_editable/pkg/subpkg1/__init__.py create mode 100644 tests/packages/importlib_editable/pkg/subpkg1/pure.py create mode 100644 tests/packages/importlib_editable/pkg/subpkg1/subpkg1.c create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/CMakeLists.txt create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/__init__.py create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/pure.py create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/subpkg2.c create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/CMakeLists.txt create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/__init__.py create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/pure.py create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/subsubpkg1.c create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/CMakeLists.txt create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/__init__.py create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/pure.py create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/subsubpkg2.c create mode 100644 tests/packages/importlib_editable/pyproject.toml diff --git a/tests/packages/importlib_editable/CMakeLists.txt b/tests/packages/importlib_editable/CMakeLists.txt new file mode 100644 index 00000000..0863d78e --- /dev/null +++ b/tests/packages/importlib_editable/CMakeLists.txt @@ -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) diff --git a/tests/packages/importlib_editable/pkg/CMakeLists.txt b/tests/packages/importlib_editable/pkg/CMakeLists.txt new file mode 100644 index 00000000..0a07d102 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/CMakeLists.txt @@ -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) diff --git a/tests/packages/importlib_editable/pkg/__init__.py b/tests/packages/importlib_editable/pkg/__init__.py new file mode 100644 index 00000000..931c3ff1 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/__init__.py @@ -0,0 +1,3 @@ +from . import pure, subpkg1, subpkg2 + +__all__ = ["pure", "subpkg1", "subpkg2"] diff --git a/tests/packages/importlib_editable/pkg/pkg.c b/tests/packages/importlib_editable/pkg/pkg.c new file mode 100644 index 00000000..6a303da3 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/pkg.c @@ -0,0 +1,25 @@ +#define PY_SSIZE_T_CLEAN +#include + +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); +} diff --git a/tests/packages/importlib_editable/pkg/pure.py b/tests/packages/importlib_editable/pkg/pure.py new file mode 100644 index 00000000..caf28fe9 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/pure.py @@ -0,0 +1,2 @@ +def square(x): + return x * x diff --git a/tests/packages/importlib_editable/pkg/subpkg1/CMakeLists.txt b/tests/packages/importlib_editable/pkg/subpkg1/CMakeLists.txt new file mode 100644 index 00000000..1696ad76 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg1/CMakeLists.txt @@ -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) diff --git a/tests/packages/importlib_editable/pkg/subpkg1/__init__.py b/tests/packages/importlib_editable/pkg/subpkg1/__init__.py new file mode 100644 index 00000000..888c1dc3 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg1/__init__.py @@ -0,0 +1,3 @@ +from . import pure + +__all__ = ["pure"] diff --git a/tests/packages/importlib_editable/pkg/subpkg1/pure.py b/tests/packages/importlib_editable/pkg/subpkg1/pure.py new file mode 100644 index 00000000..caf28fe9 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg1/pure.py @@ -0,0 +1,2 @@ +def square(x): + return x * x diff --git a/tests/packages/importlib_editable/pkg/subpkg1/subpkg1.c b/tests/packages/importlib_editable/pkg/subpkg1/subpkg1.c new file mode 100644 index 00000000..cdfb22cf --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg1/subpkg1.c @@ -0,0 +1,25 @@ +#define PY_SSIZE_T_CLEAN +#include + +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); +} diff --git a/tests/packages/importlib_editable/pkg/subpkg2/CMakeLists.txt b/tests/packages/importlib_editable/pkg/subpkg2/CMakeLists.txt new file mode 100644 index 00000000..1a2b9d6b --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg2/CMakeLists.txt @@ -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) diff --git a/tests/packages/importlib_editable/pkg/subpkg2/__init__.py b/tests/packages/importlib_editable/pkg/subpkg2/__init__.py new file mode 100644 index 00000000..e611a3b8 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg2/__init__.py @@ -0,0 +1,3 @@ +from . import pure, subsubpkg1, subsubpkg2 + +__all__ = ["pure", "subsubpkg1", "subsubpkg2"] diff --git a/tests/packages/importlib_editable/pkg/subpkg2/pure.py b/tests/packages/importlib_editable/pkg/subpkg2/pure.py new file mode 100644 index 00000000..caf28fe9 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg2/pure.py @@ -0,0 +1,2 @@ +def square(x): + return x * x diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subpkg2.c b/tests/packages/importlib_editable/pkg/subpkg2/subpkg2.c new file mode 100644 index 00000000..4a1e4b48 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg2/subpkg2.c @@ -0,0 +1,25 @@ +#define PY_SSIZE_T_CLEAN +#include + +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); +} diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/CMakeLists.txt b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/CMakeLists.txt new file mode 100644 index 00000000..812aef4d --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/CMakeLists.txt @@ -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/) diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/__init__.py b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/__init__.py new file mode 100644 index 00000000..888c1dc3 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/__init__.py @@ -0,0 +1,3 @@ +from . import pure + +__all__ = ["pure"] diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/pure.py b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/pure.py new file mode 100644 index 00000000..caf28fe9 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/pure.py @@ -0,0 +1,2 @@ +def square(x): + return x * x diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/subsubpkg1.c b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/subsubpkg1.c new file mode 100644 index 00000000..0da41bea --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/subsubpkg1.c @@ -0,0 +1,25 @@ +#define PY_SSIZE_T_CLEAN +#include + +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); +} diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/CMakeLists.txt b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/CMakeLists.txt new file mode 100644 index 00000000..0ffd74cc --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/CMakeLists.txt @@ -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/) diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/__init__.py b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/__init__.py new file mode 100644 index 00000000..888c1dc3 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/__init__.py @@ -0,0 +1,3 @@ +from . import pure + +__all__ = ["pure"] diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/pure.py b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/pure.py new file mode 100644 index 00000000..caf28fe9 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/pure.py @@ -0,0 +1,2 @@ +def square(x): + return x * x diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/subsubpkg2.c b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/subsubpkg2.c new file mode 100644 index 00000000..de4aa397 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/subsubpkg2.c @@ -0,0 +1,25 @@ +#define PY_SSIZE_T_CLEAN +#include + +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); +} diff --git a/tests/packages/importlib_editable/pyproject.toml b/tests/packages/importlib_editable/pyproject.toml new file mode 100644 index 00000000..dae7eb5a --- /dev/null +++ b/tests/packages/importlib_editable/pyproject.toml @@ -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}" diff --git a/tests/test_editable.py b/tests/test_editable.py index 1d54d866..0dfffbdd 100644 --- a/tests/test_editable.py +++ b/tests/test_editable.py @@ -156,3 +156,191 @@ def test_install_dir(isolated): assert "Running cmake" in out assert c_module.exists() assert not failed_c_module.exists() + + +def _setup_package_for_editable_layout_tests( + monkeypatch, tmp_path, editable, editable_mode, isolated +): + editable_flag = ["-e"] if editable else [] + + config_mode_flags = [] + if editable: + config_mode_flags.append(f"--config-settings=editable.mode={editable_mode}") + if editable_mode != "inplace": + config_mode_flags.append("--config-settings=build-dir=build/{wheel_tag}") + + # Use a context so that we only change into the directory up until the point where + # we run the editable install. We do not want to be in that directory when importing + # to avoid importing the source directory instead of the installed package. + with monkeypatch.context() as m: + package = PackageInfo("importlib_editable") + process_package(package, tmp_path, m) + + ninja = [ + "ninja" + for f in isolated.wheelhouse.iterdir() + if f.name.startswith("ninja-") + ] + cmake = [ + "cmake" + for f in isolated.wheelhouse.iterdir() + if f.name.startswith("cmake-") + ] + + isolated.install("pip>23") + isolated.install("scikit-build-core", *ninja, *cmake) + + isolated.install( + "-v", + *config_mode_flags, + "--no-build-isolation", + *editable_flag, + ".", + ) + + +@pytest.mark.compile +@pytest.mark.configure +@pytest.mark.integration +@pytest.mark.parametrize( + ("editable", "editable_mode"), [(False, ""), (True, "redirect"), (True, "inplace")] +) +def test_direct_import(monkeypatch, tmp_path, editable, editable_mode, isolated): + _setup_package_for_editable_layout_tests( # type: ignore[no-untyped-call] + monkeypatch, tmp_path, editable, editable_mode, isolated + ) + isolated.execute( + textwrap.dedent( + """ + import pkg + import pkg.pure + import pkg.subpkg1 + import pkg.subpkg1.pure + import pkg.subpkg2 + import pkg.subpkg2.pure + import pkg.subpkg2.subsubpkg1 + import pkg.subpkg2.subsubpkg1.pure + import pkg.subpkg2.subsubpkg2 + import pkg.subpkg2.subsubpkg2.pure + """ + ) + ) + + +@pytest.mark.compile +@pytest.mark.configure +@pytest.mark.integration +@pytest.mark.parametrize( + ("editable", "editable_mode", "check"), + [ + # Without editable + (False, "", "isinstance(files(pkg), pathlib.Path)"), + (False, "", "any(str(x).endswith('.so') for x in files(pkg).iterdir())"), + (False, "", "isinstance(files(pkg.subpkg1), pathlib.Path)"), + ( + False, + "", + "any(str(x).endswith('.so') for x in files(pkg.subpkg1).iterdir())", + ), + (False, "", "isinstance(files(pkg.subpkg2), pathlib.Path)"), + ( + False, + "", + "any(str(x).endswith('.so') for x in files(pkg.subpkg2).iterdir())", + ), + (False, "", "isinstance(files(pkg.subpkg2.subsubpkg1), pathlib.Path)"), + ( + False, + "", + "any(str(x).endswith('.so') for x in files(pkg.subpkg2.subsubpkg1).iterdir())", + ), + (False, "", "isinstance(files(pkg.subpkg2.subsubpkg2), pathlib.Path)"), + ( + False, + "", + "any(str(x).endswith('.so') for x in files(pkg.subpkg2.subsubpkg2).iterdir())", + ), + # Editable redirect + (True, "redirect", "isinstance(files(pkg), pathlib.Path)"), + pytest.param( + True, + "redirect", + "any(str(x).endswith('.so') for x in files(pkg).iterdir())", + marks=pytest.mark.xfail, + ), + (True, "redirect", "isinstance(files(pkg.subpkg1), pathlib.Path)"), + pytest.param( + True, + "redirect", + "any(str(x).endswith('.so') for x in files(pkg.subpkg1).iterdir())", + marks=pytest.mark.xfail, + ), + (True, "redirect", "isinstance(files(pkg.subpkg2), pathlib.Path)"), + pytest.param( + True, + "redirect", + "any(str(x).endswith('.so') for x in files(pkg.subpkg2).iterdir())", + marks=pytest.mark.xfail, + ), + (True, "redirect", "isinstance(files(pkg.subpkg2.subsubpkg1), pathlib.Path)"), + pytest.param( + True, + "redirect", + "any(str(x).endswith('.so') for x in files(pkg.subpkg2.subsubpkg1).iterdir())", + marks=pytest.mark.xfail, + ), + (True, "redirect", "isinstance(files(pkg.subpkg2.subsubpkg2), pathlib.Path)"), + pytest.param( + True, + "redirect", + "any(str(x).endswith('.so') for x in files(pkg.subpkg2.subsubpkg2).iterdir())", + marks=pytest.mark.xfail, + ), + # Editable inplace + (True, "inplace", "isinstance(files(pkg), pathlib.Path)"), + (True, "inplace", "any(str(x).endswith('.so') for x in files(pkg).iterdir())"), + (True, "inplace", "isinstance(files(pkg.subpkg1), pathlib.Path)"), + ( + True, + "inplace", + "any(str(x).endswith('.so') for x in files(pkg.subpkg1).iterdir())", + ), + (True, "inplace", "isinstance(files(pkg.subpkg2), pathlib.Path)"), + ( + True, + "inplace", + "any(str(x).endswith('.so') for x in files(pkg.subpkg2).iterdir())", + ), + (True, "inplace", "isinstance(files(pkg.subpkg2.subsubpkg1), pathlib.Path)"), + ( + True, + "inplace", + "any(str(x).endswith('.so') for x in files(pkg.subpkg2.subsubpkg1).iterdir())", + ), + (True, "inplace", "isinstance(files(pkg.subpkg2.subsubpkg2), pathlib.Path)"), + ( + True, + "inplace", + "any(str(x).endswith('.so') for x in files(pkg.subpkg2.subsubpkg2).iterdir())", + ), + ], +) +def test_importlib_resources( + monkeypatch, tmp_path, editable, editable_mode, isolated, check +): + _setup_package_for_editable_layout_tests( # type: ignore[no-untyped-call] + monkeypatch, tmp_path, editable, editable_mode, isolated + ) + value = isolated.execute( + textwrap.dedent( + f""" + from importlib.resources import files + from importlib.readers import MultiplexedPath + import pkg + import pathlib + print({check}) + """ + ) + ) + + assert value == "True" From 6c8bb9a6e1a2f41333501f5d71ba9f801ae3987b Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Fri, 18 Oct 2024 14:36:08 -0700 Subject: [PATCH 2/9] Move assert into subprocess --- tests/test_editable.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test_editable.py b/tests/test_editable.py index 0dfffbdd..9df671a7 100644 --- a/tests/test_editable.py +++ b/tests/test_editable.py @@ -331,16 +331,14 @@ def test_importlib_resources( _setup_package_for_editable_layout_tests( # type: ignore[no-untyped-call] monkeypatch, tmp_path, editable, editable_mode, isolated ) - value = isolated.execute( + isolated.execute( textwrap.dedent( f""" from importlib.resources import files from importlib.readers import MultiplexedPath import pkg import pathlib - print({check}) + assert {check} """ ) ) - - assert value == "True" From 84a04ba03bdf3e9295dab428083c24106b18732f Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Fri, 18 Oct 2024 14:47:35 -0700 Subject: [PATCH 3/9] Also import all extension modules in __init__.py files --- tests/packages/importlib_editable/pkg/__init__.py | 4 ++-- tests/packages/importlib_editable/pkg/pkg.pyi | 0 tests/packages/importlib_editable/pkg/subpkg1/__init__.py | 4 ++-- tests/packages/importlib_editable/pkg/subpkg1/subpkg1.pyi | 0 tests/packages/importlib_editable/pkg/subpkg2/__init__.py | 4 ++-- tests/packages/importlib_editable/pkg/subpkg2/subpkg2.pyi | 0 .../importlib_editable/pkg/subpkg2/subsubpkg1/__init__.py | 4 ++-- .../importlib_editable/pkg/subpkg2/subsubpkg1/subsubpkg1.pyi | 0 .../importlib_editable/pkg/subpkg2/subsubpkg2/__init__.py | 4 ++-- .../importlib_editable/pkg/subpkg2/subsubpkg2/subsubpkg2.pyi | 0 10 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 tests/packages/importlib_editable/pkg/pkg.pyi create mode 100644 tests/packages/importlib_editable/pkg/subpkg1/subpkg1.pyi create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/subpkg2.pyi create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/subsubpkg1.pyi create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/subsubpkg2.pyi diff --git a/tests/packages/importlib_editable/pkg/__init__.py b/tests/packages/importlib_editable/pkg/__init__.py index 931c3ff1..df21698d 100644 --- a/tests/packages/importlib_editable/pkg/__init__.py +++ b/tests/packages/importlib_editable/pkg/__init__.py @@ -1,3 +1,3 @@ -from . import pure, subpkg1, subpkg2 +from . import pkg, pure, subpkg1, subpkg2 -__all__ = ["pure", "subpkg1", "subpkg2"] +__all__ = ["pure", "pkg", "subpkg1", "subpkg2"] diff --git a/tests/packages/importlib_editable/pkg/pkg.pyi b/tests/packages/importlib_editable/pkg/pkg.pyi new file mode 100644 index 00000000..e69de29b diff --git a/tests/packages/importlib_editable/pkg/subpkg1/__init__.py b/tests/packages/importlib_editable/pkg/subpkg1/__init__.py index 888c1dc3..c244d6be 100644 --- a/tests/packages/importlib_editable/pkg/subpkg1/__init__.py +++ b/tests/packages/importlib_editable/pkg/subpkg1/__init__.py @@ -1,3 +1,3 @@ -from . import pure +from . import pure, subpkg1 -__all__ = ["pure"] +__all__ = ["pure", "subpkg1"] diff --git a/tests/packages/importlib_editable/pkg/subpkg1/subpkg1.pyi b/tests/packages/importlib_editable/pkg/subpkg1/subpkg1.pyi new file mode 100644 index 00000000..e69de29b diff --git a/tests/packages/importlib_editable/pkg/subpkg2/__init__.py b/tests/packages/importlib_editable/pkg/subpkg2/__init__.py index e611a3b8..6c5f61b9 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/__init__.py +++ b/tests/packages/importlib_editable/pkg/subpkg2/__init__.py @@ -1,3 +1,3 @@ -from . import pure, subsubpkg1, subsubpkg2 +from . import pure, subpkg2, subsubpkg1, subsubpkg2 -__all__ = ["pure", "subsubpkg1", "subsubpkg2"] +__all__ = ["pure", "subpkg2", "subsubpkg1", "subsubpkg2"] diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subpkg2.pyi b/tests/packages/importlib_editable/pkg/subpkg2/subpkg2.pyi new file mode 100644 index 00000000..e69de29b diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/__init__.py b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/__init__.py index 888c1dc3..e08bfdd0 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/__init__.py +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/__init__.py @@ -1,3 +1,3 @@ -from . import pure +from . import pure, subsubpkg1 -__all__ = ["pure"] +__all__ = ["pure", "subsubpkg1"] diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/subsubpkg1.pyi b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/subsubpkg1.pyi new file mode 100644 index 00000000..e69de29b diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/__init__.py b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/__init__.py index 888c1dc3..2132dee5 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/__init__.py +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/__init__.py @@ -1,3 +1,3 @@ -from . import pure +from . import pure, subsubpkg2 -__all__ = ["pure"] +__all__ = ["pure", "subsubpkg2"] diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/subsubpkg2.pyi b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/subsubpkg2.pyi new file mode 100644 index 00000000..e69de29b From 81a422416e39c819d10dc458d87200970f14b39f Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Fri, 18 Oct 2024 14:50:11 -0700 Subject: [PATCH 4/9] Remove now duplicative imports --- tests/test_editable.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/tests/test_editable.py b/tests/test_editable.py index 9df671a7..e3877ff9 100644 --- a/tests/test_editable.py +++ b/tests/test_editable.py @@ -209,22 +209,7 @@ def test_direct_import(monkeypatch, tmp_path, editable, editable_mode, isolated) _setup_package_for_editable_layout_tests( # type: ignore[no-untyped-call] monkeypatch, tmp_path, editable, editable_mode, isolated ) - isolated.execute( - textwrap.dedent( - """ - import pkg - import pkg.pure - import pkg.subpkg1 - import pkg.subpkg1.pure - import pkg.subpkg2 - import pkg.subpkg2.pure - import pkg.subpkg2.subsubpkg1 - import pkg.subpkg2.subsubpkg1.pure - import pkg.subpkg2.subsubpkg2 - import pkg.subpkg2.subsubpkg2.pure - """ - ) - ) + isolated.execute("import pkg") @pytest.mark.compile From 35f6128c07f33b8bb6e36771302b9bedac9930a9 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Fri, 18 Oct 2024 15:47:00 -0700 Subject: [PATCH 5/9] Differentiate module and package names --- .../importlib_editable/pkg/CMakeLists.txt | 4 +-- .../importlib_editable/pkg/__init__.py | 4 +-- .../pkg/{pkg.c => emod_a.c} | 10 ++++---- .../pkg/{pkg.pyi => emod_a.pyi} | 0 .../pkg/{pure.py => pmod_a.py} | 0 .../pkg/subpkg1/CMakeLists.txt | 4 +-- .../pkg/subpkg1/__init__.py | 4 +-- .../pkg/subpkg1/{subpkg1.c => emod_b.c} | 10 ++++---- .../pkg/subpkg1/{subpkg1.pyi => emod_b.pyi} | 0 .../pkg/subpkg1/{pure.py => pmod_b.py} | 0 .../pkg/subpkg2/CMakeLists.txt | 4 +-- .../pkg/subpkg2/__init__.py | 4 +-- .../pkg/subpkg2/{subpkg2.c => emod_c.c} | 10 ++++---- .../pkg/subpkg2/{subpkg2.pyi => emod_c.pyi} | 0 .../pkg/subpkg2/{pure.py => pmod_c.py} | 0 .../pkg/subpkg2/subsubpkg1/CMakeLists.txt | 4 +-- .../pkg/subpkg2/subsubpkg1/__init__.py | 4 +-- .../subsubpkg1/{subsubpkg1.c => emod_d.c} | 10 ++++---- .../subsubpkg1/{subsubpkg1.pyi => emod_d.pyi} | 0 .../subpkg2/subsubpkg1/{pure.py => pmod_d.py} | 0 .../pkg/subpkg2/subsubpkg2/CMakeLists.txt | 4 +-- .../pkg/subpkg2/subsubpkg2/__init__.py | 4 +-- .../pkg/subpkg2/subsubpkg2/emod_e.c | 25 +++++++++++++++++++ .../subsubpkg2/{subsubpkg2.pyi => emod_e.pyi} | 0 .../subpkg2/subsubpkg2/{pure.py => pmod_e.py} | 0 .../pkg/subpkg2/subsubpkg2/subsubpkg2.c | 25 ------------------- 26 files changed, 65 insertions(+), 65 deletions(-) rename tests/packages/importlib_editable/pkg/{pkg.c => emod_a.c} (63%) rename tests/packages/importlib_editable/pkg/{pkg.pyi => emod_a.pyi} (100%) rename tests/packages/importlib_editable/pkg/{pure.py => pmod_a.py} (100%) rename tests/packages/importlib_editable/pkg/subpkg1/{subpkg1.c => emod_b.c} (63%) rename tests/packages/importlib_editable/pkg/subpkg1/{subpkg1.pyi => emod_b.pyi} (100%) rename tests/packages/importlib_editable/pkg/subpkg1/{pure.py => pmod_b.py} (100%) rename tests/packages/importlib_editable/pkg/subpkg2/{subpkg2.c => emod_c.c} (63%) rename tests/packages/importlib_editable/pkg/subpkg2/{subpkg2.pyi => emod_c.pyi} (100%) rename tests/packages/importlib_editable/pkg/subpkg2/{pure.py => pmod_c.py} (100%) rename tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/{subsubpkg1.c => emod_d.c} (61%) rename tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/{subsubpkg1.pyi => emod_d.pyi} (100%) rename tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/{pure.py => pmod_d.py} (100%) create mode 100644 tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/emod_e.c rename tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/{subsubpkg2.pyi => emod_e.pyi} (100%) rename tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/{pure.py => pmod_e.py} (100%) delete mode 100644 tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/subsubpkg2.c diff --git a/tests/packages/importlib_editable/pkg/CMakeLists.txt b/tests/packages/importlib_editable/pkg/CMakeLists.txt index 0a07d102..600c8f6e 100644 --- a/tests/packages/importlib_editable/pkg/CMakeLists.txt +++ b/tests/packages/importlib_editable/pkg/CMakeLists.txt @@ -1,6 +1,6 @@ -python_add_library(pkg MODULE pkg.c WITH_SOABI) +python_add_library(emod_a MODULE emod_a.c WITH_SOABI) -install(TARGETS pkg DESTINATION pkg/) +install(TARGETS emod_a DESTINATION pkg/) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/) diff --git a/tests/packages/importlib_editable/pkg/__init__.py b/tests/packages/importlib_editable/pkg/__init__.py index df21698d..221322be 100644 --- a/tests/packages/importlib_editable/pkg/__init__.py +++ b/tests/packages/importlib_editable/pkg/__init__.py @@ -1,3 +1,3 @@ -from . import pkg, pure, subpkg1, subpkg2 +from . import emod_a, pmod_a, subpkg1, subpkg2 -__all__ = ["pure", "pkg", "subpkg1", "subpkg2"] +__all__ = ["emod_a", "pmod_a", "subpkg1", "subpkg2"] diff --git a/tests/packages/importlib_editable/pkg/pkg.c b/tests/packages/importlib_editable/pkg/emod_a.c similarity index 63% rename from tests/packages/importlib_editable/pkg/pkg.c rename to tests/packages/importlib_editable/pkg/emod_a.c index 6a303da3..043116ca 100644 --- a/tests/packages/importlib_editable/pkg/pkg.c +++ b/tests/packages/importlib_editable/pkg/emod_a.c @@ -12,14 +12,14 @@ static PyObject *square_wrapper(PyObject *self, PyObject *args) { return PyFloat_FromDouble(result); } -static PyMethodDef pkg_methods[] = { +static PyMethodDef emod_a_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}; +static struct PyModuleDef emod_a_module = {PyModuleDef_HEAD_INIT, "emod_a", + NULL, -1, emod_a_methods}; /* name here must match extension name, with PyInit_ prefix */ -PyMODINIT_FUNC PyInit_pkg(void) { - return PyModule_Create(&pkg_module); +PyMODINIT_FUNC PyInit_emod_a(void) { + return PyModule_Create(&emod_a_module); } diff --git a/tests/packages/importlib_editable/pkg/pkg.pyi b/tests/packages/importlib_editable/pkg/emod_a.pyi similarity index 100% rename from tests/packages/importlib_editable/pkg/pkg.pyi rename to tests/packages/importlib_editable/pkg/emod_a.pyi diff --git a/tests/packages/importlib_editable/pkg/pure.py b/tests/packages/importlib_editable/pkg/pmod_a.py similarity index 100% rename from tests/packages/importlib_editable/pkg/pure.py rename to tests/packages/importlib_editable/pkg/pmod_a.py diff --git a/tests/packages/importlib_editable/pkg/subpkg1/CMakeLists.txt b/tests/packages/importlib_editable/pkg/subpkg1/CMakeLists.txt index 1696ad76..135921f4 100644 --- a/tests/packages/importlib_editable/pkg/subpkg1/CMakeLists.txt +++ b/tests/packages/importlib_editable/pkg/subpkg1/CMakeLists.txt @@ -1,5 +1,5 @@ -python_add_library(subpkg1 MODULE subpkg1.c WITH_SOABI) +python_add_library(emod_b MODULE emod_b.c WITH_SOABI) -install(TARGETS subpkg1 DESTINATION pkg/subpkg1) +install(TARGETS emod_b DESTINATION pkg/subpkg1) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/subpkg1) diff --git a/tests/packages/importlib_editable/pkg/subpkg1/__init__.py b/tests/packages/importlib_editable/pkg/subpkg1/__init__.py index c244d6be..7eb1259b 100644 --- a/tests/packages/importlib_editable/pkg/subpkg1/__init__.py +++ b/tests/packages/importlib_editable/pkg/subpkg1/__init__.py @@ -1,3 +1,3 @@ -from . import pure, subpkg1 +from . import emod_b, pmod_b -__all__ = ["pure", "subpkg1"] +__all__ = ["emod_b", "pmod_b"] diff --git a/tests/packages/importlib_editable/pkg/subpkg1/subpkg1.c b/tests/packages/importlib_editable/pkg/subpkg1/emod_b.c similarity index 63% rename from tests/packages/importlib_editable/pkg/subpkg1/subpkg1.c rename to tests/packages/importlib_editable/pkg/subpkg1/emod_b.c index cdfb22cf..51b14bb7 100644 --- a/tests/packages/importlib_editable/pkg/subpkg1/subpkg1.c +++ b/tests/packages/importlib_editable/pkg/subpkg1/emod_b.c @@ -12,14 +12,14 @@ static PyObject *square_wrapper(PyObject *self, PyObject *args) { return PyFloat_FromDouble(result); } -static PyMethodDef subpkg1_methods[] = { +static PyMethodDef emod_b_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}; +static struct PyModuleDef emod_b_module = {PyModuleDef_HEAD_INIT, "emod_b", + NULL, -1, emod_b_methods}; /* name here must match extension name, with PyInit_ prefix */ -PyMODINIT_FUNC PyInit_subpkg1(void) { - return PyModule_Create(&subpkg1_module); +PyMODINIT_FUNC PyInit_emod_b(void) { + return PyModule_Create(&emod_b_module); } diff --git a/tests/packages/importlib_editable/pkg/subpkg1/subpkg1.pyi b/tests/packages/importlib_editable/pkg/subpkg1/emod_b.pyi similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg1/subpkg1.pyi rename to tests/packages/importlib_editable/pkg/subpkg1/emod_b.pyi diff --git a/tests/packages/importlib_editable/pkg/subpkg1/pure.py b/tests/packages/importlib_editable/pkg/subpkg1/pmod_b.py similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg1/pure.py rename to tests/packages/importlib_editable/pkg/subpkg1/pmod_b.py diff --git a/tests/packages/importlib_editable/pkg/subpkg2/CMakeLists.txt b/tests/packages/importlib_editable/pkg/subpkg2/CMakeLists.txt index 1a2b9d6b..61797133 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/CMakeLists.txt +++ b/tests/packages/importlib_editable/pkg/subpkg2/CMakeLists.txt @@ -1,6 +1,6 @@ -python_add_library(subpkg2 MODULE subpkg2.c WITH_SOABI) +python_add_library(emod_c MODULE emod_c.c WITH_SOABI) -install(TARGETS subpkg2 DESTINATION pkg/subpkg2) +install(TARGETS emod_c DESTINATION pkg/subpkg2) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/subpkg2) diff --git a/tests/packages/importlib_editable/pkg/subpkg2/__init__.py b/tests/packages/importlib_editable/pkg/subpkg2/__init__.py index 6c5f61b9..7d9438b0 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/__init__.py +++ b/tests/packages/importlib_editable/pkg/subpkg2/__init__.py @@ -1,3 +1,3 @@ -from . import pure, subpkg2, subsubpkg1, subsubpkg2 +from . import emod_c, pmod_c, subsubpkg1, subsubpkg2 -__all__ = ["pure", "subpkg2", "subsubpkg1", "subsubpkg2"] +__all__ = ["emod_c", "pmod_c", "subsubpkg1", "subsubpkg2"] diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subpkg2.c b/tests/packages/importlib_editable/pkg/subpkg2/emod_c.c similarity index 63% rename from tests/packages/importlib_editable/pkg/subpkg2/subpkg2.c rename to tests/packages/importlib_editable/pkg/subpkg2/emod_c.c index 4a1e4b48..7cefd9d2 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/subpkg2.c +++ b/tests/packages/importlib_editable/pkg/subpkg2/emod_c.c @@ -12,14 +12,14 @@ static PyObject *square_wrapper(PyObject *self, PyObject *args) { return PyFloat_FromDouble(result); } -static PyMethodDef subpkg2_methods[] = { +static PyMethodDef emod_c_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}; +static struct PyModuleDef emod_c_module = {PyModuleDef_HEAD_INIT, "emod_c", + NULL, -1, emod_c_methods}; /* name here must match extension name, with PyInit_ prefix */ -PyMODINIT_FUNC PyInit_subpkg2(void) { - return PyModule_Create(&subpkg2_module); +PyMODINIT_FUNC PyInit_emod_c(void) { + return PyModule_Create(&emod_c_module); } diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subpkg2.pyi b/tests/packages/importlib_editable/pkg/subpkg2/emod_c.pyi similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/subpkg2.pyi rename to tests/packages/importlib_editable/pkg/subpkg2/emod_c.pyi diff --git a/tests/packages/importlib_editable/pkg/subpkg2/pure.py b/tests/packages/importlib_editable/pkg/subpkg2/pmod_c.py similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/pure.py rename to tests/packages/importlib_editable/pkg/subpkg2/pmod_c.py diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/CMakeLists.txt b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/CMakeLists.txt index 812aef4d..ba119af9 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/CMakeLists.txt +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/CMakeLists.txt @@ -1,6 +1,6 @@ -python_add_library(subsubpkg1 MODULE subsubpkg1.c WITH_SOABI) +python_add_library(emod_d MODULE emod_d.c WITH_SOABI) -install(TARGETS subsubpkg1 DESTINATION pkg/subpkg2/subsubpkg1) +install(TARGETS emod_d 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/) diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/__init__.py b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/__init__.py index e08bfdd0..d41c38b3 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/__init__.py +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/__init__.py @@ -1,3 +1,3 @@ -from . import pure, subsubpkg1 +from . import emod_d, pmod_d -__all__ = ["pure", "subsubpkg1"] +__all__ = ["emod_d", "pmod_d"] diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/subsubpkg1.c b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/emod_d.c similarity index 61% rename from tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/subsubpkg1.c rename to tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/emod_d.c index 0da41bea..c1ca4f2e 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/subsubpkg1.c +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/emod_d.c @@ -12,14 +12,14 @@ static PyObject *square_wrapper(PyObject *self, PyObject *args) { return PyFloat_FromDouble(result); } -static PyMethodDef subsubpkg1_methods[] = { +static PyMethodDef emod_d_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}; +static struct PyModuleDef emod_d_module = {PyModuleDef_HEAD_INIT, "emod_d", + NULL, -1, emod_d_methods}; /* name here must match extension name, with PyInit_ prefix */ -PyMODINIT_FUNC PyInit_subsubpkg1(void) { - return PyModule_Create(&subsubpkg1_module); +PyMODINIT_FUNC PyInit_emod_d(void) { + return PyModule_Create(&emod_d_module); } diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/subsubpkg1.pyi b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/emod_d.pyi similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/subsubpkg1.pyi rename to tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/emod_d.pyi diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/pure.py b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/pmod_d.py similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/pure.py rename to tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/pmod_d.py diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/CMakeLists.txt b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/CMakeLists.txt index 0ffd74cc..e8d824d7 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/CMakeLists.txt +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/CMakeLists.txt @@ -1,6 +1,6 @@ -python_add_library(subsubpkg2 MODULE subsubpkg2.c WITH_SOABI) +python_add_library(emod_e MODULE emod_e.c WITH_SOABI) -install(TARGETS subsubpkg2 DESTINATION pkg/subpkg2/subsubpkg2/) +install(TARGETS emod_e 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/) diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/__init__.py b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/__init__.py index 2132dee5..3ca2841d 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/__init__.py +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/__init__.py @@ -1,3 +1,3 @@ -from . import pure, subsubpkg2 +from . import emod_e, pmod_e -__all__ = ["pure", "subsubpkg2"] +__all__ = ["pmod_e", "emod_e"] diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/emod_e.c b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/emod_e.c new file mode 100644 index 00000000..878fd1c6 --- /dev/null +++ b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/emod_e.c @@ -0,0 +1,25 @@ +#define PY_SSIZE_T_CLEAN +#include + +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 emod_e_methods[] = { + {"square", square_wrapper, METH_VARARGS, "Square function"}, + {NULL, NULL, 0, NULL}}; + +static struct PyModuleDef emod_e_module = {PyModuleDef_HEAD_INIT, "emod_e", + NULL, -2, emod_e_methods}; + +/* name here must match extension name, with PyInit_ prefix */ +PyMODINIT_FUNC PyInit_emod_e(void) { + return PyModule_Create(&emod_e_module); +} diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/subsubpkg2.pyi b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/emod_e.pyi similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/subsubpkg2.pyi rename to tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/emod_e.pyi diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/pure.py b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/pmod_e.py similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/pure.py rename to tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/pmod_e.py diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/subsubpkg2.c b/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/subsubpkg2.c deleted file mode 100644 index de4aa397..00000000 --- a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/subsubpkg2.c +++ /dev/null @@ -1,25 +0,0 @@ -#define PY_SSIZE_T_CLEAN -#include - -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); -} From 8a5f301c0cdba7b18fb54103c4e9865d34b81f5b Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Fri, 18 Oct 2024 16:02:21 -0700 Subject: [PATCH 6/9] Add more nested imports --- .../importlib_editable/pkg/__init__.py | 49 ++++++++++++++++++- .../pkg/subpkg2/__init__.py | 32 +++++++++++- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/tests/packages/importlib_editable/pkg/__init__.py b/tests/packages/importlib_editable/pkg/__init__.py index 221322be..5756375d 100644 --- a/tests/packages/importlib_editable/pkg/__init__.py +++ b/tests/packages/importlib_editable/pkg/__init__.py @@ -1,3 +1,48 @@ -from . import emod_a, pmod_a, subpkg1, subpkg2 +# Don't let ruff sort imports in this file, we want to keep them with the comments as is +# for clarity. +# ruff: noqa: I001 -__all__ = ["emod_a", "pmod_a", "subpkg1", "subpkg2"] +# Level one pure modules +from . import pmod_a + +# Level one extension modules +from . import emod_a + +# Level one subpackages +from . import subpkg1, subpkg2 + +# Level two pure modules +from .subpkg1 import pmod_b +from .subpkg2 import pmod_c + +# Level two extension modules +from .subpkg1 import emod_b +from .subpkg2 import emod_c + +# Level two subpackages +from .subpkg2 import subsubpkg1, subsubpkg2 + +# Level three pure modules +from .subpkg2.subsubpkg1 import pmod_d +from .subpkg2.subsubpkg2 import pmod_e + +# Level three extension modules +from .subpkg2.subsubpkg1 import emod_d +from .subpkg2.subsubpkg2 import emod_e + +__all__ = [ + "emod_a", + "emod_b", + "emod_c", + "emod_d", + "emod_e", + "pmod_a", + "pmod_b", + "pmod_c", + "pmod_d", + "pmod_e", + "subpkg1", + "subpkg2", + "subsubpkg1", + "subsubpkg2", +] diff --git a/tests/packages/importlib_editable/pkg/subpkg2/__init__.py b/tests/packages/importlib_editable/pkg/subpkg2/__init__.py index 7d9438b0..16d2a630 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/__init__.py +++ b/tests/packages/importlib_editable/pkg/subpkg2/__init__.py @@ -1,3 +1,31 @@ -from . import emod_c, pmod_c, subsubpkg1, subsubpkg2 +# Don't let ruff sort imports in this file, we want to keep them with the comments as is +# for clarity. +# ruff: noqa: I001 -__all__ = ["emod_c", "pmod_c", "subsubpkg1", "subsubpkg2"] +# Level one pure modules +from . import pmod_c + +# Level one extension modules +from . import emod_c + +# Level one subpackages +from . import subsubpkg1, subsubpkg2 + +# Level two pure modules +from .subsubpkg1 import pmod_d +from .subsubpkg2 import pmod_e + +# Level two extension modules +from .subsubpkg1 import emod_d +from .subsubpkg2 import emod_e + +__all__ = [ + "emod_c", + "emod_d", + "emod_e", + "pmod_c", + "pmod_d", + "pmod_e", + "subsubpkg1", + "subsubpkg2", +] From 6ad3b64360d74909cc4e158ca639f79add2a014a Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Fri, 18 Oct 2024 16:12:14 -0700 Subject: [PATCH 7/9] Consolidate and simplify package names --- .../importlib_editable/pkg/CMakeLists.txt | 4 +-- .../importlib_editable/pkg/__init__.py | 28 +++++++++---------- .../pkg/{subpkg1 => sub_a}/CMakeLists.txt | 4 +-- .../pkg/{subpkg1 => sub_a}/__init__.py | 0 .../pkg/{subpkg1 => sub_a}/emod_b.c | 0 .../pkg/{subpkg1 => sub_a}/emod_b.pyi | 0 .../pkg/{subpkg1 => sub_a}/pmod_b.py | 0 .../pkg/{subpkg2 => sub_b}/CMakeLists.txt | 8 +++--- .../pkg/{subpkg2 => sub_b}/__init__.py | 14 +++++----- .../pkg/{subpkg2 => sub_b}/emod_c.c | 0 .../pkg/{subpkg2 => sub_b}/emod_c.pyi | 0 .../pkg/{subpkg2 => sub_b}/pmod_c.py | 0 .../subsubpkg1 => sub_b/sub_c}/CMakeLists.txt | 4 +-- .../subsubpkg1 => sub_b/sub_c}/__init__.py | 0 .../subsubpkg1 => sub_b/sub_c}/emod_d.c | 0 .../subsubpkg1 => sub_b/sub_c}/emod_d.pyi | 0 .../subsubpkg1 => sub_b/sub_c}/pmod_d.py | 0 .../subsubpkg2 => sub_b/sub_d}/CMakeLists.txt | 4 +-- .../subsubpkg2 => sub_b/sub_d}/__init__.py | 0 .../subsubpkg2 => sub_b/sub_d}/emod_e.c | 0 .../subsubpkg2 => sub_b/sub_d}/emod_e.pyi | 0 .../subsubpkg2 => sub_b/sub_d}/pmod_e.py | 0 22 files changed, 33 insertions(+), 33 deletions(-) rename tests/packages/importlib_editable/pkg/{subpkg1 => sub_a}/CMakeLists.txt (75%) rename tests/packages/importlib_editable/pkg/{subpkg1 => sub_a}/__init__.py (100%) rename tests/packages/importlib_editable/pkg/{subpkg1 => sub_a}/emod_b.c (100%) rename tests/packages/importlib_editable/pkg/{subpkg1 => sub_a}/emod_b.pyi (100%) rename tests/packages/importlib_editable/pkg/{subpkg1 => sub_a}/pmod_b.py (100%) rename tests/packages/importlib_editable/pkg/{subpkg2 => sub_b}/CMakeLists.txt (61%) rename tests/packages/importlib_editable/pkg/{subpkg2 => sub_b}/__init__.py (67%) rename tests/packages/importlib_editable/pkg/{subpkg2 => sub_b}/emod_c.c (100%) rename tests/packages/importlib_editable/pkg/{subpkg2 => sub_b}/emod_c.pyi (100%) rename tests/packages/importlib_editable/pkg/{subpkg2 => sub_b}/pmod_c.py (100%) rename tests/packages/importlib_editable/pkg/{subpkg2/subsubpkg1 => sub_b/sub_c}/CMakeLists.txt (63%) rename tests/packages/importlib_editable/pkg/{subpkg2/subsubpkg1 => sub_b/sub_c}/__init__.py (100%) rename tests/packages/importlib_editable/pkg/{subpkg2/subsubpkg1 => sub_b/sub_c}/emod_d.c (100%) rename tests/packages/importlib_editable/pkg/{subpkg2/subsubpkg1 => sub_b/sub_c}/emod_d.pyi (100%) rename tests/packages/importlib_editable/pkg/{subpkg2/subsubpkg1 => sub_b/sub_c}/pmod_d.py (100%) rename tests/packages/importlib_editable/pkg/{subpkg2/subsubpkg2 => sub_b/sub_d}/CMakeLists.txt (62%) rename tests/packages/importlib_editable/pkg/{subpkg2/subsubpkg2 => sub_b/sub_d}/__init__.py (100%) rename tests/packages/importlib_editable/pkg/{subpkg2/subsubpkg2 => sub_b/sub_d}/emod_e.c (100%) rename tests/packages/importlib_editable/pkg/{subpkg2/subsubpkg2 => sub_b/sub_d}/emod_e.pyi (100%) rename tests/packages/importlib_editable/pkg/{subpkg2/subsubpkg2 => sub_b/sub_d}/pmod_e.py (100%) diff --git a/tests/packages/importlib_editable/pkg/CMakeLists.txt b/tests/packages/importlib_editable/pkg/CMakeLists.txt index 600c8f6e..9db38f05 100644 --- a/tests/packages/importlib_editable/pkg/CMakeLists.txt +++ b/tests/packages/importlib_editable/pkg/CMakeLists.txt @@ -4,5 +4,5 @@ install(TARGETS emod_a 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) +add_subdirectory(sub_a) +add_subdirectory(sub_b) diff --git a/tests/packages/importlib_editable/pkg/__init__.py b/tests/packages/importlib_editable/pkg/__init__.py index 5756375d..906a2289 100644 --- a/tests/packages/importlib_editable/pkg/__init__.py +++ b/tests/packages/importlib_editable/pkg/__init__.py @@ -9,26 +9,26 @@ from . import emod_a # Level one subpackages -from . import subpkg1, subpkg2 +from . import sub_a, sub_b # Level two pure modules -from .subpkg1 import pmod_b -from .subpkg2 import pmod_c +from .sub_a import pmod_b +from .sub_b import pmod_c # Level two extension modules -from .subpkg1 import emod_b -from .subpkg2 import emod_c +from .sub_a import emod_b +from .sub_b import emod_c # Level two subpackages -from .subpkg2 import subsubpkg1, subsubpkg2 +from .sub_b import sub_c, sub_d # Level three pure modules -from .subpkg2.subsubpkg1 import pmod_d -from .subpkg2.subsubpkg2 import pmod_e +from .sub_b.sub_c import pmod_d +from .sub_b.sub_d import pmod_e # Level three extension modules -from .subpkg2.subsubpkg1 import emod_d -from .subpkg2.subsubpkg2 import emod_e +from .sub_b.sub_c import emod_d +from .sub_b.sub_d import emod_e __all__ = [ "emod_a", @@ -41,8 +41,8 @@ "pmod_c", "pmod_d", "pmod_e", - "subpkg1", - "subpkg2", - "subsubpkg1", - "subsubpkg2", + "sub_a", + "sub_b", + "sub_c", + "sub_d", ] diff --git a/tests/packages/importlib_editable/pkg/subpkg1/CMakeLists.txt b/tests/packages/importlib_editable/pkg/sub_a/CMakeLists.txt similarity index 75% rename from tests/packages/importlib_editable/pkg/subpkg1/CMakeLists.txt rename to tests/packages/importlib_editable/pkg/sub_a/CMakeLists.txt index 135921f4..3e159b33 100644 --- a/tests/packages/importlib_editable/pkg/subpkg1/CMakeLists.txt +++ b/tests/packages/importlib_editable/pkg/sub_a/CMakeLists.txt @@ -1,5 +1,5 @@ python_add_library(emod_b MODULE emod_b.c WITH_SOABI) -install(TARGETS emod_b DESTINATION pkg/subpkg1) +install(TARGETS emod_b DESTINATION pkg/sub_a) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file") -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/subpkg1) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/sub_a) diff --git a/tests/packages/importlib_editable/pkg/subpkg1/__init__.py b/tests/packages/importlib_editable/pkg/sub_a/__init__.py similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg1/__init__.py rename to tests/packages/importlib_editable/pkg/sub_a/__init__.py diff --git a/tests/packages/importlib_editable/pkg/subpkg1/emod_b.c b/tests/packages/importlib_editable/pkg/sub_a/emod_b.c similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg1/emod_b.c rename to tests/packages/importlib_editable/pkg/sub_a/emod_b.c diff --git a/tests/packages/importlib_editable/pkg/subpkg1/emod_b.pyi b/tests/packages/importlib_editable/pkg/sub_a/emod_b.pyi similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg1/emod_b.pyi rename to tests/packages/importlib_editable/pkg/sub_a/emod_b.pyi diff --git a/tests/packages/importlib_editable/pkg/subpkg1/pmod_b.py b/tests/packages/importlib_editable/pkg/sub_a/pmod_b.py similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg1/pmod_b.py rename to tests/packages/importlib_editable/pkg/sub_a/pmod_b.py diff --git a/tests/packages/importlib_editable/pkg/subpkg2/CMakeLists.txt b/tests/packages/importlib_editable/pkg/sub_b/CMakeLists.txt similarity index 61% rename from tests/packages/importlib_editable/pkg/subpkg2/CMakeLists.txt rename to tests/packages/importlib_editable/pkg/sub_b/CMakeLists.txt index 61797133..90af76b2 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/CMakeLists.txt +++ b/tests/packages/importlib_editable/pkg/sub_b/CMakeLists.txt @@ -1,8 +1,8 @@ python_add_library(emod_c MODULE emod_c.c WITH_SOABI) -install(TARGETS emod_c DESTINATION pkg/subpkg2) +install(TARGETS emod_c DESTINATION pkg/sub_b) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file") -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/subpkg2) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" DESTINATION pkg/sub_b) -add_subdirectory(subsubpkg1) -add_subdirectory(subsubpkg2) +add_subdirectory(sub_c) +add_subdirectory(sub_d) diff --git a/tests/packages/importlib_editable/pkg/subpkg2/__init__.py b/tests/packages/importlib_editable/pkg/sub_b/__init__.py similarity index 67% rename from tests/packages/importlib_editable/pkg/subpkg2/__init__.py rename to tests/packages/importlib_editable/pkg/sub_b/__init__.py index 16d2a630..907b1501 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/__init__.py +++ b/tests/packages/importlib_editable/pkg/sub_b/__init__.py @@ -9,15 +9,15 @@ from . import emod_c # Level one subpackages -from . import subsubpkg1, subsubpkg2 +from . import sub_c, sub_d # Level two pure modules -from .subsubpkg1 import pmod_d -from .subsubpkg2 import pmod_e +from .sub_c import pmod_d +from .sub_d import pmod_e # Level two extension modules -from .subsubpkg1 import emod_d -from .subsubpkg2 import emod_e +from .sub_c import emod_d +from .sub_d import emod_e __all__ = [ "emod_c", @@ -26,6 +26,6 @@ "pmod_c", "pmod_d", "pmod_e", - "subsubpkg1", - "subsubpkg2", + "sub_c", + "sub_d", ] diff --git a/tests/packages/importlib_editable/pkg/subpkg2/emod_c.c b/tests/packages/importlib_editable/pkg/sub_b/emod_c.c similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/emod_c.c rename to tests/packages/importlib_editable/pkg/sub_b/emod_c.c diff --git a/tests/packages/importlib_editable/pkg/subpkg2/emod_c.pyi b/tests/packages/importlib_editable/pkg/sub_b/emod_c.pyi similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/emod_c.pyi rename to tests/packages/importlib_editable/pkg/sub_b/emod_c.pyi diff --git a/tests/packages/importlib_editable/pkg/subpkg2/pmod_c.py b/tests/packages/importlib_editable/pkg/sub_b/pmod_c.py similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/pmod_c.py rename to tests/packages/importlib_editable/pkg/sub_b/pmod_c.py diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/CMakeLists.txt b/tests/packages/importlib_editable/pkg/sub_b/sub_c/CMakeLists.txt similarity index 63% rename from tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/CMakeLists.txt rename to tests/packages/importlib_editable/pkg/sub_b/sub_c/CMakeLists.txt index ba119af9..50bdbdd7 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/CMakeLists.txt +++ b/tests/packages/importlib_editable/pkg/sub_b/sub_c/CMakeLists.txt @@ -1,6 +1,6 @@ python_add_library(emod_d MODULE emod_d.c WITH_SOABI) -install(TARGETS emod_d DESTINATION pkg/subpkg2/subsubpkg1) +install(TARGETS emod_d DESTINATION pkg/sub_b/sub_c) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" - DESTINATION pkg/subpkg2/subsubpkg1/) + DESTINATION pkg/sub_b/sub_c/) diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/__init__.py b/tests/packages/importlib_editable/pkg/sub_b/sub_c/__init__.py similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/__init__.py rename to tests/packages/importlib_editable/pkg/sub_b/sub_c/__init__.py diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/emod_d.c b/tests/packages/importlib_editable/pkg/sub_b/sub_c/emod_d.c similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/emod_d.c rename to tests/packages/importlib_editable/pkg/sub_b/sub_c/emod_d.c diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/emod_d.pyi b/tests/packages/importlib_editable/pkg/sub_b/sub_c/emod_d.pyi similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/emod_d.pyi rename to tests/packages/importlib_editable/pkg/sub_b/sub_c/emod_d.pyi diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/pmod_d.py b/tests/packages/importlib_editable/pkg/sub_b/sub_c/pmod_d.py similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/subsubpkg1/pmod_d.py rename to tests/packages/importlib_editable/pkg/sub_b/sub_c/pmod_d.py diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/CMakeLists.txt b/tests/packages/importlib_editable/pkg/sub_b/sub_d/CMakeLists.txt similarity index 62% rename from tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/CMakeLists.txt rename to tests/packages/importlib_editable/pkg/sub_b/sub_d/CMakeLists.txt index e8d824d7..58af95ba 100644 --- a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/CMakeLists.txt +++ b/tests/packages/importlib_editable/pkg/sub_b/sub_d/CMakeLists.txt @@ -1,6 +1,6 @@ python_add_library(emod_e MODULE emod_e.c WITH_SOABI) -install(TARGETS emod_e DESTINATION pkg/subpkg2/subsubpkg2/) +install(TARGETS emod_e DESTINATION pkg/sub_b/sub_d/) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testfile" "This is the file") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/testfile" - DESTINATION pkg/subpkg2/subsubpkg2/) + DESTINATION pkg/sub_b/sub_d/) diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/__init__.py b/tests/packages/importlib_editable/pkg/sub_b/sub_d/__init__.py similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/__init__.py rename to tests/packages/importlib_editable/pkg/sub_b/sub_d/__init__.py diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/emod_e.c b/tests/packages/importlib_editable/pkg/sub_b/sub_d/emod_e.c similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/emod_e.c rename to tests/packages/importlib_editable/pkg/sub_b/sub_d/emod_e.c diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/emod_e.pyi b/tests/packages/importlib_editable/pkg/sub_b/sub_d/emod_e.pyi similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/emod_e.pyi rename to tests/packages/importlib_editable/pkg/sub_b/sub_d/emod_e.pyi diff --git a/tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/pmod_e.py b/tests/packages/importlib_editable/pkg/sub_b/sub_d/pmod_e.py similarity index 100% rename from tests/packages/importlib_editable/pkg/subpkg2/subsubpkg2/pmod_e.py rename to tests/packages/importlib_editable/pkg/sub_b/sub_d/pmod_e.py From cd2998950b7a9b0b15a6f060599bae592f65174e Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Fri, 18 Oct 2024 16:15:48 -0700 Subject: [PATCH 8/9] Update test_importlib_resources --- tests/test_editable.py | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/test_editable.py b/tests/test_editable.py index e3877ff9..17ae8fa5 100644 --- a/tests/test_editable.py +++ b/tests/test_editable.py @@ -221,29 +221,29 @@ def test_direct_import(monkeypatch, tmp_path, editable, editable_mode, isolated) # Without editable (False, "", "isinstance(files(pkg), pathlib.Path)"), (False, "", "any(str(x).endswith('.so') for x in files(pkg).iterdir())"), - (False, "", "isinstance(files(pkg.subpkg1), pathlib.Path)"), + (False, "", "isinstance(files(pkg.sub_a), pathlib.Path)"), ( False, "", - "any(str(x).endswith('.so') for x in files(pkg.subpkg1).iterdir())", + "any(str(x).endswith('.so') for x in files(pkg.sub_a).iterdir())", ), - (False, "", "isinstance(files(pkg.subpkg2), pathlib.Path)"), + (False, "", "isinstance(files(pkg.sub_b), pathlib.Path)"), ( False, "", - "any(str(x).endswith('.so') for x in files(pkg.subpkg2).iterdir())", + "any(str(x).endswith('.so') for x in files(pkg.sub_b).iterdir())", ), - (False, "", "isinstance(files(pkg.subpkg2.subsubpkg1), pathlib.Path)"), + (False, "", "isinstance(files(pkg.sub_b.sub_c), pathlib.Path)"), ( False, "", - "any(str(x).endswith('.so') for x in files(pkg.subpkg2.subsubpkg1).iterdir())", + "any(str(x).endswith('.so') for x in files(pkg.sub_b.sub_c).iterdir())", ), - (False, "", "isinstance(files(pkg.subpkg2.subsubpkg2), pathlib.Path)"), + (False, "", "isinstance(files(pkg.sub_b.sub_d), pathlib.Path)"), ( False, "", - "any(str(x).endswith('.so') for x in files(pkg.subpkg2.subsubpkg2).iterdir())", + "any(str(x).endswith('.so') for x in files(pkg.sub_b.sub_d).iterdir())", ), # Editable redirect (True, "redirect", "isinstance(files(pkg), pathlib.Path)"), @@ -253,60 +253,60 @@ def test_direct_import(monkeypatch, tmp_path, editable, editable_mode, isolated) "any(str(x).endswith('.so') for x in files(pkg).iterdir())", marks=pytest.mark.xfail, ), - (True, "redirect", "isinstance(files(pkg.subpkg1), pathlib.Path)"), + (True, "redirect", "isinstance(files(pkg.sub_a), pathlib.Path)"), pytest.param( True, "redirect", - "any(str(x).endswith('.so') for x in files(pkg.subpkg1).iterdir())", + "any(str(x).endswith('.so') for x in files(pkg.sub_a).iterdir())", marks=pytest.mark.xfail, ), - (True, "redirect", "isinstance(files(pkg.subpkg2), pathlib.Path)"), + (True, "redirect", "isinstance(files(pkg.sub_b), pathlib.Path)"), pytest.param( True, "redirect", - "any(str(x).endswith('.so') for x in files(pkg.subpkg2).iterdir())", + "any(str(x).endswith('.so') for x in files(pkg.sub_b).iterdir())", marks=pytest.mark.xfail, ), - (True, "redirect", "isinstance(files(pkg.subpkg2.subsubpkg1), pathlib.Path)"), + (True, "redirect", "isinstance(files(pkg.sub_b.sub_c), pathlib.Path)"), pytest.param( True, "redirect", - "any(str(x).endswith('.so') for x in files(pkg.subpkg2.subsubpkg1).iterdir())", + "any(str(x).endswith('.so') for x in files(pkg.sub_b.sub_c).iterdir())", marks=pytest.mark.xfail, ), - (True, "redirect", "isinstance(files(pkg.subpkg2.subsubpkg2), pathlib.Path)"), + (True, "redirect", "isinstance(files(pkg.sub_b.sub_d), pathlib.Path)"), pytest.param( True, "redirect", - "any(str(x).endswith('.so') for x in files(pkg.subpkg2.subsubpkg2).iterdir())", + "any(str(x).endswith('.so') for x in files(pkg.sub_b.sub_d).iterdir())", marks=pytest.mark.xfail, ), # Editable inplace (True, "inplace", "isinstance(files(pkg), pathlib.Path)"), (True, "inplace", "any(str(x).endswith('.so') for x in files(pkg).iterdir())"), - (True, "inplace", "isinstance(files(pkg.subpkg1), pathlib.Path)"), + (True, "inplace", "isinstance(files(pkg.sub_a), pathlib.Path)"), ( True, "inplace", - "any(str(x).endswith('.so') for x in files(pkg.subpkg1).iterdir())", + "any(str(x).endswith('.so') for x in files(pkg.sub_a).iterdir())", ), - (True, "inplace", "isinstance(files(pkg.subpkg2), pathlib.Path)"), + (True, "inplace", "isinstance(files(pkg.sub_b), pathlib.Path)"), ( True, "inplace", - "any(str(x).endswith('.so') for x in files(pkg.subpkg2).iterdir())", + "any(str(x).endswith('.so') for x in files(pkg.sub_b).iterdir())", ), - (True, "inplace", "isinstance(files(pkg.subpkg2.subsubpkg1), pathlib.Path)"), + (True, "inplace", "isinstance(files(pkg.sub_b.sub_c), pathlib.Path)"), ( True, "inplace", - "any(str(x).endswith('.so') for x in files(pkg.subpkg2.subsubpkg1).iterdir())", + "any(str(x).endswith('.so') for x in files(pkg.sub_b.sub_c).iterdir())", ), - (True, "inplace", "isinstance(files(pkg.subpkg2.subsubpkg2), pathlib.Path)"), + (True, "inplace", "isinstance(files(pkg.sub_b.sub_d), pathlib.Path)"), ( True, "inplace", - "any(str(x).endswith('.so') for x in files(pkg.subpkg2.subsubpkg2).iterdir())", + "any(str(x).endswith('.so') for x in files(pkg.sub_b.sub_d).iterdir())", ), ], ) From e1193676e9d4be5875813d61c76d19581cfdc549 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Fri, 18 Oct 2024 16:20:58 -0700 Subject: [PATCH 9/9] Add top-level modules --- .../importlib_editable/CMakeLists.txt | 4 +++ tests/packages/importlib_editable/emod.c | 25 +++++++++++++++++++ tests/packages/importlib_editable/pmod.py | 2 ++ 3 files changed, 31 insertions(+) create mode 100644 tests/packages/importlib_editable/emod.c create mode 100644 tests/packages/importlib_editable/pmod.py diff --git a/tests/packages/importlib_editable/CMakeLists.txt b/tests/packages/importlib_editable/CMakeLists.txt index 0863d78e..7a96fb06 100644 --- a/tests/packages/importlib_editable/CMakeLists.txt +++ b/tests/packages/importlib_editable/CMakeLists.txt @@ -6,4 +6,8 @@ find_package( COMPONENTS Interpreter Development.Module REQUIRED) +python_add_library(emod MODULE emod.c WITH_SOABI) +install(TARGETS emod DESTINATION .) +install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/pmod.py" DESTINATION .) + add_subdirectory(pkg) diff --git a/tests/packages/importlib_editable/emod.c b/tests/packages/importlib_editable/emod.c new file mode 100644 index 00000000..3e71f04e --- /dev/null +++ b/tests/packages/importlib_editable/emod.c @@ -0,0 +1,25 @@ +#define PY_SSIZE_T_CLEAN +#include + +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 emod_methods[] = { + {"square", square_wrapper, METH_VARARGS, "Square function"}, + {NULL, NULL, 0, NULL}}; + +static struct PyModuleDef emod_module = {PyModuleDef_HEAD_INIT, "emod", + NULL, -1, emod_methods}; + +/* name here must match extension name, with PyInit_ prefix */ +PyMODINIT_FUNC PyInit_emod(void) { + return PyModule_Create(&emod_module); +} diff --git a/tests/packages/importlib_editable/pmod.py b/tests/packages/importlib_editable/pmod.py new file mode 100644 index 00000000..caf28fe9 --- /dev/null +++ b/tests/packages/importlib_editable/pmod.py @@ -0,0 +1,2 @@ +def square(x): + return x * x