diff --git a/noxfile.py b/noxfile.py index 749b158..2c950bb 100644 --- a/noxfile.py +++ b/noxfile.py @@ -10,6 +10,7 @@ "hello-cpp", "hello-pybind11", "hello-cython", + "core-cython-hello", "hello-cmake-package", "pi-fortran", ] diff --git a/projects/core-cython-hello/CMakeLists.txt b/projects/core-cython-hello/CMakeLists.txt new file mode 100644 index 0000000..daeb9ba --- /dev/null +++ b/projects/core-cython-hello/CMakeLists.txt @@ -0,0 +1,13 @@ +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 MODULE REQUIRED VERSION 3.0) +include(UseCython) + +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..f91f9cf --- /dev/null +++ b/projects/core-cython-hello/hello/CMakeLists.txt @@ -0,0 +1,5 @@ +cython_transpile(_hello.pyx LANGUAGE C OUTPUT_VARIABLE _hello_c) + +python_add_library(_hello MODULE "${_hello_c}" 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..c6a2cc7 --- /dev/null +++ b/projects/core-cython-hello/hello/__init__.py @@ -0,0 +1,3 @@ +from ._hello import elevation, hello + +__all__ = ("elevation", "hello") diff --git a/projects/core-cython-hello/hello/_hello.pyx b/projects/core-cython-hello/hello/_hello.pyx new file mode 100644 index 0000000..d619787 --- /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 21463 diff --git a/projects/core-cython-hello/pyproject.toml b/projects/core-cython-hello/pyproject.toml new file mode 100644 index 0000000..cf180d4 --- /dev/null +++ b/projects/core-cython-hello/pyproject.toml @@ -0,0 +1,20 @@ +[build-system] +requires = ["scikit-build-core", "cython>=3.0", "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.9" +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