Browse Source

Added scikit-build

Adam Kelly 5 years ago
parent
commit
305682c628
5 changed files with 76 additions and 0 deletions
  1. 2 0
      .gitignore
  2. 9 0
      CMakeLists.txt
  3. 7 0
      setup.py
  4. 2 0
      tangle/__init__.py
  5. 56 0
      tangle/_tangle.cxx

+ 2 - 0
.gitignore

@@ -256,3 +256,5 @@ ENV/
 .pytest_cache
 
 # End of https://www.gitignore.io/api/c,c++,cuda,linux,macos,windows
+
+_skbuild

+ 9 - 0
CMakeLists.txt

@@ -0,0 +1,9 @@
+cmake_minimum_required(VERSION 3.9)
+
+project(tangle)
+
+find_package(PythonExtensions REQUIRED)
+
+add_library(_tangle MODULE tangle/_tangle.cxx)
+python_extension_module(_tangle)
+install(TARGETS _tangle LIBRARY DESTINATION tangle)

+ 7 - 0
setup.py

@@ -0,0 +1,7 @@
+from skbuild import setup
+
+setup(
+    name='tangle',
+    version='0.2.0',
+    packages=['tangle']
+)

+ 2 - 0
tangle/__init__.py

@@ -0,0 +1,2 @@
+from ._tangle import hello
+from ._tangle import elevation

+ 56 - 0
tangle/_tangle.cxx

@@ -0,0 +1,56 @@
+#include <Python.h>
+#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')"},
+
+    {"elevation",
+     elevation_example,
+     METH_VARARGS,
+     "Returns elevation of Nevado Sajama."},
+    {NULL, NULL, 0, NULL} /* Sentinel */
+};
+
+//-----------------------------------------------------------------------------
+#if PY_MAJOR_VERSION < 3
+PyMODINIT_FUNC init_tangle(void)
+{
+    (void)Py_InitModule("_tangle", hello_methods);
+}
+#else  /* PY_MAJOR_VERSION >= 3 */
+static struct PyModuleDef tangle_module_def = {
+    PyModuleDef_HEAD_INIT,
+    "_tangle",
+    "Internal \"_tangle\" module",
+    -1,
+    hello_methods};
+
+PyMODINIT_FUNC PyInit__tangle(void)
+{
+    return PyModule_Create(&tangle_module_def);
+}
+#endif /* PY_MAJOR_VERSION >= 3 */