summaryrefslogtreecommitdiff
path: root/peripheral/libmraa/src/python
diff options
context:
space:
mode:
Diffstat (limited to 'peripheral/libmraa/src/python')
-rw-r--r--peripheral/libmraa/src/python/CMakeLists.txt55
-rw-r--r--peripheral/libmraa/src/python/docs/CMakeLists.txt (renamed from peripheral/libmraa/src/python/python2/docs/CMakeLists.txt)2
-rw-r--r--peripheral/libmraa/src/python/docs/conf.py.in (renamed from peripheral/libmraa/src/python/python2/docs/conf.py.in)2
-rw-r--r--peripheral/libmraa/src/python/docs/example.rst (renamed from peripheral/libmraa/src/python/python2/docs/example.rst)6
-rw-r--r--peripheral/libmraa/src/python/docs/index.rst (renamed from peripheral/libmraa/src/python/python2/docs/index.rst)0
-rw-r--r--peripheral/libmraa/src/python/docs/mraa.rst (renamed from peripheral/libmraa/src/python/python2/docs/mraa.rst)0
-rw-r--r--peripheral/libmraa/src/python/mraa.i (renamed from peripheral/libmraa/src/python/mraapython.i)21
-rw-r--r--peripheral/libmraa/src/python/mraapy.c91
-rw-r--r--peripheral/libmraa/src/python/python2/CMakeLists.txt39
-rw-r--r--peripheral/libmraa/src/python/python2/mraa2.i5
-rw-r--r--peripheral/libmraa/src/python/python3/CMakeLists.txt24
-rw-r--r--peripheral/libmraa/src/python/python3/mraa3.i3
12 files changed, 62 insertions, 186 deletions
diff --git a/peripheral/libmraa/src/python/CMakeLists.txt b/peripheral/libmraa/src/python/CMakeLists.txt
index e014fad..1d06b82 100644
--- a/peripheral/libmraa/src/python/CMakeLists.txt
+++ b/peripheral/libmraa/src/python/CMakeLists.txt
@@ -1,5 +1,52 @@
-set_source_files_properties (mraapython.i PROPERTIES CPLUSPLUS ON)
-set_source_files_properties (mraapython.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
+find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
-add_subdirectory (python2)
-add_subdirectory (python3)
+INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
+
+include_directories(
+ ${CMAKE_CURRENT_SOURCE_DIR}/..
+ ${PYTHON_INCLUDE_DIRS}
+)
+
+set_source_files_properties (mraa.i PROPERTIES CPLUSPLUS ON)
+set_source_files_properties (mraa.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
+swig_add_module (python-mraa python mraa.i ${mraa_LIB_SRCS})
+swig_link_libraries (python-mraa ${PYTHON_LIBRARIES} ${mraa_LIBS})
+
+if (DOXYGEN_FOUND)
+ foreach (_file ${DOCCLASSES})
+ add_dependencies (${SWIG_MODULE_python-mraa_REAL_NAME} ${_file}class_doc_i)
+ endforeach ()
+ add_dependencies (${SWIG_MODULE_python-mraa_REAL_NAME} common_hpp_doc_i)
+
+ add_custom_target (pydoc
+ pydoc -w ${CMAKE_CURRENT_BINARY_DIR}/mraa.py ${CMAKE_CURRENT_BINARY_DIR}/
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ COMMENT "Generating API documentation with pydoc" VERBATIM
+ )
+endif ()
+
+set_target_properties (${SWIG_MODULE_python-mraa_REAL_NAME} PROPERTIES
+ OUTPUT_NAME _mraa
+ COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
+)
+
+execute_process (
+ COMMAND ${PYTHON_EXECUTABLE} -c
+ "import site, sys; sys.stdout.write(site.PREFIXES[-1])"
+ OUTPUT_VARIABLE PYTHON_PREFIX
+)
+file (TO_CMAKE_PATH "${PYTHON_PREFIX}" PYTHON_PREFIX)
+execute_process (
+ COMMAND ${PYTHON_EXECUTABLE} -c
+ "import site, sys; sys.stdout.write(site.getusersitepackages().replace(site.getuserbase(), site.PREFIXES[-1]))"
+ OUTPUT_VARIABLE PYTHON_SITE_DIR
+)
+file (TO_CMAKE_PATH "${PYTHON_SITE_DIR}" PYTHON_SITE_DIR)
+string (REGEX REPLACE "^${PYTHON_PREFIX}/" ""
+ PYTHON_SITE_DIR "${PYTHON_SITE_DIR}")
+
+install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa.so
+ ${CMAKE_CURRENT_BINARY_DIR}/mraa.py
+ DESTINATION ${PYTHON_SITE_DIR})
+
+add_subdirectory (docs)
diff --git a/peripheral/libmraa/src/python/python2/docs/CMakeLists.txt b/peripheral/libmraa/src/python/docs/CMakeLists.txt
index c2a7c98..9ce7880 100644
--- a/peripheral/libmraa/src/python/python2/docs/CMakeLists.txt
+++ b/peripheral/libmraa/src/python/docs/CMakeLists.txt
@@ -36,6 +36,6 @@ if (DOXYGEN_FOUND)
COMMENT "Building HTML documentation with Sphinx"
)
- add_dependencies (sphinx ${SWIG_MODULE_python2-mraa_REAL_NAME})
+ add_dependencies (sphinx ${SWIG_MODULE_python-mraa_REAL_NAME})
endif ()
endif ()
diff --git a/peripheral/libmraa/src/python/python2/docs/conf.py.in b/peripheral/libmraa/src/python/docs/conf.py.in
index fa662ff..344abe1 100644
--- a/peripheral/libmraa/src/python/python2/docs/conf.py.in
+++ b/peripheral/libmraa/src/python/docs/conf.py.in
@@ -19,7 +19,7 @@ import os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
-sys.path.insert(0, "@CMAKE_BINARY_DIR@/src/python/python2")
+sys.path.insert(0, "@CMAKE_BINARY_DIR@/src/python")
# -- General configuration ------------------------------------------------
diff --git a/peripheral/libmraa/src/python/python2/docs/example.rst b/peripheral/libmraa/src/python/docs/example.rst
index ab11be5..4daf98c 100644
--- a/peripheral/libmraa/src/python/python2/docs/example.rst
+++ b/peripheral/libmraa/src/python/docs/example.rst
@@ -16,13 +16,13 @@ Here is the simplest Gpio program in mraa.
:prepend: import mraa
:start-after: import mraa
-GPIO Interrupt (isr)
+GPIO Interupt (isr)
===================
-The GPIO module allows you to set an interrupt on a GPIO. This interrupt is
+The GPIO module allows you to set an interupt on a GPIO. This interupt is
controlled by the mode that the 'edge' is in. Before setting another isr please
remove the first one, multiple isrs on one pin are not supported. Some
-platforms will not support interrupts on all pins so please check your return
+platforms will not support interupts on all pins so please check your return
values.
**Note:** Galileo Gen1 only supports EDGE_BOTH
diff --git a/peripheral/libmraa/src/python/python2/docs/index.rst b/peripheral/libmraa/src/python/docs/index.rst
index cbdbab0..cbdbab0 100644
--- a/peripheral/libmraa/src/python/python2/docs/index.rst
+++ b/peripheral/libmraa/src/python/docs/index.rst
diff --git a/peripheral/libmraa/src/python/python2/docs/mraa.rst b/peripheral/libmraa/src/python/docs/mraa.rst
index 04e7c1e..04e7c1e 100644
--- a/peripheral/libmraa/src/python/python2/docs/mraa.rst
+++ b/peripheral/libmraa/src/python/docs/mraa.rst
diff --git a/peripheral/libmraa/src/python/mraapython.i b/peripheral/libmraa/src/python/mraa.i
index 521ef53..64d086e 100644
--- a/peripheral/libmraa/src/python/mraapython.i
+++ b/peripheral/libmraa/src/python/mraa.i
@@ -1,3 +1,7 @@
+%module(docstring="Python interface to libmraa") mraa
+
+%feature("autodoc", "3");
+
%include typemaps.i
%include carrays.i
@@ -145,19 +149,6 @@ class Spi;
%include ../mraa.i
%init %{
- #include "python/mraapy.h"
- #include "mraa_lang_func.h"
- extern mraa_lang_func_t* lang_func;
- // Initialise python threads, this allows use to grab the GIL when we are
- // required to do so
- Py_InitializeEx(0);
- PyEval_InitThreads();
- // Add mraa_init() to the module initialisation process and set isr function
- mraa_result_t res = mraa_init();
- if (res == MRAA_SUCCESS) {
- lang_func->python_isr = &mraa_python_isr;
- }
- else
- SWIG_Error(SWIG_RuntimeError, "mraa_init() failed");
-
+ //Adding mraa_init() to the module initialisation process
+ mraa_init();
%}
diff --git a/peripheral/libmraa/src/python/mraapy.c b/peripheral/libmraa/src/python/mraapy.c
deleted file mode 100644
index 84b8c36..0000000
--- a/peripheral/libmraa/src/python/mraapy.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Author: Henry Bruce <henry.bruce@intel.com>
- * Copyright (c) 2016 Intel Corporation.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include <syslog.h>
-#include <Python.h>
-#include "python/mraapy.h"
-
-
-// In order to call a python object (all python functions are objects) we
-// need to aquire the GIL (Global Interpreter Lock). This may not always be
-// necessary but especially if doing IO (like print()) python will segfault
-// if we do not hold a lock on the GIL
-void
-mraa_python_isr(void (*isr)(void*), void* isr_args)
-{
-
- PyGILState_STATE gilstate = PyGILState_Ensure();
- PyObject* arglist;
- PyObject* ret;
- arglist = Py_BuildValue("(O)", isr_args);
- if (arglist == NULL) {
- syslog(LOG_ERR, "gpio: Py_BuildValue NULL");
- } else {
- ret = PyEval_CallObject((PyObject*) isr, arglist);
- if (ret == NULL) {
- syslog(LOG_ERR, "gpio: PyEval_CallObject failed");
- PyObject *pvalue, *ptype, *ptraceback;
- PyObject *pvalue_pystr, *ptype_pystr, *ptraceback_pystr;
- char *pvalue_cstr, *ptype_cstr, *ptraceback_cstr;
- PyErr_Fetch(&pvalue, &ptype, &ptraceback);
- pvalue_pystr = PyObject_Str(pvalue);
- ptype_pystr = PyObject_Str(ptype);
- ptraceback_pystr = PyObject_Str(ptraceback);
-// Python2
-#if PY_VERSION_HEX < 0x03000000
- pvalue_cstr = PyString_AsString(pvalue_pystr);
- ptype_cstr = PyString_AsString(ptype_pystr);
- ptraceback_cstr = PyString_AsString(ptraceback_pystr);
-// Python 3 and up
-#elif PY_VERSION_HEX >= 0x03000000
- // In Python 3 we need one extra conversion
- PyObject *pvalue_ustr, *ptype_ustr, *ptraceback_ustr;
- pvalue_ustr = PyUnicode_AsUTF8String(pvalue_pystr);
- pvalue_cstr = PyBytes_AsString(pvalue_ustr);
- ptype_ustr = PyUnicode_AsUTF8String(ptype_pystr);
- ptype_cstr = PyBytes_AsString(ptype_ustr);
- ptraceback_ustr = PyUnicode_AsUTF8String(ptraceback_pystr);
- ptraceback_cstr = PyBytes_AsString(ptraceback_ustr);
-#endif // PY_VERSION_HEX
- syslog(LOG_ERR, "gpio: the error was %s:%s:%s", pvalue_cstr, ptype_cstr, ptraceback_cstr);
- Py_XDECREF(pvalue);
- Py_XDECREF(ptype);
- Py_XDECREF(ptraceback);
- Py_XDECREF(pvalue_pystr);
- Py_XDECREF(ptype_pystr);
- Py_XDECREF(ptraceback_pystr);
-// Python 3 and up
-#if PY_VERSION_HEX >= 0x03000000
- Py_XDECREF(pvalue_ustr);
- Py_XDECREF(ptype_ustr);
- Py_XDECREF(ptraceback_ustr);
-#endif // PY_VERSION_HEX
- } else {
- Py_DECREF(ret);
- }
- Py_DECREF(arglist);
- }
-
- PyGILState_Release(gilstate);
-}
diff --git a/peripheral/libmraa/src/python/python2/CMakeLists.txt b/peripheral/libmraa/src/python/python2/CMakeLists.txt
deleted file mode 100644
index 10d23c2..0000000
--- a/peripheral/libmraa/src/python/python2/CMakeLists.txt
+++ /dev/null
@@ -1,39 +0,0 @@
-set_source_files_properties (mraa2.i PROPERTIES CPLUSPLUS ON)
-set_source_files_properties (mraa2.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
-
-if (PYTHON2_LIBRARY)
- message ("PYTHON2 attempting to build!")
-
- swig_add_module (python2-mraa python mraa2.i ../mraapy.c)
- swig_link_libraries (python2-mraa ${PYTHON2_LIBRARIES} mraa)
-
- target_include_directories(${SWIG_MODULE_python2-mraa_REAL_NAME}
- PUBLIC
- "${CMAKE_CURRENT_SOURCE_DIR}/../.."
- "${PYTHON2_INCLUDE_DIR}"
- )
-
- if (DOXYGEN_FOUND AND PYTHON2_EXECUTABLE)
- foreach (_file ${DOCCLASSES})
- add_dependencies (${SWIG_MODULE_python2-mraa_REAL_NAME} ${_file}class_doc_i)
- endforeach ()
- add_dependencies (${SWIG_MODULE_python2-mraa_REAL_NAME} common_hpp_doc_i)
-
- add_custom_target (pydoc
- pydoc -w ${CMAKE_CURRENT_BINARY_DIR}/mraa.py ${CMAKE_CURRENT_BINARY_DIR}/
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- COMMENT "Generating API documentation with pydoc" VERBATIM
- )
- endif ()
-
- set_target_properties (${SWIG_MODULE_python2-mraa_REAL_NAME} PROPERTIES
- OUTPUT_NAME _mraa
- COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
- )
-
- install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa.so
- ${CMAKE_CURRENT_BINARY_DIR}/mraa.py
- DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON2_PACKAGES_PATH})
-endif()
-
-add_subdirectory (docs)
diff --git a/peripheral/libmraa/src/python/python2/mraa2.i b/peripheral/libmraa/src/python/python2/mraa2.i
deleted file mode 100644
index 81f9158..0000000
--- a/peripheral/libmraa/src/python/python2/mraa2.i
+++ /dev/null
@@ -1,5 +0,0 @@
-%module(docstring="Python interface to libmraa") mraa
-
-%feature("autodoc", "3");
-
-%include ../mraapython.i
diff --git a/peripheral/libmraa/src/python/python3/CMakeLists.txt b/peripheral/libmraa/src/python/python3/CMakeLists.txt
deleted file mode 100644
index 5fb8822..0000000
--- a/peripheral/libmraa/src/python/python3/CMakeLists.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-set_source_files_properties (mraa3.i PROPERTIES CPLUSPLUS ON)
-set_source_files_properties (mraa3.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
-
-if (PYTHON3_LIBRARY)
- message ("PYTHON3 attempting to build!")
-
- swig_add_module (python3-mraa python mraa3.i ../mraapy.c)
- swig_link_libraries (python3-mraa ${PYTHON3_LIBRARIES} mraa)
-
- target_include_directories(${SWIG_MODULE_python3-mraa_REAL_NAME}
- PUBLIC
- "${CMAKE_CURRENT_SOURCE_DIR}/../.."
- "${PYTHON3_INCLUDE_DIR}"
- )
-
- set_target_properties (${SWIG_MODULE_python3-mraa_REAL_NAME} PROPERTIES
- OUTPUT_NAME _mraa
- COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
- )
-
- install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa.so
- ${CMAKE_CURRENT_BINARY_DIR}/mraa.py
- DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON3_PACKAGES_PATH})
-endif ()
diff --git a/peripheral/libmraa/src/python/python3/mraa3.i b/peripheral/libmraa/src/python/python3/mraa3.i
deleted file mode 100644
index e3df17a..0000000
--- a/peripheral/libmraa/src/python/python3/mraa3.i
+++ /dev/null
@@ -1,3 +0,0 @@
-%module(docstring="Python interface to libmraa") mraa
-
-%include ../mraapython.i