diff --git a/CMakeLists.txt b/CMakeLists.txt index fb029a2cb..1df46e463 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,8 @@ if (OPM_ENABLE_PYTHON) endif() set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE}) set(Python3_LIBRARIES ${PYTHON_LIBRARIES}) + set(Python3_VERSION "${PYTHON_VERSION_STRING}"}) + set(Python3_VERSION_MINOR ${PYTHON_VERSION_MINOR}) else() # Be backwards compatible. if(PYTHON_EXECUTABLE AND NOT Python3_EXECUTABLE) @@ -51,7 +53,10 @@ if (OPM_ENABLE_PYTHON) endif() find_package(Python3 REQUIRED COMPONENTS Interpreter Development) endif() - + if(Python3_VERSION_MINOR LESS 3) + # Python native namespace packages requires python >= 3.3 + message(SEND_ERROR "OPM requires python >= 3.3 but only version ${Python3_VERSION} was found") + endif() # Compatibility settings for PythonInterp and PythonLibs # used e.g. in FindCwrap, pybind11 set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE}) diff --git a/python/opm2/simulators/__init__.py b/python/opm/simulators/__init__.py similarity index 88% rename from python/opm2/simulators/__init__.py rename to python/opm/simulators/__init__.py index a6ca336e6..6e35f2c08 100644 --- a/python/opm2/simulators/__init__.py +++ b/python/opm/simulators/__init__.py @@ -1,6 +1,6 @@ # Instead of having the pybind11 extension module, e.g. # simulators.cpython-310-x86_64-linux-gnu.so located -# directly in the opm2 directory, we create a package (sub +# directly in the opm directory, we create a package (sub # directory) with the same name and place it there. # In this way we can do (if needed in the future) # diff --git a/python/simulators/CMakeLists.txt b/python/simulators/CMakeLists.txt index 1f3521220..ecb1d6a39 100644 --- a/python/simulators/CMakeLists.txt +++ b/python/simulators/CMakeLists.txt @@ -1,7 +1,5 @@ -# NOTE: we assume that add_subdirectory( pybind11 ) is called from the -# parent folder's CMakeLists.txt before this CMakeLists.txt is loaded. -# Therefore, pybind11's CMakeLists.txt has already run -# find_package(PYTHON) to define variables like ${PYTHON_EXECUTABLE} +# Note: If the new find_package(Python3) is used in the top level CMakeLists.txt, the variable +# ${PYTHON_EXECUTABLE} is set there to ${Python3_EXECUTABLE} # # NOTE: The variable ${PYBIND11_SYSTEM} is set in python/CMakeLists.txt # to the value "SYSTEM" or unset, depending on the current version of Pybind11. @@ -14,7 +12,7 @@ pybind11_add_module(simulators ${PYBIND11_SYSTEM} PyBlackOilSimulator.cpp Pybind11Exporter.cpp) -set(PYTHON_OPM_SIMULATORS_PACKAGE_PATH ${PROJECT_BINARY_DIR}/python/opm2/simulators) +set(PYTHON_OPM_SIMULATORS_PACKAGE_PATH ${PROJECT_BINARY_DIR}/python/opm/simulators) set_target_properties( simulators PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PYTHON_OPM_SIMULATORS_PACKAGE_PATH} ) target_sources(simulators @@ -41,9 +39,6 @@ else() endif() if(OPM_ENABLE_PYTHON_TESTS) - if(Python3_EXECUTABLE AND NOT PYTHON_EXECUTABLE) - set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE}) - endif() set(PYTHON_PATH ${PROJECT_BINARY_DIR}/python:${opm-common_DIR}/python:$ENV{PYTHONPATH}) # NOTE: See comment in test_basic.py for the reason why we are # splitting the python tests into multiple add_test() tests instead @@ -86,6 +81,6 @@ if (OPM_INSTALL_PYTHON) CODE "execute_process( COMMAND ${PYTHON_EXECUTABLE} ${_opm_common_python_script_dir}/install.py - ${PROJECT_BINARY_DIR}/python/opm2 + ${PROJECT_BINARY_DIR}/python/opm ${DEST_PREFIX}${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PREFIX} 1)") endif()