From b5732fd7429765fcca16101a9353c339c011ac6e Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Thu, 21 Mar 2024 10:11:35 +0100 Subject: [PATCH] Collection of fixes --- .github/workflows/CI.yml | 2 +- CMakeLists.txt | 4 ++-- cmake/SerialboxTooling.cmake | 3 +-- cmake/modules/FindPythonModule.cmake | 11 +++++------ src/serialbox-python/setup.py | 11 ++++++----- src/serialbox/core/hash/Hash.h | 1 + src/serialbox/core/hash/SHA256.cpp | 1 + test/serialbox-python/run_python_tests.sh.cmake | 6 +++--- 8 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 34e34f29..b9e06670 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -76,7 +76,7 @@ jobs: mkdir build && cd build cmake .. \ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ - -DPYTHON_EXECUTABLE=`which python3` \ + -DPython3_EXECUTABLE=`which python3` \ -DSERIALBOX_TESTING=ON \ -DSERIALBOX_ENABLE_FORTRAN=${TEST_FORTRAN} \ -DSERIALBOX_TESTING_FORTRAN=${TEST_FORTRAN} \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 648913cb..da0f6878 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,8 +14,8 @@ set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/install" CACHE PATH "CMake install prefix") cmake_policy(SET CMP0048 NEW) -project(Serialbox LANGUAGES C CXX VERSION 2.6.1) cmake_minimum_required(VERSION 3.12.0) +project(Serialbox LANGUAGES C CXX VERSION 2.6.1) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_C_EXTENSIONS OFF) @@ -218,7 +218,7 @@ endif() #---------------------------------------- Python --------------------------------------------------- if(SERIALBOX_ENABLE_PYTHON) - find_package(PythonInterp 3.4) + find_package(Python3 COMPONENTS Interpreter) # Python tests are enabled by default if we can find "nose" and "numpy" set(ENABLE_PYTHON_TESTS OFF) diff --git a/cmake/SerialboxTooling.cmake b/cmake/SerialboxTooling.cmake index 704f8b18..fb9c310b 100644 --- a/cmake/SerialboxTooling.cmake +++ b/cmake/SerialboxTooling.cmake @@ -89,7 +89,7 @@ function(serialbox_run_pp_ser) if(pp_ser_input) add_custom_command(OUTPUT ${pp_ser_output} - COMMAND ${PYTHON_EXECUTABLE} ${SERIALBOX_PPSER} --verbose + COMMAND ${Python3_EXECUTABLE} ${SERIALBOX_PPSER} --verbose --ignore-identical --output-dir=${output_dir} ${pp_ser_input} @@ -97,4 +97,3 @@ function(serialbox_run_pp_ser) COMMENT "Preprocessing for serialization") endif() endfunction(serialbox_run_pp_ser) - diff --git a/cmake/modules/FindPythonModule.cmake b/cmake/modules/FindPythonModule.cmake index 8d8a0b03..0a40de32 100644 --- a/cmake/modules/FindPythonModule.cmake +++ b/cmake/modules/FindPythonModule.cmake @@ -4,7 +4,7 @@ # # find_python_module(PyQt5 REQUIRED) # -# The module makes use of the ${PYTHON_EXECUTABLE} which needs to be set before calling the +# The module makes use of the ${Python3_EXECUTABLE} which needs to be set before calling the # find_python_module function. # # Variables defined by this cmake module: @@ -25,7 +25,7 @@ function(find_python_module module) endif() # A module's location is usually a directory, but for binary modules it's a .so file. - execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" + execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))" RESULT_VARIABLE _${module}_status OUTPUT_VARIABLE _${module}_location @@ -34,7 +34,7 @@ function(find_python_module module) # Set result if(NOT _${module}_status) - message(STATUS "Found Python module \"${module}\" for Python: ${PYTHON_EXECUTABLE}") + message(STATUS "Found Python module \"${module}\" for Python: ${Python3_EXECUTABLE}") set(PY_${module_upper}_PATH ${_${module}_location} CACHE STRING "Location of Python module ${module}") set(PY_${module_upper}_FOUND TRUE @@ -43,11 +43,10 @@ function(find_python_module module) else() set(PY_${module_upper}_FOUND FALSE) if(${module}_FIND_REQUIRED) - message(FATAL_ERROR "Could NOT find module ${module} for python ${PYTHON_EXECUTABLE}") + message(FATAL_ERROR "Could NOT find module ${module} for python ${Python3_EXECUTABLE}") else() - message(STATUS "Could NOT find \"${module}\" for python: ${PYTHON_EXECUTABLE}") + message(STATUS "Could NOT find \"${module}\" for python: ${Python3_EXECUTABLE}") endif() endif() endif(NOT PY_${module_upper}_FOUND) endfunction(find_python_module) - diff --git a/src/serialbox-python/setup.py b/src/serialbox-python/setup.py index 57ca0699..6a5b890f 100644 --- a/src/serialbox-python/setup.py +++ b/src/serialbox-python/setup.py @@ -45,18 +45,17 @@ def build_extension(self, ext): # Can be set with Conda-Build, for example. cmake_generator = os.environ.get("CMAKE_GENERATOR", "") - # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON + # Set Python3_EXECUTABLE instead if you use PYBIND11_FINDPYTHON # EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code # from Python. cmake_args = [ "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}".format(extdir), - "-DPYTHON_EXECUTABLE={}".format(sys.executable), + "-DPython3_EXECUTABLE={}".format(sys.executable), "-DCMAKE_BUILD_TYPE={}".format(cfg), # not used on MSVC, but no harm "-DSERIALBOX_ENABLE_FORTRAN=false", "-DCMAKE_BUILD_RPATH={}".format(origin), "-DSERIALBOX_ENABLE_SDB=false", "-DSERIALBOX_ASYNC_API=false", - ] build_args = [] # Adding CMake arguments set as environment variable @@ -70,6 +69,7 @@ def build_extension(self, ext): ] if sys.platform == "darwin": from distutils import sysconfig + vars = sysconfig.get_config_vars() vars["SO"] = ".dylib" vars["EXT_SUFFIX"] = ".dylib" @@ -89,7 +89,6 @@ def build_extension(self, ext): pass else: - # Single config generators are handled "normally" single_config = any(x in cmake_generator for x in {"NMake", "Ninja"}) @@ -151,7 +150,9 @@ def _get_origin(self): author="Serialbox Developers", packages=find_packages(), install_requires=["numpy"], - ext_modules=[CMakeExtension("libSerialboxC", sourcedir=os.path.join(DIR, "../../"))], + ext_modules=[ + CMakeExtension("libSerialboxC", sourcedir=os.path.join(DIR, "../../")) + ], cmdclass={"build_ext": CMakeBuild}, zip_safe=False, ) diff --git a/src/serialbox/core/hash/Hash.h b/src/serialbox/core/hash/Hash.h index 381a1b8b..d93f2534 100644 --- a/src/serialbox/core/hash/Hash.h +++ b/src/serialbox/core/hash/Hash.h @@ -36,6 +36,7 @@ class Hash { /// /// \return Hex representation as string of the computed hash virtual std::string hash(const void* data, int length) = 0; + virtual ~Hash() = default; }; } // namespace serialbox diff --git a/src/serialbox/core/hash/SHA256.cpp b/src/serialbox/core/hash/SHA256.cpp index cba62f1c..4a5fb075 100644 --- a/src/serialbox/core/hash/SHA256.cpp +++ b/src/serialbox/core/hash/SHA256.cpp @@ -19,6 +19,7 @@ //===------------------------------------------------------------------------------------------===// #include "serialbox/core/hash/SHA256.h" +#include #include #include #include diff --git a/test/serialbox-python/run_python_tests.sh.cmake b/test/serialbox-python/run_python_tests.sh.cmake index 452026cf..0ff3b1aa 100644 --- a/test/serialbox-python/run_python_tests.sh.cmake +++ b/test/serialbox-python/run_python_tests.sh.cmake @@ -23,7 +23,7 @@ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${PROJECT_BINARY_DIR}/src/serialbox-c" # # Check if nose exists # -"${PYTHON_EXECUTABLE}" -c "import nose" +"${Python3_EXECUTABLE}" -c "import nose" if [ "$?" == "1" ]; then echo ">> Python tests require module 'nose'" exit 1 @@ -33,10 +33,10 @@ fi # Run serialbox python tests with nose # cd "${PYTHON_TEST_DIR}/serialbox" -"${PYTHON_EXECUTABLE}" -m "nose" +"${Python3_EXECUTABLE}" -m "nose" # # Run the sdb tests with nose # cd "${PYTHON_TEST_DIR}/sdb/sdbcore" -"${PYTHON_EXECUTABLE}" -m "nose" +"${Python3_EXECUTABLE}" -m "nose"