python2: remove ability to build python2 bindings from project

This removes Python 2 package generation from the project to encourage safer development with Python 3 instead. Documentation for the generated modules switched to Python 3. Default interpreter is now Python 3 but can be overridden if needed for running the tests only on older environments.

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Mihai Tudor Panu
2020-09-24 19:03:27 -07:00
committed by Propanu
parent 36696db591
commit 1a66c6dc6a
14 changed files with 22 additions and 93 deletions

View File

@@ -24,15 +24,13 @@ jobs:
- BUILDARCH=MOCK docker-compose run ${TARGET}
- &run-with-clang
stage: Clang 3.8
env: TARGET=python2
env: TARGET=python3
before_script: docker-compose pull ${TARGET}
script:
- export CC=clang-3.8 CXX=clang++-3.8
- docker-compose run ${TARGET}
- BUILDARCH=MOCK docker-compose run ${TARGET}
- if [[ ${TARGET} != *"node"* ]]; then JSONPLAT=ON docker-compose run ${TARGET}; fi
- <<: *run-with-clang
env: TARGET=python3
- <<: *run-with-clang
env: TARGET=node4
- <<: *run-with-clang
@@ -43,15 +41,13 @@ jobs:
env: TARGET=java
- &run-with-gcc-5
stage: Gcc 5
env: TARGET=python2
env: TARGET=python3
before_script: docker-compose pull ${TARGET}
script:
- export CC=gcc-5 CXX=g++-5
- docker-compose run ${TARGET}
- BUILDARCH=MOCK docker-compose run ${TARGET}
- if [[ ${TARGET} != *"node"* ]]; then JSONPLAT=ON docker-compose run ${TARGET}; fi
- <<: *run-with-gcc-5
env: TARGET=python3
- <<: *run-with-gcc-5
env: TARGET=node4
- <<: *run-with-gcc-5
@@ -62,15 +58,13 @@ jobs:
env: TARGET=java
- &run-with-gcc-6
stage: Gcc 6
env: TARGET=python2
env: TARGET=python3
before_script: docker-compose pull ${TARGET}
script:
- export CC=gcc-6 CXX=g++-6
- docker-compose run ${TARGET}
- BUILDARCH=MOCK docker-compose run ${TARGET}
- if [[ ${TARGET} != *"node"* ]]; then JSONPLAT=ON docker-compose run ${TARGET}; fi
- <<: *run-with-gcc-6
env: TARGET=python3
- <<: *run-with-gcc-6
env: TARGET=node4
- <<: *run-with-gcc-6

View File

@@ -154,10 +154,10 @@ find_python(3 "${MIN_VER_PYTHON3}" PYTHON3_LIBRARY PYTHON3_INCLUDE_DIR
if(PYTHON_DEFAULT_EXECUTABLE)
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
elseif(PYTHON2INTERP_FOUND) # Use Python 2 as default Python interpreter
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON2_EXECUTABLE}")
elseif(PYTHON3INTERP_FOUND) # Use Python 2 as fallback Python interpreter (if there is no Python 2)
elseif(PYTHON3INTERP_FOUND) # Use Python 3 as default Python interpreter
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON3_EXECUTABLE}")
elseif(PYTHON2INTERP_FOUND) # Use Python 2 as fallback Python interpreter (if there is no Python 3)
set(PYTHON_DEFAULT_AVAILABLE "TRUE")
set(PYTHON_DEFAULT_EXECUTABLE "${PYTHON2_EXECUTABLE}")
endif()

View File

@@ -112,17 +112,12 @@ services:
- FTDI4222=ON
command: bash -c "./scripts/run-cmake.sh && make -Cbuild"
python2:
python3:
extends: base
image: inteliotdevkit/mraa-python
environment:
- BUILDSWIG=ON
- BUILDSWIGPYTHON=ON
command: bash -c "./scripts/run-cmake.sh && cd build && make _python2-mraa test_unit_all && ctest --output-on-failure"
python3:
extends: python2
environment:
- USEPYTHON3TESTS=ON
command: bash -c "./scripts/run-cmake.sh && cd build && make _python3-mraa test_unit_all && ctest --output-on-failure"

View File

