diff --git a/noxfile.py b/noxfile.py index 2001736..b866ebf 100644 --- a/noxfile.py +++ b/noxfile.py @@ -2,10 +2,26 @@ import nox -hello_list = ["hello-pure", "hello-cpp", "hello-pybind11", "hello-cython"] +hello_list = [ + "hello-pure", + "hello-cpp", + "hello-pybind11", + "hello-cython", + "core-cython-hello", +] if not sys.platform.startswith("win"): - hello_list.extend(["hello-cmake-package", "pi-fortran"]) -long_hello_list = [*hello_list, "pen2-cython", "core-c-hello", "core-pybind11-hello"] + hello_list.extend( + [ + "hello-cmake-package", + "pi-fortran", + ] + ) +long_hello_list = [ + *hello_list, + "pen2-cython", + "core-c-hello", + "core-pybind11-hello", +] @nox.session diff --git a/projects/core-cython-hello/CMakeLists.txt b/projects/core-cython-hello/CMakeLists.txt new file mode 100644 index 0000000..58f4f91 --- /dev/null +++ b/projects/core-cython-hello/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.15...3.26) + +project(${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_VERSION} LANGUAGES C) + +find_package( + Python + COMPONENTS Interpreter Development.Module + REQUIRED) + +find_package( + Cython + REQUIRED) + +add_subdirectory(hello) diff --git a/projects/core-cython-hello/hello/CMakeLists.txt b/projects/core-cython-hello/hello/CMakeLists.txt new file mode 100644 index 0000000..13d5a26 --- /dev/null +++ b/projects/core-cython-hello/hello/CMakeLists.txt @@ -0,0 +1,9 @@ +Cython_compile_pyx(_hello.pyx + OUTPUT_VAR _hello_source_file + ) + +Python_add_library(_hello + MODULE ${_hello_source_file} + WITH_SOABI) + +install(TARGETS _hello LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME}) diff --git a/projects/core-cython-hello/hello/__init__.py b/projects/core-cython-hello/hello/__init__.py new file mode 100644 index 0000000..c6909c7 --- /dev/null +++ b/projects/core-cython-hello/hello/__init__.py @@ -0,0 +1,3 @@ +from ._hello import elevation, hello + +__all__ = ("hello", "elevation") diff --git a/projects/core-cython-hello/hello/_hello.pyx b/projects/core-cython-hello/hello/_hello.pyx new file mode 100644 index 0000000..22a41fa --- /dev/null +++ b/projects/core-cython-hello/hello/_hello.pyx @@ -0,0 +1,8 @@ + +cpdef void hello(str strArg): + "Prints back 'Hello ', for example example: hello.hello('you')" + print("Hello, {}!".format(strArg)) + +cpdef long elevation(): + "Returns elevation of Nevado Sajama." + return 21463L diff --git a/projects/core-cython-hello/pyproject.toml b/projects/core-cython-hello/pyproject.toml new file mode 100644 index 0000000..01fecf3 --- /dev/null +++ b/projects/core-cython-hello/pyproject.toml @@ -0,0 +1,20 @@ +[build-system] +requires = ["scikit-build-core[pyproject]", "cython", "cython-cmake"] +build-backend = "scikit_build_core.build" + +[project] +name = "hello" +version = "1.2.3" +authors = [ + { name = "The scikit-build team" }, +] +description = "a minimal example package (cython version)" +requires-python = ">=3.8" +classifiers = [ + "License :: OSI Approved :: MIT License", +] +dependencies = [] + +[tool.scikit-build] +cmake.source-dir = "." +minimum-version = "0.5" diff --git a/projects/core-cython-hello/tests/test_hello_cython.py b/projects/core-cython-hello/tests/test_hello_cython.py new file mode 100644 index 0000000..8c0927f --- /dev/null +++ b/projects/core-cython-hello/tests/test_hello_cython.py @@ -0,0 +1,11 @@ +import hello + + +def test_hello(capfd): + hello.hello("World") + captured = capfd.readouterr() + assert captured.out == "Hello, World!\n" + + +def test_elevation(): + assert hello.elevation() == 21463