diff --git a/CMake/CTestCustom.cmake.in b/CMake/CTestCustom.cmake.in index e54174b5e82a0fe2ef3bfc133a7091c15242ddc2..8e1019b558c708d4baf945c3b3ad10ebd71092ea 100644 --- a/CMake/CTestCustom.cmake.in +++ b/CMake/CTestCustom.cmake.in @@ -63,7 +63,6 @@ set(CTEST_CUSTOM_COVERAGE_EXCLUDE # Exclude SWIG wrappers files ".*/Modules/Wrappers/SWIG/src/python/otbApplicationPYTHON_wrap.*" - ".*/Modules/Wrappers/SWIG/src/python3/otbApplicationPYTHON_wrap.*" ".*/Modules/Wrappers/SWIG/src/java/otbApplicationJAVA_wrap.*" # Exclude Qt moc file diff --git a/CMake/OTBModuleDoxygen.cmake b/CMake/OTBModuleDoxygen.cmake index e4b918a8901af8aaffb56270c8741ea898dab343..826c54d192fe74e94c6817cf440ef54313825de2 100644 --- a/CMake/OTBModuleDoxygen.cmake +++ b/CMake/OTBModuleDoxygen.cmake @@ -26,7 +26,6 @@ # python is needed to verify the presence of the module name in the doxygen header # Don't require it to not force the developers to install python to be able to build # OTB. The tests will simply not be run if python is not available. -find_package(PythonInterp) macro( otb_module_doxygen _name ) diff --git a/CMake/OTBModuleHeaderTest.cmake b/CMake/OTBModuleHeaderTest.cmake index 2191be7c721734b249aa6d87796bdeeb7c333867..20b43b76d4a276af341b20b5160c03ae71313a3f 100644 --- a/CMake/OTBModuleHeaderTest.cmake +++ b/CMake/OTBModuleHeaderTest.cmake @@ -26,7 +26,6 @@ # This does not force the developer to install python to be able to build OTB. # The tests will simply not be run if python is unavailable. -find_package(PythonInterp) # The maximum number of headers in a test. This helps limit memory issues, # and the cppcheck tests. However, if this is not unity, there is a slight diff --git a/CMakeLists.txt b/CMakeLists.txt index 10a0b012afc5a8dff90bb3591500d4fc7ca64a45..7014752fc25d1c5dcc486d5b774694fc54c6d738 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,19 @@ reset_qt_i18n_sources() repository_status(${PROJECT_SOURCE_DIR} OTB_GIT_STATUS_MESSAGE) +# Find python stuff +# Version 3 is prefered before 2 +set ( Python_ADDITIONAL_VERSIONS "3;2" ) +set ( PythonInterp_FIND_REQUIRED ${OTB_WRAP_PYTHON} ) +set ( PythonLibs_FIND_REQUIRED ${OTB_WRAP_PYTHON} ) +find_package( PythonInterp ) +if ( OTB_WRAP_PYTHON AND ( ${PYTHON_VERSION_MAJOR} EQUAL 2 ) ) + message (WARNING "Python3 not found. There is no longer support of \ + wrapping in python2 in OTB, but it can still be used.") +endif() +set (Python_ADDITIONAL_VERSIONS "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}") +find_package ( PythonLibs ) + #----------------------------------------------------------------------------- # Configure the default OTB_DATA_ROOT for the location of OTB Data. find_path(OTB_DATA_ROOT @@ -152,9 +165,6 @@ endif() if(NOT OTB_INSTALL_PYTHON_DIR) set(OTB_INSTALL_PYTHON_DIR "${OTB_INSTALL_LIBRARY_DIR}/otb/python") endif() -if(NOT OTB_INSTALL_PYTHON3_DIR) - set(OTB_INSTALL_PYTHON3_DIR "${OTB_INSTALL_LIBRARY_DIR}/otb/python3") -endif() if(NOT OTB_INSTALL_JAVA_DIR) set(OTB_INSTALL_JAVA_DIR "${OTB_INSTALL_LIBRARY_DIR}/otb/java") endif() @@ -339,6 +349,7 @@ set(OTB_CONFIG_CODE " set(OTB_MODULES_DIR \"${OTB_MODULES_DIR}\")") set(OTB_CONFIG_CMAKE_DIR "${OTB_SOURCE_DIR}/CMake") set(OTB_USE_FILE "${OTB_CONFIG_CMAKE_DIR}/UseOTB.cmake") + if(OTB_WRAP_PYTHON) set(OTB_CONFIG_CODE "${OTB_CONFIG_CODE} set(OTB_PYTHONPATH \"${OTB_BINARY_DIR}/${OTB_INSTALL_PYTHON_DIR}\")") @@ -366,10 +377,12 @@ set(OTB_CONFIG_CODE "${OTB_CONFIG_CODE} set(OTB_MODULES_DIR \"\${OTB_INSTALL_PREFIX}/${OTB_INSTALL_PACKAGE_DIR}/Modules\")") set(OTB_USE_FILE "\${OTB_INSTALL_PREFIX}/${OTB_INSTALL_PACKAGE_DIR}/UseOTB.cmake") set(OTB_CONFIG_CMAKE_DIR "\${OTB_INSTALL_PREFIX}/${OTB_INSTALL_PACKAGE_DIR}") + if(OTB_WRAP_PYTHON) set(OTB_CONFIG_CODE "${OTB_CONFIG_CODE} set(OTB_PYTHONPATH \"\${OTB_INSTALL_PREFIX}/${OTB_INSTALL_PYTHON_DIR}\")") endif() + set(OTB_CONFIG_APPLICATION_PATH "\${OTB_INSTALL_PREFIX}/${OTB_INSTALL_APP_DIR}") set(OTB_CONFIG_TARGETS_CONDITION "") set(OTB_CONFIG_TARGETS_FILE "\${OTB_INSTALL_PREFIX}/${OTB_INSTALL_PACKAGE_DIR}/OTBTargets.cmake") diff --git a/Documentation/Cookbook/CMakeLists.txt b/Documentation/Cookbook/CMakeLists.txt index a690ee397ec2aac38bb6b2b10b57f5a3f5e21ed4..cee9b6269ceeae37f27a13504916ff8b6e3d4101 100644 --- a/Documentation/Cookbook/CMakeLists.txt +++ b/Documentation/Cookbook/CMakeLists.txt @@ -66,9 +66,9 @@ foreach(cmd endforeach() # We need to set PYTHONPATH for the script otbGenerateWrappersRstDoc.py, depending on how the Python3 module was built -if (OTB_WRAP_PYTHON3) - set(PYTHONPATH_COOKBOOK "${CMAKE_BINARY_DIR}/lib/otb/python3") -elseif (OTB_WRAP_PYTHON) +if (OTB_WRAP_PYTHON) + set(PYTHONPATH_COOKBOOK "${CMAKE_BINARY_DIR}/lib/otb/python") +else() # Cookbook only supports Python3 # But OTB_WRAP_PYTHON can wrap both python2 and python3 if (${PYTHONLIBS_VERSION_STRING} STRGREATER "3.0.0") diff --git a/Documentation/Cookbook/rst/Installation_Linux.rst b/Documentation/Cookbook/rst/Installation_Linux.rst index b4e8ec3c63d23e0337dd1a4b50176893112cebfb..c1afb31371941985cc1e90283c48eb011fe08e68 100644 --- a/Documentation/Cookbook/rst/Installation_Linux.rst +++ b/Documentation/Cookbook/rst/Installation_Linux.rst @@ -84,23 +84,20 @@ necessary to install one of the following packages: Python bindings ~~~~~~~~~~~~~~~ -Starting from OTB 5.8.0, OTB bindings for Python 2.7 are distributed as a binary -package. With OTB 6.4.0, additional bindings for Python 3.5 are also included. +Since OTB 6.7.0 OTB bindings for Python 3.5 are distributed as a binary +package. Please note that using a different Python version may not be compatible with -OTB wrappings. If no compatible Python 2.x version is found a -notification is generated during the installation process. If the installation completes +OTB wrappings. If the installation completes without issue, information relating to your Python bindings will be provided. You must have Python NumPy bindings installed in your system. They can be installed locally without admin rights as follows: "pip install --user numpy". This is to give users the option -to select their own existing Python installation rather than the one distributed by the OTB package. +to select their own existing Python installation rather than the one dibstributed by the OTB package. -By default, bindings for Python 2.7 will be enabled with the ``otbenv`` script. -If you want to use bindings for Python 3.5, you can copy this script and modify: - -- ``lib/python`` into ``lib/python3``, for variable PYTHONPATH +By default, bindings for Python 3.5 will be enabled with the ``otbenv`` script. Notes: +~~~~~~ - You must use monteverdi and mapla through ``mapla.sh`` and ``monteverdi.sh`` helper scripts in extracted directory. diff --git a/Documentation/Cookbook/rst/Installation_Macos.rst b/Documentation/Cookbook/rst/Installation_Macos.rst index d9273b72b6609bc334939db567cecf1c888931ba..d0d4480e6a90fa3868e4a64806469ea66fa8be5e 100644 --- a/Documentation/Cookbook/rst/Installation_Macos.rst +++ b/Documentation/Cookbook/rst/Installation_Macos.rst @@ -44,23 +44,20 @@ supplied script ``tools/uninstall_otb.sh``. Python bindings ~~~~~~~~~~~~~~~ -Starting from OTB 5.8.0, OTB bindings for Python 2.7 are distributed as a binary -package. With OTB 6.4.0, additional bindings for Python 3.5 are also included. +Since OTB 6.7.0 OTB bindings for Python 3.5 are distributed as a binary +package. Please note that using a different Python version may not be compatible with -OTB wrappings. If no compatible Python 2.x version is found a -notification is generated during the installation process. If the installation completes +OTB wrappings. If the installation completes without issue, information relating to your Python bindings will be provided. You must have Python numpy bindings installed in your system. They can be installed locally without admin rights as follows: "pip install --user numpy". This is to give users the option to select their own existing Python installation rather than the one dibstributed by the OTB package. -By default, bindings for Python 2.7 will be enabled with the ``otbenv`` script. -If you want to use bindings for Python 3.5, you can copy this script and modify: - -- ``lib/python`` into ``lib/python3``, for variable PYTHONPATH +By default, bindings for Python 3.5 will be enabled with the ``otbenv`` script. Notes: +~~~~~~ - If you want to use the otbcli and otbgui launchers, you must access them via a terminal prompt. diff --git a/Documentation/Cookbook/rst/Installation_Windows.rst b/Documentation/Cookbook/rst/Installation_Windows.rst index bd8a8af23d0c75e9cfa1b408f9641755f7b39cef..2384005ccf4b190c9d326a6e90206c708e19b9cb 100644 --- a/Documentation/Cookbook/rst/Installation_Windows.rst +++ b/Documentation/Cookbook/rst/Installation_Windows.rst @@ -43,24 +43,20 @@ start Visual Studio. Python bindings ~~~~~~~~~~~~~~~ -Starting from OTB 5.8.0, OTB bindings for Python 2.7 are distributed as a binary -package. With OTB 6.4.0, additional bindings for Python 3.5 are also included. +Since OTB 6.7.0 OTB bindings for Python 3.5 are distributed as a binary +package. Please note that using a different Python version may not be compatible with -OTB wrappings. If no compatible Python 2.x version is found a -notification is generated during the installation process. If the installation completes +OTB wrappings. If the installation completes without issue, information relating to your Python bindings will be provided. You must have Python numpy bindings installed in your system. They can be installed locally without admin rights as follows: "pip install --user numpy". This is to give users the option to select their own existing Python installation rather than the one dibstributed by the OTB package. -By default, bindings for Python 2.7 will be enabled with the ``otbenv`` script. -If you want to use bindings for Python 3.5, you can copy this script and modify: +By default, bindings for Python 3.5 will be enabled with the ``otbenv`` script. -- ``lib/python`` into ``lib/python3``, for variable PYTHONPATH - -Notes -~~~~~ +Notes: +~~~~~~ - You must have "Visual C++ Redistributable for Visual Studio 2015" installed for using this package. It can be downloaded freely from `microsoft <https://www.microsoft.com/en-us/download/details.aspx?id=48145>`_ diff --git a/Modules/Wrappers/SWIG/otb-module-init.cmake b/Modules/Wrappers/SWIG/otb-module-init.cmake index 42c3f700c726d6da91f373d2155aa8e3dbe5c1a0..496497bd52198a20e428cb635caeb515aaed8b9b 100644 --- a/Modules/Wrappers/SWIG/otb-module-init.cmake +++ b/Modules/Wrappers/SWIG/otb-module-init.cmake @@ -19,10 +19,9 @@ # option ( OTB_WRAP_PYTHON "Wrap Python" OFF ) -option ( OTB_WRAP_PYTHON3 "Wrap Python 3" OFF ) option ( OTB_WRAP_JAVA "Wrap Java" OFF ) -if ( OTB_WRAP_PYTHON OR OTB_WRAP_JAVA OR OTB_WRAP_PYTHON3) +if ( OTB_WRAP_PYTHON OR OTB_WRAP_JAVA ) find_package ( SWIG REQUIRED ) mark_as_advanced(SWIG_DIR) mark_as_advanced(SWIG_EXECUTABLE) @@ -40,72 +39,18 @@ macro(check_PIC_flag Language) endif() endif() endmacro() +# this macro should be removed - +# +# Python SWIG configuration +# if ( OTB_WRAP_PYTHON ) check_PIC_flag ( Python ) - find_package ( PythonInterp REQUIRED ) - find_package ( PythonLibs REQUIRED ) - find_package ( Numpy ) -endif() - -macro(swap_cache_variable var1 var2) - # Only swap variable if var1 exists in the cmake cache - if (${var1}) - set(_backup ${${var1}}) - get_property(_var1_type CACHE ${var1} PROPERTY TYPE) - get_property(_var1_help CACHE ${var1} PROPERTY HELPSTRING) - get_property(_var2_type CACHE ${var2} PROPERTY TYPE) - get_property(_var2_help CACHE ${var2} PROPERTY HELPSTRING) - set(${var1} ${${var2}} CACHE ${_var1_type} "${_var1_help}" FORCE) - set(${var2} ${_backup} CACHE ${_var2_type} "${_var2_help}" FORCE) + find_package(Numpy) + if ( NOT NUMPY_FOUND ) + message( WARNING + "OTB wrappers will be done without support for NumPy (not found).") endif() -endmacro() - -macro(swap_variable var1 var2) - set(_backup ${${var1}}) - set(${var1} ${${var2}}) - set(${var2} ${_backup}) -endmacro() - -if ( OTB_WRAP_PYTHON3 ) - set(PYTHON3_EXECUTABLE "PYTHON3_EXECUTABLE-NOTFOUND" CACHE FILEPATH "Path to python 3 interpreter") - set(PYTHON3_INCLUDE_DIR "PYTHON3_INCLUDE_DIR-NOTFOUND" CACHE PATH "Path to python 3 include directory") - set(PYTHON3_LIBRARY "PYTHON3_LIBRARY-NOTFOUND" CACHE FILEPATH "Path to python 3 library") - set(PYTHON3_LIBRARY_DEBUG "PYTHON3_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to python 3 library (debug)") - set(PYTHON3_LIBRARY_RELEASE "PYTHON3_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to python 3 library (release)") - set(NUMPY_PYTHON3_INCLUDE_DIR "NUMPY_PYTHON3_INCLUDE_DIR" CACHE PATH "Path to numpy module for Python 3") - - # Swap cache variables between python and python3 - swap_cache_variable(PYTHON_EXECUTABLE PYTHON3_EXECUTABLE) - swap_cache_variable(PYTHON_INCLUDE_DIR PYTHON3_INCLUDE_DIR) - swap_cache_variable(PYTHON_LIBRARY PYTHON3_LIBRARY) - swap_cache_variable(PYTHON_LIBRARY_DEBUG PYTHON3_LIBRARY_DEBUG) - swap_cache_variable(PYTHON_LIBRARY_RELEASE PYTHON3_LIBRARY_RELEASE) - swap_cache_variable(NUMPY_INCLUDE_DIR NUMPY_PYTHON3_INCLUDE_DIR) - - swap_variable(PYTHON_LIBRARIES PYTHON3_LIBRARIES) - swap_variable(NUMPY_INCLUDE_DIRS NUMPY_PYTHON3_INCLUDE_DIRS) - swap_variable(NUMPY_FOUND NUMPY_PYTHON3_FOUND) - swap_variable(PYTHON_VERSION_STRING PYTHON3_VERSION_STRING) - - check_PIC_flag ( Python ) - find_package ( PythonInterp 3 REQUIRED ) - find_package ( PythonLibs 3 REQUIRED ) - find_package ( Numpy ) - - # Swap cache variables between python and python3 - swap_cache_variable(PYTHON_EXECUTABLE PYTHON3_EXECUTABLE) - swap_cache_variable(PYTHON_INCLUDE_DIR PYTHON3_INCLUDE_DIR) - swap_cache_variable(PYTHON_LIBRARY PYTHON3_LIBRARY) - swap_cache_variable(PYTHON_LIBRARY_DEBUG PYTHON3_LIBRARY_DEBUG) - swap_cache_variable(PYTHON_LIBRARY_RELEASE PYTHON3_LIBRARY_RELEASE) - swap_cache_variable(NUMPY_INCLUDE_DIR NUMPY_PYTHON3_INCLUDE_DIR) - - swap_variable(PYTHON_LIBRARIES PYTHON3_LIBRARIES) - swap_variable(NUMPY_INCLUDE_DIRS NUMPY_PYTHON3_INCLUDE_DIRS) - swap_variable(NUMPY_FOUND NUMPY_PYTHON3_FOUND) - swap_variable(PYTHON_VERSION_STRING PYTHON3_VERSION_STRING) endif() # diff --git a/Modules/Wrappers/SWIG/src/CMakeLists.txt b/Modules/Wrappers/SWIG/src/CMakeLists.txt index 5b5fea9f4cf40ce42854fb055e15819fb132ed74..bf7b888185f28195bf2d696bb67ee2dd06c58b11 100644 --- a/Modules/Wrappers/SWIG/src/CMakeLists.txt +++ b/Modules/Wrappers/SWIG/src/CMakeLists.txt @@ -18,7 +18,7 @@ # limitations under the License. # -if ( OTB_WRAP_PYTHON OR OTB_WRAP_JAVA OR OTB_WRAP_PYTHON3) +if ( OTB_WRAP_PYTHON OR OTB_WRAP_JAVA ) include ( UseSWIGLocal ) list(APPEND SWIG_EXTRA_DEPS otbWrapperSWIGIncludes.h @@ -34,11 +34,6 @@ if ( OTB_WRAP_PYTHON ) add_subdirectory(python) endif() -# Python 3 SWIG configuration -if ( OTB_WRAP_PYTHON3 ) - add_subdirectory(python3) -endif() - # JAVA SWIG configuration if ( OTB_WRAP_JAVA ) add_subdirectory(java) diff --git a/Modules/Wrappers/SWIG/src/python/CMakeLists.txt b/Modules/Wrappers/SWIG/src/python/CMakeLists.txt index 9290ec912c287f9c9528eb27ed9b890cb7bc3ea8..0a8bcc684e11090b42e832b3c69b98c4b64cd551 100644 --- a/Modules/Wrappers/SWIG/src/python/CMakeLists.txt +++ b/Modules/Wrappers/SWIG/src/python/CMakeLists.txt @@ -19,7 +19,7 @@ # include_directories ( ${PYTHON_INCLUDE_DIR} ) -include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} ) +include_directories ( ${CMAKE_CURRENT_SOURCE_DIR}) set_source_files_properties ( ../otbApplication.i PROPERTIES CPLUSPLUS ON ) # Run swig set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_GLOBAL_FLAGS}) @@ -32,10 +32,20 @@ set(SWIG_MODULE_otbApplication_EXTRA_DEPS ${CMAKE_CURRENT_SOURCE_DIR}/../Python.i ${CMAKE_CURRENT_SOURCE_DIR}/../PyCommand.i itkPyCommand.h + otbLogOutputCallback.h + otbPythonLogOutput.h + otbCallbackProgressReporter.h + otbProgressReporterManager.h OTBApplicationEngine) -SWIG_add_module( otbApplication python ../otbApplication.i otbApplicationPYTHON_wrap.cxx itkPyCommand.cxx ) +SWIG_add_module( otbApplication python ../otbApplication.i + otbApplicationPYTHON_wrap.cxx + itkPyCommand.cxx + ../python/otbPythonLogOutput.cxx + ../python/otbCallbackProgressReporter.cxx + ../python/otbProgressReporterManager.cxx) SWIG_link_libraries( otbApplication ${PYTHON_LIBRARIES} OTBApplicationEngine ) set_target_properties(_otbApplication PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SWIG_OUTDIR}) + if(MSVC) set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/otbApplicationPYTHON_wrap.cxx COMPILE_FLAGS "/wd4005" ) else() diff --git a/Modules/Wrappers/SWIG/src/python3/CMakeLists.txt b/Modules/Wrappers/SWIG/src/python3/CMakeLists.txt deleted file mode 100644 index a00335eabbfb745af9c985929925e30bbccd626c..0000000000000000000000000000000000000000 --- a/Modules/Wrappers/SWIG/src/python3/CMakeLists.txt +++ /dev/null @@ -1,82 +0,0 @@ -# -# Copyright (C) 2005-2019 CS Systemes d'Information (CS SI) -# -# This file is part of Orfeo Toolbox -# -# https://www.orfeo-toolbox.org/ -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -include_directories ( ${PYTHON3_INCLUDE_DIR} ) -include_directories ( ${CMAKE_CURRENT_SOURCE_DIR}/../python ) -set_source_files_properties ( ../otbApplication.i PROPERTIES CPLUSPLUS ON ) -# Run swig -set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_GLOBAL_FLAGS}) -if(NUMPY_PYTHON3_FOUND) - include_directories(${NUMPY_PYTHON3_INCLUDE_DIRS}) - list(APPEND CMAKE_SWIG_FLAGS "-DOTB_SWIGNUMPY=1") -endif() -set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR}/${OTB_INSTALL_PYTHON3_DIR}) -set(SWIG_MODULE_otbApplication_EXTRA_DEPS - ${CMAKE_CURRENT_SOURCE_DIR}/../Python.i - ${CMAKE_CURRENT_SOURCE_DIR}/../PyCommand.i - itkPyCommand.h - otbLogOutputCallback.h - otbPythonLogOutput.h - otbCallbackProgressReporter.h - otbProgressReporterManager.h - OTBApplicationEngine) -SWIG_add_module( otbApplicationPy3 python ../otbApplication.i - otbApplicationPYTHON_wrap.cxx - ../python/itkPyCommand.cxx - ../python/otbPythonLogOutput.cxx - ../python/otbCallbackProgressReporter.cxx - ../python/otbProgressReporterManager.cxx) -SWIG_link_libraries( otbApplicationPy3 ${PYTHON3_LIBRARIES} OTBApplicationEngine ) -set_target_properties(_otbApplicationPy3 PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SWIG_OUTDIR}) -set_target_properties(_otbApplicationPy3 PROPERTIES LIBRARY_OUTPUT_NAME _otbApplication) -if(MSVC) - set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/otbApplicationPYTHON_wrap.cxx COMPILE_FLAGS "/wd4005" ) -else() - set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/otbApplicationPYTHON_wrap.cxx COMPILE_FLAGS "-w" ) -endif() - -# byte-compile the resulting python file -add_custom_command( - TARGET _otbApplicationPy3 - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E echo "Byte-compiling otbApplication.py" - COMMAND ${PYTHON3_EXECUTABLE} - ${CMAKE_SOURCE_DIR}/CMake/PythonCompile.py - ${CMAKE_SWIG_OUTDIR}/otbApplication.py - DEPENDS _otbApplicationPy3 - ) - -otb_module_target_label( _otbApplicationPy3 ) - -install( TARGETS _otbApplicationPy3 - DESTINATION ${OTB_INSTALL_PYTHON3_DIR} - COMPONENT RuntimeLibraries ) - -install( FILES ${CMAKE_SWIG_OUTDIR}/otbApplication.py - DESTINATION ${OTB_INSTALL_PYTHON3_DIR} - COMPONENT RuntimeLibraries ) - -if(PYTHON3_VERSION_STRING VERSION_LESS "3.2.0") - install( FILES ${CMAKE_SWIG_OUTDIR}/otbApplication.pyc - DESTINATION ${OTB_INSTALL_PYTHON3_DIR} - COMPONENT RuntimeLibraries ) -else() - # TODO : pyc file is in a subfolder. -endif() diff --git a/Packaging/CMakeLists.txt b/Packaging/CMakeLists.txt index 089cb6e350743f77c4d67b6c08f01670659b025b..698edc7321baa9eab96003aa917a0c7c8f26e185 100644 --- a/Packaging/CMakeLists.txt +++ b/Packaging/CMakeLists.txt @@ -51,10 +51,6 @@ if( "${CMAKE_SYSTEM_NAME}" MATCHES "Linux") set(LINUX TRUE) endif() -if(OTB_WRAP_PYTHON AND NOT PYTHON_EXECUTABLE) - find_package(PythonInterp REQUIRED) -endif() - find_program(FILE_COMMAND NAMES "file") find_program(READLINK NAMES "readlink") find_program(ZIP_EXECUTABLE NAMES 7z 7za) @@ -182,11 +178,6 @@ if(EXISTS "${SUPERBUILD_INSTALL_DIR}/lib/otb/python/_otbApplication${PYMODULE_EX set(HAVE_PYTHON TRUE) endif() -set(HAVE_PYTHON3 FALSE CACHE INTERNAL "Python3 wrappings") -if(EXISTS "${SUPERBUILD_INSTALL_DIR}/lib/otb/python3/_otbApplication${PYMODULE_EXT}") - set(HAVE_PYTHON3 TRUE) -endif() - set(HAVE_JAVA FALSE CACHE INTERNAL "Java wrappings") if(EXISTS "${SUPERBUILD_INSTALL_DIR}/lib/otb/java/org.otb.application.jar") set(HAVE_JAVA TRUE) diff --git a/Packaging/CTestConfig.cmake b/Packaging/CTestConfig.cmake index c998a21193f7778027f68b338162393aa96d5a31..35a87e8e010b6464fbee114c714eb63fdece763e 100644 --- a/Packaging/CTestConfig.cmake +++ b/Packaging/CTestConfig.cmake @@ -24,5 +24,5 @@ set(CTEST_DROP_METHOD "https") set(CTEST_DROP_SITE "dash.orfeo-toolbox.org") set(CTEST_DROP_LOCATION "/submit.php?project=OTB") set(CTEST_DROP_SITE_CDASH TRUE) -set(CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE 4096) -set(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE 4096) +set(CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE 409600) +set(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE 409600) diff --git a/Packaging/Files/selftester.bat b/Packaging/Files/selftester.bat index 622b6d4591b276b7e6343be6f37c12f9ac5dc25f..dc44d62ba8757ac0a842eb29e7252aa48804ceda 100755 --- a/Packaging/Files/selftester.bat +++ b/Packaging/Files/selftester.bat @@ -180,7 +180,7 @@ goto :eof :check_python_wrapping setlocal type NUL > tmp.log -python -c "import otbApplication" > tmp.log 2>&1 +python3 -c "import otbApplication" > tmp.log 2>&1 call :nb_tmp_lines if %nb_tmp_lines_out% gtr 0 ( echo ERROR : failed to run python wrapping diff --git a/Packaging/Files/selftester.sh b/Packaging/Files/selftester.sh index 8906e1d86cb242c129ddc0ee40db8dfbc18eb5c4..5dfe3e38ce17e9a60c0ab1e2495d5d9814b2de24 100755 --- a/Packaging/Files/selftester.sh +++ b/Packaging/Files/selftester.sh @@ -159,7 +159,7 @@ for app in $OTB_APPS; do done # test python wrapping -PY_OUTPUT=$(python -c 'import otbApplication' 2>&1) +PY_OUTPUT=$(python3 -c 'import otbApplication' 2>&1) if [ -n "$PY_OUTPUT" ]; then echo_and_report "ERROR: python wrapping test failed :" echo_and_report "$PY_OUTPUT" diff --git a/Packaging/Files/setup_python.sh b/Packaging/Files/setup_python.sh index 3b1c7984d36cb5b9eff052292b36c2b7709739a5..d2b256f7111fca6a8e14545692114869be24988b 100755 --- a/Packaging/Files/setup_python.sh +++ b/Packaging/Files/setup_python.sh @@ -20,38 +20,61 @@ # # get current working dir (this should be the install directory) +python_version_check() { + python_major_version=$($OTB_PYTHON_EXE -c "import sys;print(sys.version_info[0])") + python_minor_version=$($OTB_PYTHON_EXE -c "import sys;print(sys.version_info[1])") + python_patch_version=$($OTB_PYTHON_EXE -c "import sys;print(sys.version_info[2])") + python_version="$python_major_version.$python_minor_version.$python_patch_version" +} + +python_check_failed() { + printf %s\\n "*****Error occurred during installation******" + printf %s\\n "OTB python bindings normally require python 3.5 but current \ + detected python version is $python_version" + printf %s\\n "If you have python 3.5 installed in your system you should \ + set OTB_PYTHON_EXE and re-run this installation script." + printf %s\\n "eg: OTB_PYTHON_EXE=/path/to/python3 ./OTB-X.Y-Linux64.run" + printf %s\\n "Python bindings might not work." +} + CWD=$(pwd) +CUSTOM_PYTHON=true # Setup python environment if [ ! -f "$OTB_PYTHON_EXE" ] ; then + CUSTOM_PYTHON=false + OTB_PYTHON_EXE=$(which python3) + if [ ! -f "$OTB_PYTHON_EXE" ] ; then OTB_PYTHON_EXE=$(which python) + # On old system we still have python => python2.x and python3 => python3.x + if [ ! -f "$OTB_PYTHON_EXE" ] ; then + printf %s\\n "*****Error occurred during installation******" + printf %s\\n "Python executable not found" + exit 1 + fi + fi fi -if [ ! -f "$OTB_PYTHON_EXE" ] ; then - printf %s\\n "*****Error occurred during installation******" - printf %s\\n "Python executable not found" - exit 1 -fi - -python_major_version=$($OTB_PYTHON_EXE -c "import sys;print(sys.version_info[0])") -python_minor_version=$($OTB_PYTHON_EXE -c "import sys;print(sys.version_info[1])") -python_patch_version=$($OTB_PYTHON_EXE -c "import sys;print(sys.version_info[2])") -python_version="$python_major_version.$python_minor_version.$python_patch_version" +#From here we should have a python executable -python_check_failed() { - printf %s\\n "*****Error occurred during installation******" - printf %s\\n "OTB python bindings requires python2.6 or python2.7 but current detected python version is $python_version" - printf %s\\n "If you have python2.6 or Python2.7 installed in your system " - printf %s\\n "You should set OTB_PYTHON_EXE and re-run this installation script." - printf %s\\n "eg: OTB_PYTHON_EXE=/path/to/python2.7 ./OTB-X.Y-Linux64.run" - exit 1 -} -if [ "$python_major_version" -gt 2 ]; then -python_check_failed -fi +python_version_check -if [ "$python_minor_version" -lt 5 ]; then -python_check_failed +if [ ! $CUSTOM_PYTHON ] + then + if [ ! "$python_major_version" -eq 3 ] && [ ! "$python_minor_version" -eq 5 ] + then + python_check_failed + fi +else # case wher user provides an OTB_PYTHON_EXE + if [ ! "$python_major_version" -eq 3 ] || [ ! "$python_minor_version" -eq 5 ] + then + printf %s\\n "*****Warning******" + printf %s\\n "OTB python bindings normally require python3.5." + printf %s\\n "The version of OTB_PYTHON_EXE ($OTB_PYTHON_EXE) is \ + $python_version." + printf %s\\n "This case is undefined unless you are sure the packages were \ + build with this version of python." + fi fi python_INSTSONAME=$($OTB_PYTHON_EXE -c "import sys; from distutils import sysconfig; print (sysconfig.get_config_var('INSTSONAME'));") @@ -76,13 +99,14 @@ if [ "$found_python_lib" -eq "1" ]; then numpy_import_result="$($OTB_PYTHON_EXE -c 'import numpy' 2>&1)" || numpy_ret=$? if [ ! -z "$numpy_import_result" ]; then printf %s\\n "*****Error occurred during installation******" - printf %s\\n "Python interpreter detected is : $OTB_PYTHON_EXE ( version: $python_version )" + printf %s\\n "Python interpreter detected is : $OTB_PYTHON_EXE \ + ( version: $python_version )" printf %s\\n "numpy not installed with '$OTB_PYTHON_EXE'" printf %s\\n "Check failed with result:" printf %s\\n "$numpy_import_result" - exit 1 else - printf %s\\n "OTB python bindings will be configured for $OTB_PYTHON_EXE ( version: $python_version )" + printf %s\\n "OTB python bindings will be configured for $OTB_PYTHON_EXE \ + ( version: $python_version )" printf %s\\n "Found python library: $python_lib_file_path" fi #ln -sf "$python_lib_file_path" "$CWD/lib/$python_INSTALLED_SONAME" @@ -94,5 +118,4 @@ else printf %s\\n "If you don't have python-dev package installed, install it and make a symlink" printf %s\\n "If you don't have python headers and so installed on a custom location, then make a symlink" printf %s\\n "eg: ln -s /usr/lib/x86_64-linux-gnu/$python_INSTSONAME $CWD/lib/$python_INSTSONAME" - exit 1 fi diff --git a/Packaging/Files/uninstall_otb.bat b/Packaging/Files/uninstall_otb.bat index cbe917c1479c7bb3b05e96d7f124f784cee88a6a..cc112505c175279155b5af2e31e3752ef4aab84e 100644 --- a/Packaging/Files/uninstall_otb.bat +++ b/Packaging/Files/uninstall_otb.bat @@ -37,7 +37,6 @@ rd /S /Q lib\otb del /S /Q lib\otb* del /S /Q lib\python\*otbApplication.* || exit 1 -del /S /Q lib\python3\*otbApplication.* || exit 1 del /S /Q lib\java\org.otb.application.jar || exit 1 del /S /Q bin\otb* || exit 1 del /S /Q bin\monteverdi.exe || exit 1 diff --git a/Packaging/Files/uninstall_otb.sh b/Packaging/Files/uninstall_otb.sh index c46ff597460258fab93194df05d2ca50c19716a5..d160333f402a31c77aa287c73b431ae182253214 100755 --- a/Packaging/Files/uninstall_otb.sh +++ b/Packaging/Files/uninstall_otb.sh @@ -21,7 +21,7 @@ set -e rm -fr OUT_DIR/include/OTB-* rm -f OUT_DIR/lib/{libotb*,libOTB*} -rm -fr OUT_DIR/lib/{otb,python/*otbApplication*,python3/*otbApplication*,java/org.otb.application.jar} +rm -fr OUT_DIR/lib/{otb,python/*otbApplication*,java/org.otb.application.jar} rm -fr OUT_DIR/lib/cmake/OTB-* rm -fr OUT_DIR/share/otb/ rm -fv OUT_DIR/bin/{otb*,monteverdi,mapla} diff --git a/Packaging/check_cmake_variables.cmake b/Packaging/check_cmake_variables.cmake index 0744e625d5e253a43ac9b7933ea4d1548d77e5f6..4582ede61f9741215d6f4872a6bde91b61039ef3 100644 --- a/Packaging/check_cmake_variables.cmake +++ b/Packaging/check_cmake_variables.cmake @@ -19,10 +19,6 @@ # macro(check_cmake_variables) set(required_vars) - if(OTB_WRAP_PYTHON) - list(APPEND required_vars PYTHON_EXECUTABLE) - endif() - if(LINUX) list(APPEND required_vars FILE_COMMAND) list(APPEND required_vars READLINK) diff --git a/Packaging/install_python_bindings.cmake b/Packaging/install_python_bindings.cmake index 0dbe1ee705764a9c7cefc75bea1e437609e72865..754986de0a96b845f761ca02143a73ac839ee843 100644 --- a/Packaging/install_python_bindings.cmake +++ b/Packaging/install_python_bindings.cmake @@ -25,20 +25,15 @@ function(install_python_bindings) PATTERN "__pycache__" EXCLUDE ) endif() - if(HAVE_PYTHON3) - install(DIRECTORY ${SUPERBUILD_INSTALL_DIR}/lib/otb/python3 - DESTINATION ${PKG_STAGE_DIR}/lib - PATTERN "*.pyc" EXCLUDE - PATTERN "__pycache__" EXCLUDE - ) - endif() # Handle GDAL python bindings file(GLOB gdal_python_scripts "${SUPERBUILD_INSTALL_DIR}/bin/gdal*.py") foreach(_script ${gdal_python_scripts}) install(PROGRAMS ${_script} DESTINATION ${PKG_STAGE_DIR}/bin) endforeach() - file(GLOB gdal_python_wrappings "${SUPERBUILD_INSTALL_DIR}/lib/python[2|3]*") + # file(GLOB gdal_python_wrappings "${SUPERBUILD_INSTALL_DIR}/lib/python[2|3]*") + # Do we need to get rid of gdal python 2 bindings too? + file(GLOB gdal_python_wrappings "${SUPERBUILD_INSTALL_DIR}/lib/python*") foreach(_wrap ${gdal_python_wrappings}) if (IS_DIRECTORY "${_wrap}") install(DIRECTORY ${_wrap} diff --git a/SuperBuild/CMake/External_gdal.cmake b/SuperBuild/CMake/External_gdal.cmake index 4534c9c98d90e387ee30ececc4df52ed27d01be0..618ff71265f2c7928454d17f39ad73950e4a35fd 100644 --- a/SuperBuild/CMake/External_gdal.cmake +++ b/SuperBuild/CMake/External_gdal.cmake @@ -106,8 +106,14 @@ if(UNIX) ${GDAL_SB_CONFIG} ${GDAL_SB_EXTRA_OPTIONS} ) - #set(GDAL_BUILD_COMMAND ${CMAKE_MAKE_PROGRAM}) - #set(GDAL_INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install) + + # For now gdal is built if Superbuild has find python... And only on UNIX + # That might be a problem + # User will not be able to override this... + if ( OTB_WRAP_PYTHON AND PYTHON_EXECUTABLE) + list(APPEND GDAL_CONFIGURE_COMMAND "--with-python=${PYTHON_EXECUTABLE}") + endif() + else(MSVC) configure_file( diff --git a/SuperBuild/CMake/External_otb.cmake b/SuperBuild/CMake/External_otb.cmake index 31466622cf365c82211ec735e3467d84235854ce..556ff87310f79077eb82dfa548106c40c9cf9cd9 100644 --- a/SuperBuild/CMake/External_otb.cmake +++ b/SuperBuild/CMake/External_otb.cmake @@ -79,7 +79,7 @@ if(OTB_USE_MUPARSERX) ADD_SUPERBUILD_CMAKE_VAR(OTB MUPARSERX_LIBRARY) endif() -if(OTB_WRAP_PYTHON OR OTB_WRAP_JAVA OR OTB_WRAP_PYTHON3) +if(OTB_WRAP_PYTHON OR OTB_WRAP_JAVA) ADD_SUPERBUILD_CMAKE_VAR(OTB SWIG_EXECUTABLE) ADDTO_DEPENDENCIES_IF_NOT_SYSTEM(OTB SWIG) endif() @@ -90,12 +90,6 @@ if(OTB_WRAP_PYTHON) ADD_SUPERBUILD_CMAKE_VAR(OTB PYTHON_EXECUTABLE) endif() -if(OTB_WRAP_PYTHON3) - ADD_SUPERBUILD_CMAKE_VAR(OTB PYTHON3_INCLUDE_DIR) - ADD_SUPERBUILD_CMAKE_VAR(OTB PYTHON3_LIBRARY) - ADD_SUPERBUILD_CMAKE_VAR(OTB PYTHON3_EXECUTABLE) -endif() - if(OTB_USE_QT) ADDTO_DEPENDENCIES_IF_NOT_SYSTEM(OTB QT5) ADD_SUPERBUILD_CMAKE_VAR(OTB QT_QMAKE_EXECUTABLE) @@ -150,7 +144,7 @@ ADD_SUPERBUILD_CMAKE_VAR(OTB Boost_LIBRARY_DIR) set(OTB_MODULES_CONFIG) if(WITH_REMOTE_MODULES) - foreach(remote_module SertitObject Mosaic otbGRM OTBFFSforGMM DiapOTBModule) + foreach(remote_module SertitObject Mosaic otbGRM DiapOTBModule) list(APPEND OTB_MODULES_CONFIG -DModule_${remote_module}:BOOL=ON) endforeach() @@ -213,10 +207,10 @@ ExternalProject_Add(OTB -DOTB_USE_OPENMP:BOOL=${OTB_USE_OPENMP} -DOTB_USE_GSL:BOOL=${OTB_USE_GSL} -DOTB_WRAP_PYTHON:BOOL=${OTB_WRAP_PYTHON} - -DOTB_WRAP_PYTHON3:BOOL=${OTB_WRAP_PYTHON3} -DOTB_WRAP_JAVA:BOOL=${OTB_WRAP_JAVA} -DOTB_USE_MPI:BOOL=${OTB_USE_MPI} -DOTB_USE_SPTW:BOOL=${OTB_USE_SPTW} + -DPYTHON_EXECUTABLE:PATH=${PYTHON_EXECUTABLE} ${OTB_ADDITIONAL_CACHE} CMAKE_ARGS ${OTB_SB_CONFIG} CMAKE_COMMAND ${SB_CMAKE_COMMAND} diff --git a/SuperBuild/CMake/External_swig.cmake b/SuperBuild/CMake/External_swig.cmake index 7c95bd9cb9e0c365af40b03b4596226c88c1aafb..ce8f49a3360c34b6874991be4beaa755b19e9f21 100644 --- a/SuperBuild/CMake/External_swig.cmake +++ b/SuperBuild/CMake/External_swig.cmake @@ -22,9 +22,7 @@ INCLUDE_ONCE_MACRO(SWIG) SETUP_SUPERBUILD(SWIG) -set(PythonInterp_FIND_VERSION 2.7) -find_package(PythonInterp) -if(PYTHONINTERP_FOUND) +if( PYTHON_EXECUTABLE ) set(SWIG_SB_PYTHON_CONFIG "--with-python=${PYTHON_EXECUTABLE}") else() set(SWIG_SB_PYTHON_CONFIG) diff --git a/SuperBuild/CMakeLists.txt b/SuperBuild/CMakeLists.txt index 1ee7296feee01b2d88a39f37c82970806b681d01..a2befe2fa4ffc1cc3bd68febf9146a82e1327eb9 100644 --- a/SuperBuild/CMakeLists.txt +++ b/SuperBuild/CMakeLists.txt @@ -350,7 +350,6 @@ find_path(OTB_DATA_ROOT README-OTB-Data # SWIG Wrapping option(OTB_WRAP_PYTHON "Enable python wrappers for OTB applications (requires SWIG)" ON) -option(OTB_WRAP_PYTHON3 "Enable python 3 wrappers for OTB applications (requires SWIG)" OFF) option(OTB_WRAP_JAVA "Enable java wrappers for OTB applications (requires SWIG)" OFF) configure_file(${CMAKE_SOURCE_DIR}/CMake/CTestCustom.cmake.in @@ -376,6 +375,22 @@ foreach(lib ${_SYSTEM_CHECKUP_CONTENT}) message(STATUS "|----------------------------------------------------------") endforeach() +# Python +# This should set the following variables (and more): +# -PYTHON_EXECUTABLE +# -PYTHON_INCLUDE_DIR +# -PYTHON_LIBRARY +set ( Python_ADDITIONAL_VERSIONS "3;2" ) +set ( PythonInterp_FIND_REQUIRED ${OTB_WRAP_PYTHON} ) +set ( PythonLibs_FIND_REQUIRED ${OTB_WRAP_PYTHON} ) +find_package( PythonInterp ) +if ( OTB_WRAP_PYTHON AND ( ${PYTHON_VERSION_MAJOR} EQUAL 2 ) ) + message (WARNING "Python3 not found. There is no longer support of \ + wrapping in python2 in OTB, but it can still be used.") +endif() +set (Python_ADDITIONAL_VERSIONS "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}") +find_package ( PythonLibs ) + include(External_otb) if(FROM_SYSTEM_LIST)