@@ -28,6 +28,6 @@ cd build/src/java && echo ../../../src/mraa.i > mraa.i.list && \
doxygen Doxyfile && cd ../../../
# Copy output to build/html/ directory
cp -r build/src/python/python2/docs/html build/html/python && \
cp -r build/src/python/python3/docs/html build/html/python && \
cp -r build/src/java/html build/html/java && \
cp build/jsdoc/ternjs/mraa/doc.js build/html/node/mraa_tern.js

View File

@@ -1,9 +1,6 @@
set_source_files_properties (mraapython.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (mraapython.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
if (PYTHON2_LIBRARY)
add_subdirectory (python2)
endif ()
if (PYTHON3_LIBRARY)
add_subdirectory (python3)
endif ()

View File

@@ -1,6 +1,6 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2016 Intel Corporation.
* Copyright (c) 2016-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*/
@@ -30,27 +30,18 @@ mraa_python_isr(void (*isr)(void*), void* isr_args)
syslog(LOG_ERR, "gpio: PyEval_CallObject failed");
PyObject *pvalue, *ptype, *ptraceback;
PyObject *pvalue_pystr, *ptype_pystr, *ptraceback_pystr;
PyObject *pvalue_ustr, *ptype_ustr, *ptraceback_ustr;
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);
@@ -58,12 +49,9 @@ mraa_python_isr(void (*isr)(void*), void* isr_args)
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);
}

View File

@@ -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")
message (STATUS "PYTHON2 attempting to build!")
if (CMAKE_VERSION VERSION_LESS "3.8")
swig_add_module (python2-mraa python mraa2.i ../mraapy.c)
else ()
swig_add_library (python2-mraa LANGUAGE python SOURCES mraa2.i ../mraapy.c)
endif ()
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)
endif ()
set_target_properties (${SWIG_MODULE_python2-mraa_REAL_NAME} PROPERTIES
OUTPUT_NAME _mraa
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND} -DSWIGPYTHON2=${SWIG_FOUND}"
)
install (TARGETS ${SWIG_MODULE_python2-mraa_REAL_NAME}
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON2_PACKAGES_PATH}
)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON2_PACKAGES_PATH}
)
add_subdirectory (docs)

View File

@@ -1,15 +0,0 @@
%module(docstring="Python interface to libmraa") mraa
%feature("autodoc", "3");
#ifdef DOXYGEN
%include common_hpp_doc.i
%include gpio_class_doc.i
%include i2c_class_doc.i
%include pwm_class_doc.i
%include aio_class_doc.i
%include spi_class_doc.i
%include uart_class_doc.i
#endif
%include ../mraapython.i

View File

@@ -16,6 +16,13 @@ target_include_directories(${SWIG_MODULE_python3-mraa_REAL_NAME}
"${PYTHON3_INCLUDE_DIR}"
)
if (DOXYGEN_FOUND AND PYTHON3_EXECUTABLE)
foreach (_file ${DOCCLASSES})
add_dependencies (${SWIG_MODULE_python3-mraa_REAL_NAME} ${_file}class_doc_i)
endforeach ()
add_dependencies (${SWIG_MODULE_python3-mraa_REAL_NAME} common_hpp_doc_i)
endif ()
set_target_properties (${SWIG_MODULE_python3-mraa_REAL_NAME} PROPERTIES
OUTPUT_NAME _mraa
COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND} -DSWIGPYTHON3=${SWIG_FOUND}"
@@ -28,3 +35,5 @@ install (TARGETS ${SWIG_MODULE_python3-mraa_REAL_NAME}
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYTHON3_PACKAGES_PATH}
)
add_subdirectory (docs)

View File

@@ -36,7 +36,7 @@ if (DOXYGEN_FOUND)
COMMENT "Building HTML documentation with Sphinx"
)
add_dependencies (sphinx ${SWIG_MODULE_python2-mraa_REAL_NAME})
add_dependencies (sphinx ${SWIG_MODULE_python3-mraa_REAL_NAME})
else ()
message (SEND_ERROR "ERROR - Failed to find a compatible version of Sphinx. Python API doc will not be generated")
endif (SPHINX_FOUND AND SPHINX_VERSION VERSION_GREATER "1.3")

View File

@@ -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/python3")
# -- General configuration ------------------------------------------------