Pārlūkot izejas kodu

Changed from a pure extension to Cython

Adam Kelly 5 gadi atpakaļ
vecāks
revīzija
a64d000939
5 mainītis faili ar 16 papildinājumiem un 62 dzēšanām
  1. 2 2
      setup.py
  2. 11 2
      tangle/CMakeLists.txt
  3. 1 2
      tangle/__init__.py
  4. 0 56
      tangle/_tangle.cpp
  5. 2 0
      tangle/_tangle.pyx

+ 2 - 2
setup.py

@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
 
 setup(
     name="tangle",
-    version="1.0.0",
+    version="1.1.0",
     author="Adam Kelly",
     author_email="adamkelly2201@gmail.com",
     description="High Performance Tools for Quantum Computation",
@@ -26,5 +26,5 @@ setup(
         "Programming Language :: Python :: 3.6",
         "Topic :: Scientific/Engineering",
     ],
-    install_requires=['scikit-build']
+    install_requires=['scikit-build', 'cython']
 )

+ 11 - 2
tangle/CMakeLists.txt

@@ -1,5 +1,14 @@
 find_package(PythonExtensions REQUIRED)
+find_package(Cython REQUIRED)
 
-add_library(_tangle MODULE _tangle.cpp)
+
+# add_library(_tangle MODULE _tangle.cpp)
+# python_extension_module(_tangle)
+# install(TARGETS _tangle LIBRARY DESTINATION tangle)
+
+# add_cython_target(${PROJECT_SOURCE_DIR}/tangle/_tangle.pyx)
+add_cython_target(_tangle.pyx CXX)
+add_library(_tangle MODULE ${_tangle})
 python_extension_module(_tangle)
-install(TARGETS _tangle LIBRARY DESTINATION tangle)
+
+install(TARGETS _tangle LIBRARY DESTINATION tangle)

+ 1 - 2
tangle/__init__.py

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

+ 0 - 56
tangle/_tangle.cpp

@@ -1,56 +0,0 @@
-#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 */

+ 2 - 0
tangle/_tangle.pyx

@@ -0,0 +1,2 @@
+cpdef say_hi ():
+    print("Hello World")