mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
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:
@@ -44,6 +44,8 @@ if (OPM_ENABLE_PYTHON)
|
|||||||
endif()
|
endif()
|
||||||
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
|
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
|
||||||
set(Python3_LIBRARIES ${PYTHON_LIBRARIES})
|
set(Python3_LIBRARIES ${PYTHON_LIBRARIES})
|
||||||
|
set(Python3_VERSION "${PYTHON_VERSION_STRING}"})
|
||||||
|
set(Python3_VERSION_MINOR ${PYTHON_VERSION_MINOR})
|
||||||
else()
|
else()
|
||||||
# Be backwards compatible.
|
# Be backwards compatible.
|
||||||
if(PYTHON_EXECUTABLE AND NOT Python3_EXECUTABLE)
|
if(PYTHON_EXECUTABLE AND NOT Python3_EXECUTABLE)
|
||||||
@@ -51,7 +53,10 @@ if (OPM_ENABLE_PYTHON)
|
|||||||
endif()
|
endif()
|
||||||
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
|
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
|
||||||
endif()
|
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
|
# Compatibility settings for PythonInterp and PythonLibs
|
||||||
# used e.g. in FindCwrap, pybind11
|
# used e.g. in FindCwrap, pybind11
|
||||||
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
|
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Instead of having the pybind11 extension module, e.g.
|
# Instead of having the pybind11 extension module, e.g.
|
||||||
# simulators.cpython-310-x86_64-linux-gnu.so located
|
# 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.
|
# directory) with the same name and place it there.
|
||||||
# In this way we can do (if needed in the future)
|
# In this way we can do (if needed in the future)
|
||||||
#
|
#
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
# NOTE: we assume that add_subdirectory( pybind11 ) is called from the
|
# Note: If the new find_package(Python3) is used in the top level CMakeLists.txt, the variable
|
||||||
# parent folder's CMakeLists.txt before this CMakeLists.txt is loaded.
|
# ${PYTHON_EXECUTABLE} is set there to ${Python3_EXECUTABLE}
|
||||||
# Therefore, pybind11's CMakeLists.txt has already run
|
|
||||||
# find_package(PYTHON) to define variables like ${PYTHON_EXECUTABLE}
|
|
||||||
#
|
#
|
||||||
# NOTE: The variable ${PYBIND11_SYSTEM} is set in python/CMakeLists.txt
|
# NOTE: The variable ${PYBIND11_SYSTEM} is set in python/CMakeLists.txt
|
||||||
# to the value "SYSTEM" or unset, depending on the current version of Pybind11.
|
# 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
|
PyBlackOilSimulator.cpp
|
||||||
Pybind11Exporter.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} )
|
set_target_properties( simulators PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PYTHON_OPM_SIMULATORS_PACKAGE_PATH} )
|
||||||
|
|
||||||
target_sources(simulators
|
target_sources(simulators
|
||||||
@@ -41,9 +39,6 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(OPM_ENABLE_PYTHON_TESTS)
|
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})
|
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
|
# NOTE: See comment in test_basic.py for the reason why we are
|
||||||
# splitting the python tests into multiple add_test() tests instead
|
# splitting the python tests into multiple add_test() tests instead
|
||||||
@@ -86,6 +81,6 @@ if (OPM_INSTALL_PYTHON)
|
|||||||
CODE "execute_process(
|
CODE "execute_process(
|
||||||
COMMAND ${PYTHON_EXECUTABLE}
|
COMMAND ${PYTHON_EXECUTABLE}
|
||||||
${_opm_common_python_script_dir}/install.py
|
${_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)")
|
${DEST_PREFIX}${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PREFIX} 1)")
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user