Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
172 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
"""test_root_package | ||
---------------------------------- | ||
Ensure that skbuild supports the root package, i.e. the nameless top level | ||
"package". | ||
""" | ||
|
||
from . import project_setup_py_test | ||
|
||
|
||
@project_setup_py_test(("unit", "root-package"), ["build"], clear_cache=True) | ||
def test_hello_builds(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cmake_minimum_required(VERSION 3.5.0) | ||
|
||
project(root-package) | ||
|
||
enable_testing() | ||
|
||
find_package(PythonInterp REQUIRED) | ||
find_package(PythonLibs REQUIRED) | ||
find_package(PythonExtensions REQUIRED) | ||
|
||
add_subdirectory(lib) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
add_library(_hello MODULE _hello.cxx) | ||
python_extension_module(_hello) | ||
|
||
add_test(NAME hello | ||
COMMAND ${PYTHON_EXECUTABLE} -m hello | ||
WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}) | ||
|
||
install(TARGETS _hello LIBRARY DESTINATION "lib") | ||
install(FILES hello.py DESTINATION "lib") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
// Python includes | ||
#include <Python.h> | ||
|
||
// STD includes | ||
#include <stdio.h> | ||
|
||
//----------------------------------------------------------------------------- | ||
static PyObject *hello_example(PyObject *self, PyObject *args) | ||
{ | ||
// Unpack a string from the arguments | ||
const char *strArg; | ||
if (!PyArg_ParseTuple(args, "s", &strArg)) | ||
return NULL; | ||
|
||
// Print message and return None | ||
PySys_WriteStdout("Hello, %s! :)\n", strArg); | ||
Py_RETURN_NONE; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
static PyObject *elevation_example(PyObject *self, PyObject *args) | ||
{ | ||
// Return an integer | ||
return PyLong_FromLong(21463L); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
static PyMethodDef hello_methods[] = { | ||
{ | ||
"hello", | ||
hello_example, | ||
METH_VARARGS, | ||
"Prints back 'Hello <param>', for example example: hello.hello('you')" | ||
}, | ||
|
||
{ | ||
"size", | ||
elevation_example, | ||
METH_VARARGS, | ||
"Returns elevation of Nevado Sajama." | ||
}, | ||
{NULL, NULL, 0, NULL} /* Sentinel */ | ||
}; | ||
|
||
//----------------------------------------------------------------------------- | ||
#if PY_MAJOR_VERSION < 3 | ||
PyMODINIT_FUNC init_hello(void) | ||
{ | ||
(void) Py_InitModule("_hello", hello_methods); | ||
} | ||
#else /* PY_MAJOR_VERSION >= 3 */ | ||
static struct PyModuleDef hello_module_def = { | ||
PyModuleDef_HEAD_INIT, | ||
"_hello", | ||
"Internal \"_hello\" module", | ||
-1, | ||
hello_methods | ||
}; | ||
|
||
PyMODINIT_FUNC PyInit__hello(void) | ||
{ | ||
return PyModule_Create(&hello_module_def); | ||
} | ||
#endif /* PY_MAJOR_VERSION >= 3 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from ._hello import hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from skbuild import setup | ||
|
||
setup( | ||
name="root-package", | ||
version="1.2.3", | ||
description="a package that populates the root (nameless) package", | ||
author='The scikit-build team', | ||
license="MIT", | ||
package_dir={'': 'lib'}, | ||
py_modules=['hello'] | ||
) |