]> sigrok.org Git - libsigrok.git/commitdiff
python: use setuptools and put bindings into sigrok.core.lowlevel.
authorMartin Ling <redacted>
Wed, 17 Apr 2013 02:50:27 +0000 (03:50 +0100)
committerMartin Ling <redacted>
Wed, 17 Apr 2013 02:50:27 +0000 (03:50 +0100)
bindings/python/libsigrok_python.i [deleted file]
bindings/python/setup.py
bindings/python/sigrok/__init__.py [new file with mode: 0644]
bindings/python/sigrok/core/__init__.py [new file with mode: 0644]
bindings/python/sigrok/core/lowlevel.i [new file with mode: 0644]
bindings/swig/libsigrok.i

diff --git a/bindings/python/libsigrok_python.i b/bindings/python/libsigrok_python.i
deleted file mode 100644 (file)
index 6b2c9ee..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * This file is part of the sigrok project.
- *
- * Copyright (C) 2013 Martin Ling <martin-sigrok@earth.li>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-%include "../swig/libsigrok.i"
-
-%{
-
-void sr_datafeed_python_callback(const struct sr_dev_inst *sdi,
-        const struct sr_datafeed_packet *packet, void *cb_data)
-{
-    PyObject *sdi_obj;
-    PyObject *packet_obj;
-    PyObject *arglist;
-    PyObject *result;
-    PyGILState_STATE gstate;
-    PyObject *python_callback;
-
-    python_callback = (PyObject *) cb_data;
-    gstate = PyGILState_Ensure();
-
-    sdi_obj = SWIG_NewPointerObj(SWIG_as_voidptr(sdi),
-            SWIGTYPE_p_sr_dev_inst, 0);
-
-    packet_obj = SWIG_NewPointerObj(SWIG_as_voidptr(packet),
-            SWIGTYPE_p_sr_datafeed_packet, 0);
-
-    arglist = Py_BuildValue("(OO)", sdi_obj, packet_obj);
-
-    result = PyEval_CallObject(python_callback, arglist);
-
-    Py_XDECREF(arglist);
-    Py_XDECREF(sdi_obj);
-    Py_XDECREF(packet_obj);
-    Py_XDECREF(result);
-
-    PyGILState_Release(gstate);
-}
-
-void sr_session_datafeed_python_callback_add(PyObject *cb)
-{
-    if (!PyCallable_Check(cb))
-        PyErr_SetString(PyExc_TypeError, "Object passed is not callable");
-    else
-        sr_session_datafeed_callback_add(
-            sr_datafeed_python_callback, cb);
-}
-
-%}
-
-void sr_session_datafeed_python_callback_add(PyObject *cb);
index 57f9bc627b519671112c8e2fdfad85503dcaab7e..953fa639a693b18ac574538a6dc6900a8bc9aa21 100644 (file)
@@ -17,7 +17,7 @@
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ##
 
-from distutils.core import setup, Extension
+from setuptools import setup, find_packages, Extension
 import subprocess
 
 sr_includes = subprocess.check_output(
@@ -31,12 +31,13 @@ sr_version = subprocess.check_output(
 
 setup(
     name = 'libsigrok',
+    namespace_packages = ['sigrok'],
+    packages = find_packages(),
     version = sr_version,
     description = "libsigrok API wrapper",
-    py_modules = ['libsigrok'],
     ext_modules = [
-        Extension('_libsigrok',
-            sources = ['libsigrok_python.i'],
+        Extension('sigrok.core._lowlevel',
+            sources = ['sigrok/core/lowlevel.i'],
             swig_opts = sr_includes,
             include_dirs = [i[2:] for i in sr_includes if i.startswith('-I')],
             library_dirs = [l[2:] for l in sr_libs if l.startswith('-L')],
diff --git a/bindings/python/sigrok/__init__.py b/bindings/python/sigrok/__init__.py
new file mode 100644 (file)
index 0000000..5284146
--- /dev/null
@@ -0,0 +1 @@
+__import__("pkg_resources").declare_namespace(__name__)
diff --git a/bindings/python/sigrok/core/__init__.py b/bindings/python/sigrok/core/__init__.py
new file mode 100644 (file)
index 0000000..9b280ff
--- /dev/null
@@ -0,0 +1 @@
+import lowlevel
diff --git a/bindings/python/sigrok/core/lowlevel.i b/bindings/python/sigrok/core/lowlevel.i
new file mode 100644 (file)
index 0000000..eaf02a0
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2013 Martin Ling <martin-sigrok@earth.li>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+%module lowlevel
+
+%include "../../../swig/libsigrok.i"
+
+%{
+
+void sr_datafeed_python_callback(const struct sr_dev_inst *sdi,
+        const struct sr_datafeed_packet *packet, void *cb_data)
+{
+    PyObject *sdi_obj;
+    PyObject *packet_obj;
+    PyObject *arglist;
+    PyObject *result;
+    PyGILState_STATE gstate;
+    PyObject *python_callback;
+
+    python_callback = (PyObject *) cb_data;
+    gstate = PyGILState_Ensure();
+
+    sdi_obj = SWIG_NewPointerObj(SWIG_as_voidptr(sdi),
+            SWIGTYPE_p_sr_dev_inst, 0);
+
+    packet_obj = SWIG_NewPointerObj(SWIG_as_voidptr(packet),
+            SWIGTYPE_p_sr_datafeed_packet, 0);
+
+    arglist = Py_BuildValue("(OO)", sdi_obj, packet_obj);
+
+    result = PyEval_CallObject(python_callback, arglist);
+
+    Py_XDECREF(arglist);
+    Py_XDECREF(sdi_obj);
+    Py_XDECREF(packet_obj);
+    Py_XDECREF(result);
+
+    PyGILState_Release(gstate);
+}
+
+void sr_session_datafeed_python_callback_add(PyObject *cb)
+{
+    if (!PyCallable_Check(cb))
+        PyErr_SetString(PyExc_TypeError, "Object passed is not callable");
+    else
+        sr_session_datafeed_callback_add(
+            sr_datafeed_python_callback, cb);
+}
+
+%}
+
+void sr_session_datafeed_python_callback_add(PyObject *cb);
index 56b817cca5848a181368a5e3d21184f1342aee43..8534040d0859ebeae999eeeec8f80915261f94e6 100644 (file)
@@ -17,7 +17,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-%module libsigrok
 %include "cpointer.i"
 %include "carrays.i"
 %include "cdata.i"