Skip to content

Commit 543e033

Browse files
committed
Import from scikit-build-sample-projects
0 parents  commit 543e033

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.4.0)
2+
3+
project(hello)
4+
5+
find_package(PythonExtensions REQUIRED)
6+
7+
add_library(_hello MODULE hello/_hello.cxx)
8+
python_extension_module(_hello)
9+
install(TARGETS _hello LIBRARY DESTINATION hello)

hello/__init__.py

Whitespace-only changes.

hello/_hello.cxx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
// Python includes
3+
#include <Python.h>
4+
5+
// STD includes
6+
#include <stdio.h>
7+
8+
//-----------------------------------------------------------------------------
9+
static PyObject *hello_example(PyObject *self, PyObject *args)
10+
{
11+
// Unpack a string from the arguments
12+
const char *strArg;
13+
if (!PyArg_ParseTuple(args, "s", &strArg))
14+
return NULL;
15+
16+
// Print message and return None
17+
PySys_WriteStdout("Hello, %s!)\n", strArg);
18+
Py_RETURN_NONE;
19+
}
20+
21+
//-----------------------------------------------------------------------------
22+
static PyObject *elevation_example(PyObject *self, PyObject *args)
23+
{
24+
// Return an integer
25+
return PyLong_FromLong(21463L);
26+
}
27+
28+
//-----------------------------------------------------------------------------
29+
static PyMethodDef hello_methods[] = {
30+
{
31+
"hello",
32+
hello_example,
33+
METH_VARARGS,
34+
"Prints back 'Hello <param>', for example example: hello.hello('you')"
35+
},
36+
37+
{
38+
"elevation",
39+
elevation_example,
40+
METH_VARARGS,
41+
"Returns elevation of Nevado Sajama."
42+
},
43+
{NULL, NULL, 0, NULL} /* Sentinel */
44+
};
45+
46+
//-----------------------------------------------------------------------------
47+
#if PY_MAJOR_VERSION < 3
48+
PyMODINIT_FUNC init_hello(void)
49+
{
50+
(void) Py_InitModule("_hello", hello_methods);
51+
}
52+
#else /* PY_MAJOR_VERSION >= 3 */
53+
static struct PyModuleDef hello_module_def = {
54+
PyModuleDef_HEAD_INIT,
55+
"_hello",
56+
"Internal \"_hello\" module",
57+
-1,
58+
hello_methods
59+
};
60+
61+
PyMODINIT_FUNC PyInit__hello(void)
62+
{
63+
return PyModule_Create(&hello_module_def);
64+
}
65+
#endif /* PY_MAJOR_VERSION >= 3 */

setup.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
3+
from skbuild import setup
4+
5+
# Require pytest-runner only when running tests
6+
pytest_runner = (['pytest-runner>=2.0,<3dev']
7+
if any(arg in sys.argv for arg in ('pytest', 'test'))
8+
else [])
9+
10+
setup_requires = pytest_runner
11+
12+
setup(
13+
name="hello-cpp",
14+
version="1.2.3",
15+
description="a minimal example package (cpp version)",
16+
author='The scikit-build team',
17+
license="MIT",
18+
packages=['hello'],
19+
tests_require=['pytest'],
20+
setup_requires=setup_requires
21+
)

test_hello_cpp.py

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!"
8+
9+
10+
def test_elevation():
11+
assert hello.elevation() == 21463

0 commit comments

Comments
 (0)