From 1a66c6dc6a61b8eeeb995bb12a1d70b652839bb9 Mon Sep 17 00:00:00 2001 From: Mihai Tudor Panu Date: Thu, 24 Sep 2020 19:03:27 -0700 Subject: [PATCH] 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 --- .travis.yml | 12 ++---- cmake/modules/OpenCVDetectPython.cmake | 8 ++-- docker-compose.yaml | 7 +--- scripts/build-doc.sh | 2 +- src/python/CMakeLists.txt | 3 -- src/python/mraapy.c | 16 +------- src/python/python2/CMakeLists.txt | 39 ------------------- src/python/python2/mraa2.i | 15 ------- src/python/python3/CMakeLists.txt | 9 +++++ .../{python2 => python3}/docs/CMakeLists.txt | 2 +- .../{python2 => python3}/docs/conf.py.in | 2 +- .../{python2 => python3}/docs/example.rst | 0 .../{python2 => python3}/docs/index.rst | 0 src/python/{python2 => python3}/docs/mraa.rst | 0 14 files changed, 22 insertions(+), 93 deletions(-) delete mode 100644 src/python/python2/CMakeLists.txt delete mode 100644 src/python/python2/mraa2.i rename src/python/{python2 => python3}/docs/CMakeLists.txt (95%) rename src/python/{python2 => python3}/docs/conf.py.in (99%) rename src/python/{python2 => python3}/docs/example.rst (100%) rename src/python/{python2 => python3}/docs/index.rst (100%) rename src/python/{python2 => python3}/docs/mraa.rst (100%) diff --git a/.travis.yml b/.travis.yml index 0f6bae5..d4b4dde 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/cmake/modules/OpenCVDetectPython.cmake b/cmake/modules/OpenCVDetectPython.cmake index 5565035..c0441c4 100644 --- a/cmake/modules/OpenCVDetectPython.cmake +++ b/cmake/modules/OpenCVDetectPython.cmake @@ -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() diff --git a/docker-compose.yaml b/docker-compose.yaml index 7e53e96..0f1e21e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -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" diff --git a/scripts/build-doc.sh b/scripts/build-doc.sh index 47a4e70..198e307 100755 --- a/scripts/build-doc.sh +++ b/scripts/build-doc.sh @@ -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 diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index e4ed3ef..4b06214 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -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 () diff --git a/src/python/mraapy.c b/src/python/mraapy.c index 8fe32e9..a3536f0 100644 --- a/src/python/mraapy.c +++ b/src/python/mraapy.c @@ -1,6 +1,6 @@ /* * Author: Henry Bruce - * 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); } diff --git a/src/python/python2/CMakeLists.txt b/src/python/python2/CMakeLists.txt deleted file mode 100644 index 41d18b2..0000000 --- a/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") - -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) diff --git a/src/python/python2/mraa2.i b/src/python/python2/mraa2.i deleted file mode 100644 index 814ba59..0000000 --- a/src/python/python2/mraa2.i +++ /dev/null @@ -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 diff --git a/src/python/python3/CMakeLists.txt b/src/python/python3/CMakeLists.txt index 5b69bb2..03894cf 100644 --- a/src/python/python3/CMakeLists.txt +++ b/src/python/python3/CMakeLists.txt @@ -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) diff --git a/src/python/python2/docs/CMakeLists.txt b/src/python/python3/docs/CMakeLists.txt similarity index 95% rename from src/python/python2/docs/CMakeLists.txt rename to src/python/python3/docs/CMakeLists.txt index 3dab7b8..4351aad 100644 --- a/src/python/python2/docs/CMakeLists.txt +++ b/src/python/python3/docs/CMakeLists.txt @@ -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") diff --git a/src/python/python2/docs/conf.py.in b/src/python/python3/docs/conf.py.in similarity index 99% rename from src/python/python2/docs/conf.py.in rename to src/python/python3/docs/conf.py.in index f1b86c4..2eab323 100644 --- a/src/python/python2/docs/conf.py.in +++ b/src/python/python3/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/python3") # -- General configuration ------------------------------------------------ diff --git a/src/python/python2/docs/example.rst b/src/python/python3/docs/example.rst similarity index 100% rename from src/python/python2/docs/example.rst rename to src/python/python3/docs/example.rst diff --git a/src/python/python2/docs/index.rst b/src/python/python3/docs/index.rst similarity index 100% rename from src/python/python2/docs/index.rst rename to src/python/python3/docs/index.rst diff --git a/src/python/python2/docs/mraa.rst b/src/python/python3/docs/mraa.rst similarity index 100% rename from src/python/python2/docs/mraa.rst rename to src/python/python3/docs/mraa.rst