Skip to content

Commit eeefc9d

Browse files
committed
feat(core-cython-hello): Add project using add_custom_command() and cython
1 parent 010f2c4 commit eeefc9d

File tree

7 files changed

+68
-0
lines changed

7 files changed

+68
-0
lines changed

noxfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"hello-cpp",
88
"hello-pybind11",
99
"hello-cython",
10+
"core-cython-hello",
1011
]
1112
if not sys.platform.startswith("win"):
1213
hello_list.extend(
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
find_program(CYTHON "cython")
10+
11+
add_subdirectory(hello)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
add_custom_command(
2+
OUTPUT _hello.c
3+
DEPENDS _hello.pyx
4+
COMMAND "${CYTHON}"
5+
"${CMAKE_CURRENT_SOURCE_DIR}/_hello.pyx"
6+
--output-file "${CMAKE_CURRENT_BINARY_DIR}/_hello.c"
7+
VERBATIM
8+
)
9+
10+
Python_add_library(_hello
11+
MODULE "${CMAKE_CURRENT_BINARY_DIR}/_hello.c"
12+
WITH_SOABI)
13+
14+
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__ = ("hello", "elevation")
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 21463L
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[pyproject]", "cython"]
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.8"
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)