Skip to content
Snippets Groups Projects
Verified Commit 0abb1655 authored by Lars Bilke's avatar Lars Bilke
Browse files

[py] Module works.

```
pip install .
pytest
```
parent f223ce6c
No related branches found
No related tags found
No related merge requests found
......@@ -42,4 +42,5 @@ nohup.out
# Python build
/_skbuild
*.egg-info/
/wheelhouse
.ipynb_checkpoints
......@@ -45,31 +45,6 @@ if(OGS_USE_PYTHON)
$<$<BOOL:${BUILD_SHARED_LIBS}>:PRIVATE
OGS_BUILD_SHARED_LIBS>
)
# Create OpenGeoSys python module
# https://pybind11.readthedocs.io/en/stable/compiling.html#building-with-cmake
if(OGS_BUILD_PYTHON_MODULE)
pybind11_add_module(
OpenGeoSys MODULE ogs_python_module.cpp
CommandLineArgumentParser.cpp
)
# lld linker strips out PyInit_OpenGeoSys symbol. Use standard linker.
get_target_property(_link_options OpenGeoSys LINK_OPTIONS)
if(_link_options)
list(REMOVE_ITEM _link_options -fuse-ld=lld)
set_target_properties(
OpenGeoSys PROPERTIES LINK_OPTIONS "${_link_options}"
)
endif()
target_link_libraries(
OpenGeoSys PRIVATE ApplicationsLib BaseLib GitInfoLib tclap
pybind11::pybind11
)
install(TARGETS OpenGeoSys LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
endif()
ogs_add_executable(ogs ogs.cpp CommandLineArgumentParser.cpp)
......@@ -94,28 +69,6 @@ target_link_libraries(
add_test(NAME ogs_no_args COMMAND ogs)
set_tests_properties(ogs_no_args PROPERTIES WILL_FAIL TRUE LABELS "default")
if(OGS_BUILD_PYTHON_MODULE AND NOT (WIN32 AND "${CMAKE_BUILD_TYPE}" STREQUAL
"Release")
)
# TODO: does not work on Windows Release
add_test(
NAME ogs_python_module
COMMAND
${Python_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/ogs_python_module.py
${CMAKE_SOURCE_DIR}/Tests/Data/Parabolic/LiquidFlow/Flux/cube_1e3_calculatesurfaceflux.prj
)
set_tests_properties(
ogs_python_module
PROPERTIES
LABELS
"default"
ENVIRONMENT_MODIFICATION
PYTHONPATH=path_list_append:$<TARGET_FILE_DIR:OpenGeoSys>:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
DISABLED
$<NOT:$<TARGET_EXISTS:LiquidFlow>>
)
endif()
# ---- Installation ----
install(TARGETS ogs RUNTIME DESTINATION bin)
......
#!/usr/bin/env python3
# The OpenGeoSys python library will be created in the lib folder of the build
# directory
## export PYTHONPATH=$PYTHONPATH:your-build_directory-here/lib
import sys
import tempfile
import OpenGeoSys
arguments = ["", sys.argv[1], "-o " + tempfile.mkdtemp()]
print("Python OpenGeoSys.init ...")
OpenGeoSys.initialize(arguments)
print("Python OpenGeoSys.executeSimulation ...")
OpenGeoSys.executeSimulation()
print("Python OpenGeoSys.finalize() ...")
OpenGeoSys.finalize()
print("Python world.")
......@@ -19,3 +19,7 @@ endif() # OGS_BUILD_CLI
if(OGS_USE_INSITU)
add_subdirectory(InSituLib)
endif()
if(OGS_BUILD_PYTHON_MODULE)
add_subdirectory(Python)
endif()
# Create OpenGeoSys python module
# https://pybind11.readthedocs.io/en/stable/compiling.html#building-with-cmake
pybind11_add_module(
_cli MODULE ogs_python_module.cpp ../CLI/CommandLineArgumentParser.cpp
)
# lld linker strips out PyInit_OpenGeoSys symbol. Use standard linker.
get_target_property(_link_options _cli LINK_OPTIONS)
if(_link_options)
list(REMOVE_ITEM _link_options -fuse-ld=lld)
set_target_properties(_cli PROPERTIES LINK_OPTIONS "${_link_options}")
endif()
target_link_libraries(_cli PRIVATE ApplicationsLib BaseLib GitInfoLib tclap)
target_include_directories(_cli PRIVATE ../CLI)
set(_cli_dest ${CMAKE_INSTALL_LIBDIR})
if(SKBUILD)
set(_cli_dest .)
endif()
install(TARGETS _cli LIBRARY DESTINATION ${_cli_dest})
from ._cli import *
......@@ -122,7 +122,7 @@ void finalize()
}
/// python module name is OpenGeoSys
PYBIND11_MODULE(OpenGeoSys, m)
PYBIND11_MODULE(_cli, m)
{
m.doc() = "pybind11 ogs example plugin";
m.def("initialize", &initOGS, "init OGS");
......
import OpenGeoSys
import tempfile
import os
def test_init():
arguments = [
"",
f"{os.path.abspath(os.path.dirname(__file__))}/../Data/Parabolic/LiquidFlow/Flux/cube_1e3_calculatesurfaceflux.prj",
"-o " + tempfile.mkdtemp(),
]
print("Python OpenGeoSys.init ...")
OpenGeoSys.initialize(arguments)
print("Python OpenGeoSys.executeSimulation ...")
OpenGeoSys.executeSimulation()
print("Python OpenGeoSys.finalize() ...")
OpenGeoSys.finalize()
......@@ -6,3 +6,19 @@ requires = [
"ninja; platform_system!='Windows'",
]
build-backend = "setuptools.build_meta"
[tool.pytest.ini_options]
testpaths = ["Tests"]
norecursedirs = ["Tests/Data"]
[tool.cibuildwheel]
archs = "auto64"
build = "cp310-*"
skip = "*musllinux*"
test-extras = "test"
test-command = "pytest {project}/Tests/Python"
build-verbosity = "1"
[tool.cibuildwheel.linux]
manylinux-x86_64-image = "manylinux2014"
manylinux-aarch64-image = "manylinux2014"
......@@ -202,7 +202,7 @@ if(OGS_USE_MPI)
set(HDF5_PREFER_PARALLEL ON)
list(APPEND _hdf5_options "-DHDF5_ENABLE_PARALLEL=ON")
endif()
if(WIN32)
if(WIN32 OR HDF5_USE_STATIC_LIBRARIES)
set(HDF5_USE_STATIC_LIBRARIES ON)
list(APPEND _hdf5_options "-DBUILD_SHARED_LIBS=OFF")
endif()
......
......@@ -2,13 +2,24 @@ from skbuild import setup
from setuptools import find_packages
setup(
name="ogs",
name="OpenGeoSys",
version="6.4.2",
description="OpenGeoSys",
author="OpenGeoSys Community",
license="BSD-3-Clause",
packages=find_packages(where="."),
package_dir={"": "."},
cmake_args=["-DOGS_BUILD_PROCESSES=SteadyStateDiffusion", "-DOGS_BUILD_UTILS=OFF"],
packages=find_packages(where="Applications/Python"),
package_dir={"": "Applications/Python"},
cmake_install_dir="Applications/Python/OpenGeoSys",
extras_require={"test": ["pytest"]},
cmake_args=[
"-DOGS_BUILD_PROCESSES=LiquidFlow",
"-DOGS_BUILD_UTILS=OFF",
"-DHDF5_USE_STATIC_LIBRARIES=ON",
"-DOGS_BUILD_HDF5=ON",
"-DOGS_USE_PYTHON=OFF", # not possible because manylinux does not provide libpythonX.Y.so
"-DOGS_BUILD_PYTHON_MODULE=ON",
"-DOGS_BUILD_TESTING=OFF",
"-DOGS_INSTALL_DEPENDENCIES=OFF", # otherwise auditwheel fails
],
python_requires=">=3.6",
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment