Skip to content
Merged
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
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"hello-cpp",
"hello-pybind11",
"hello-cython",
"core-cython-hello",
"hello-cmake-package",
"pi-fortran",
]
Expand Down
13 changes: 13 additions & 0 deletions projects/core-cython-hello/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions projects/core-cython-hello/hello/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
3 changes: 3 additions & 0 deletions projects/core-cython-hello/hello/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ._hello import elevation, hello

__all__ = ("elevation", "hello")
8 changes: 8 additions & 0 deletions projects/core-cython-hello/hello/_hello.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

cpdef void hello(str strArg):
"Prints back 'Hello <param>', for example example: hello.hello('you')"
print("Hello, {}!".format(strArg))

cpdef long elevation():
"Returns elevation of Nevado Sajama."
return 21463
20 changes: 20 additions & 0 deletions projects/core-cython-hello/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 11 additions & 0 deletions projects/core-cython-hello/tests/test_hello_cython.py
Original file line number Diff line number Diff line change
@@ -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
Loading