Skip to content

Add core cython hello #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
22 changes: 19 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions projects/core-cython-hello/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 9 additions & 0 deletions projects/core-cython-hello/hello/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
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__ = ("hello", "elevation")
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 21463L
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[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"
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