Skip to content

Commit 752c755

Browse files
authored
feat(core-cython-hello): add sample project using cython-cmake (#43)
Add a minimal scikit-build-core + Cython sample that transpiles a .pyx via the cython-cmake helpers (find_package(Cython) + UseCython + cython_transpile), and register it in the noxfile test/dist lists. Original work by @jcfr and @vyasr; rebased onto main and updated to the current cython-cmake API. Assisted-by: ClaudeCode:claude-opus-4.8
1 parent 44d5c91 commit 752c755

7 files changed

Lines changed: 61 additions & 0 deletions

File tree

noxfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"hello-cpp",
1111
"hello-pybind11",
1212
"hello-cython",
13+
"core-cython-hello",
1314
"hello-cmake-package",
1415
"pi-fortran",
1516
]
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+
3+
project(${SKBUILD_PROJECT_NAME} VERSION ${SKBUILD_PROJECT_VERSION} LANGUAGES C)
4+
5+
find_package(
6+
Python
7+
COMPONENTS Interpreter Development.Module
8+
REQUIRED)
9+
10+
find_package(Cython MODULE REQUIRED VERSION 3.0)
11+
include(UseCython)
12+
13+
add_subdirectory(hello)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cython_transpile(_hello.pyx LANGUAGE C OUTPUT_VARIABLE _hello_c)
2+
3+
python_add_library(_hello MODULE "${_hello_c}" WITH_SOABI)
4+
5+
install(TARGETS _hello LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from ._hello import elevation, hello
2+
3+
__all__ = ("elevation", "hello")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
cpdef void hello(str strArg):
3+
"Prints back 'Hello <param>', for example example: hello.hello('you')"
4+
print("Hello, {}!".format(strArg))
5+
6+
cpdef long elevation():
7+
"Returns elevation of Nevado Sajama."
8+
return 21463
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[build-system]
2+
requires = ["scikit-build-core", "cython>=3.0", "cython-cmake"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "hello"
7+
version = "1.2.3"
8+
authors = [
9+
{ name = "The scikit-build team" },
10+
]
11+
description = "a minimal example package (cython version)"
12+
requires-python = ">=3.9"
13+
classifiers = [
14+
"License :: OSI Approved :: MIT License",
15+
]
16+
dependencies = []
17+
18+
[tool.scikit-build]
19+
cmake.source-dir = "."
20+
minimum-version = "0.5"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import hello
2+
3+
4+
def test_hello(capfd):
5+
hello.hello("World")
6+
captured = capfd.readouterr()
7+
assert captured.out == "Hello, World!\n"
8+
9+
10+
def test_elevation():
11+
assert hello.elevation() == 21463

0 commit comments

Comments
 (0)