From 080d0a767b937d2845fb9f378ad9ce84c66ccd51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20K=C3=BCnsem=C3=B6ller?= <jkuensem@physik.uni-bielefeld.de> Date: Tue, 12 Jun 2018 15:17:36 +0000 Subject: [PATCH] Task LSMR-8: attempt to switch to Python 3 --- CMake/FindPython3Module.cmake | 106 ---------------------------------- SAS/LSMR/src/CMakeLists.txt | 15 ++--- SAS/LSMR/test/CMakeLists.txt | 6 +- 3 files changed, 11 insertions(+), 116 deletions(-) delete mode 100644 CMake/FindPython3Module.cmake diff --git a/CMake/FindPython3Module.cmake b/CMake/FindPython3Module.cmake deleted file mode 100644 index 6ed28bee7fa..00000000000 --- a/CMake/FindPython3Module.cmake +++ /dev/null @@ -1,106 +0,0 @@ -# - Try to find a Python module. -# The macro PYTHON_FIND_PACKAGE(module) tries to find python module <module>. -# -# Variables defined by this module: -# PYTHON_<MODULE> - file path of python <module>, if found (cached) -# PYTHON_<MODULE>_FOUND - true if python <module> was found, else false. - -# Copyright (C) 2015 -# ASTRON (Netherlands Institute for Radio Astronomy) -# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands -# -# This file is part of the LOFAR software suite. -# The LOFAR software suite 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. -# -# The LOFAR software suite 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 the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. -# -# $Id$ - -# Search for the Python interpreter. -find_package(PythonInterp) - -# ----------------------------------------------------------------------------- -# find_python3_module(module [REQUIRED]) -# -# Find the python module <module>. -# Set variable PYTHON_<MODULE> to the file path of <module> (cached). -# Set variable PYTHON_<MODULE>_FOUND to TRUE if <module> was found, else -# set it to FALSE. -# The REQUIRED option stops processing with an error message if the module -# <module> cannot be found. -# The HINTS option can be used to give a path (or colon-separated list of -# paths) that are prepended to the search path. -# ----------------------------------------------------------------------------- -include(CMakeParseArguments) - -function(find_python3_module _module) - # Name of module in uppercase. - string(TOUPPER "${_module}" _MODULE) - - list(FIND ARGV REQUIRED is_required) - - IF(BUILD_DOCUMENTATION) - IF(is_required GREATER -1) - # Removing REQUIRED option while looking for package. - # This allows cmake to continue configuring so you could make the doc, - # but building the code might not be possible. - # In case the package is not found, a WARNING is issued below. - list(REMOVE_ITEM ARGV REQUIRED) - list(REMOVE_ITEM ARGN REQUIRED) - ENDIF() - ENDIF(BUILD_DOCUMENTATION) - - cmake_parse_arguments(PYTHON_${_MODULE}_FIND - "REQUIRED" - "HINTS" - "" - ${ARGN} - ) - - if(NOT "${PYTHON_${_MODULE}_FIND_UNPARSED_ARGUMENTS}" STREQUAL "") - MESSAGE(FATAL_ERROR "Unknown arguments: ${PYTHON_${_MODULE}_FIND_UNPARSED_ARGUMENTS}") - endif() - - # Try to find the python module, if we have not found it yet. - if(NOT PYTHON_${_MODULE}) - # Try to import the python module we need to find, and get its file path. - if(PYTHON_EXECUTABLE) - set(ENV{PYTHONPATH} ${PYTHON_${_MODULE}_FIND_HINTS}:$ENV{PYTHONPATH}) - set(_cmd "from __future__ import print_function; import ${_module}; print(${_module}.__file__)") - execute_process( - COMMAND "/usr/bin/python3" "-c" "${_cmd}" - RESULT_VARIABLE _result - OUTPUT_VARIABLE _output - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - - # Set PYTHON_<MODULE> variable in the cache, if <module> was found. - if(_result EQUAL 0) - set(PYTHON_${_MODULE} ${_output} CACHE FILEPATH - "Path to python module ${_module}") - endif() - - endif() - endif() - - # Report result, and set PYTHON_<MODULE>_FOUND - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(PYTHON_${_MODULE} DEFAULT_MSG - PYTHON_${_MODULE}) - - if(NOT PYTHON_${_MODULE}_FOUND) - if(is_required GREATER -1) - message(WARNING "Removed REQUIRED option while looking for python module '${_module}' because BUILD_DOCUMENTATION=${BUILD_DOCUMENTATION}. This allows cmake to continue configuring so you could make the doc, but building the code might not be possible.") - endif(is_required GREATER -1) - endif(NOT PYTHON_${_MODULE}_FOUND) - -endfunction() diff --git a/SAS/LSMR/src/CMakeLists.txt b/SAS/LSMR/src/CMakeLists.txt index cb0ede1e343..2eba218c2b9 100644 --- a/SAS/LSMR/src/CMakeLists.txt +++ b/SAS/LSMR/src/CMakeLists.txt @@ -1,15 +1,16 @@ +lofar_find_package(PythonInterp 3.4 REQUIRED) set(USE_PYTHON_COMPILATION Off) set(PYTHON_EXECUTABLE /usr/bin/python3) -lofar_find_package(PythonInterp 3.4 REQUIRED) + include(PythonInstall) -include(FindPython3Module) +include(FindPythonModule) -find_python3_module(django REQUIRED) -find_python3_module(rest_framework REQUIRED) # pip install djangorestframework -find_python3_module(ldap REQUIRED) -# find_python3_module(markdown REQUIRED) -# find_python3_module(django_filters REQUIRED) # pip install django-filter # FIXME: raises exception on import +find_python_module(django REQUIRED) +find_python_module(rest_framework REQUIRED) # pip install djangorestframework +find_python_module(ldap REQUIRED) +# find_python_module(markdown REQUIRED) # Fixme: not discovered reliably... why?! +# find_python_module(django_filters REQUIRED) # pip install django-filter # FIXME: raises exception on import set(_py_files manage.py diff --git a/SAS/LSMR/test/CMakeLists.txt b/SAS/LSMR/test/CMakeLists.txt index 4eed12a329b..f0bd23db4f8 100644 --- a/SAS/LSMR/test/CMakeLists.txt +++ b/SAS/LSMR/test/CMakeLists.txt @@ -1,10 +1,10 @@ include(LofarCTest) -include(FindPython3Module) +include(FindPythonModule) set(USE_PYTHON_COMPILATION Off) set(PYTHON_EXECUTABLE /usr/bin/python3) -find_python3_module(mock REQUIRED) -find_python3_module(requests REQUIRED) +find_python_module(mock REQUIRED) +find_python_module(requests REQUIRED) lofar_add_test(t_lsmrapp_models) lofar_add_test(t_functional) -- GitLab