Make Python opm package a namespace package

Convert the Python opm package from a regular package to a namespace
package such that opm-simulators and opm-common can contribute to the
package from different filesystem paths. In this way, the two packages
opm.simulators and opm.io (in opm-common) can have a different parent
filesystem path.
This commit is contained in:
Håkon Hægland 2022-06-07 08:29:33 +02:00
parent 19b074805d
commit 8af152dcff
3 changed files with 11 additions and 11 deletions

View File

@ -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})

View File

@ -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)
#

View File

@ -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()