From 47db97620b26dc844262a9b12591f8c559293d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 27 May 2020 14:57:40 +0200 Subject: [PATCH 1/2] cmake: Check python packages availability in tests Use dedicated fixtures to skip tests that rely on uninstalled Python packages instead of relying on custom CMake code. --- CMakeLists.txt | 2 -- testsuite/python/CMakeLists.txt | 5 +---- testsuite/python/h5md.py | 10 +++++++++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 934e6096a0a..74672f7d4f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,8 +197,6 @@ if(WITH_HDF5) if(HDF5_FOUND) if(HDF5_IS_PARALLEL) set(H5MD 1) - include(FindPythonModule) - find_python_module(h5py) add_feature_info(HDF5 ON "parallel") else() unset(H5MD) diff --git a/testsuite/python/CMakeLists.txt b/testsuite/python/CMakeLists.txt index 6dbbb725930..a8c8ab23c6f 100644 --- a/testsuite/python/CMakeLists.txt +++ b/testsuite/python/CMakeLists.txt @@ -205,10 +205,7 @@ python_test(FILE elc.py MAX_NUM_PROC 2) python_test(FILE elc_vs_analytic.py MAX_NUM_PROC 2) python_test(FILE rotation.py MAX_NUM_PROC 1) python_test(FILE shapes.py MAX_NUM_PROC 1) - -if(PY_H5PY) - python_test(FILE h5md.py MAX_NUM_PROC 2) -endif(PY_H5PY) +python_test(FILE h5md.py MAX_NUM_PROC 2) add_custom_target( python_test_data diff --git a/testsuite/python/h5md.py b/testsuite/python/h5md.py index 370ef83151d..faf35e5e308 100644 --- a/testsuite/python/h5md.py +++ b/testsuite/python/h5md.py @@ -26,8 +26,14 @@ import unittest_decorators as utx import numpy as np import espressomd -import h5py # h5py has to be imported *after* espressomd (MPI) from espressomd.interactions import Virtual +try: + import h5py # h5py has to be imported *after* espressomd (MPI) + skipIfMissingPythonPackage = ut.case._id +except ImportError: + skipIfMissingPythonPackage = ut.skip( + "Python module h5py not available, skipping test!") + npart = 26 @@ -121,6 +127,7 @@ def test_bonds(self): @utx.skipIfMissingFeatures(['H5MD']) +@skipIfMissingPythonPackage class H5mdTestOrdered(CommonTests): """ @@ -161,6 +168,7 @@ def test_ids(self): @utx.skipIfMissingFeatures(['H5MD']) +@skipIfMissingPythonPackage class H5mdTestUnordered(CommonTests): """ From 31ffa708f7637b8ee8ed0bc9655e12af6d96dab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 27 May 2020 15:19:33 +0200 Subject: [PATCH 2/2] cmake: Remove unused FindPythonModule --- CMakeLists.txt | 1 - cmake/FindPythonModule.cmake | 24 ------------------------ 2 files changed, 25 deletions(-) delete mode 100644 cmake/FindPythonModule.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 74672f7d4f9..beafdddd87e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) include(FeatureSummary) include(GNUInstallDirs) project(ESPResSo) -include(FindPythonModule) include(option_enum) include(option_if_available) if(POLICY CMP0074) diff --git a/cmake/FindPythonModule.cmake b/cmake/FindPythonModule.cmake deleted file mode 100644 index 8d3dee1d77f..00000000000 --- a/cmake/FindPythonModule.cmake +++ /dev/null @@ -1,24 +0,0 @@ -# Check if a Python module is installed -# Found at http://www.cmake.org/pipermail/cmake/2011-January/041666.html -# To use do: find_python_module(PyQt4 REQUIRED) -function(find_python_module module) - string(TOUPPER ${module} module_upper) - if(NOT PY_${module_upper}) - if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED") - set(PY_${module}_FIND_REQUIRED TRUE) - endif() - # A module's location is usually a directory, but for binary modules - # it's a .so file. - execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" - "import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))" - RESULT_VARIABLE _${module}_status - OUTPUT_VARIABLE _${module}_location - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - if(NOT _${module}_status) - set(PY_${module_upper} ${_${module}_location} CACHE STRING - "Location of Python module ${module}") - endif(NOT _${module}_status) - endif(NOT PY_${module_upper}) - find_package_handle_standard_args(PY_${module} FAIL_MESSAGE "The Python module ${module} was not found." REQUIRED_VARS PY_${module_upper}) -endfunction(find_python_module)