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

[py] Renamed wheels package to ogs and coupling module to ogs.simulator.

parent c925801e
No related branches found
No related tags found
No related merge requests found
# 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 CMakeInfoLib GitInfoLib tclap)
target_include_directories(_cli PRIVATE ../CLI)
install(TARGETS _cli LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
add_subdirectory(ogs.simulator)
# Create OpenGeoSys python module
# https://pybind11.readthedocs.io/en/stable/compiling.html#building-with-cmake
pybind11_add_module(
simulator MODULE ogs_python_module.cpp
../../CLI/CommandLineArgumentParser.cpp
)
# lld linker strips out PyInit_OpenGeoSys symbol. Use standard linker.
get_target_property(_link_options simulator LINK_OPTIONS)
if(_link_options)
list(REMOVE_ITEM _link_options -fuse-ld=lld)
set_target_properties(simulator PROPERTIES LINK_OPTIONS "${_link_options}")
endif()
target_link_libraries(
simulator PRIVATE ApplicationsLib BaseLib CMakeInfoLib GitInfoLib tclap
)
target_include_directories(simulator PRIVATE ../../CLI)
# Install into root dir (in Python module, enables 'import ogs.simulator')
install(TARGETS simulator LIBRARY DESTINATION .)
......@@ -122,8 +122,9 @@ void finalize()
}
/// python module name is OpenGeoSys
PYBIND11_MODULE(_cli, m)
PYBIND11_MODULE(simulator, m)
{
m.attr("__name__") = "ogs.simulator";
m.doc() = "pybind11 ogs example plugin";
m.def("initialize", &initOGS, "init OGS");
m.def("currentTime", &currentTime, "get current OGS time");
......
......@@ -69,23 +69,12 @@ binaries_list = [
if "PEP517_BUILD_BACKEND" not in os.environ:
if platform.system() == "Windows":
os.add_dll_directory(os.path.join(os.path.dirname(__file__), "bin"))
from .lib._cli import *
else:
try:
from .lib64._cli import *
except ImportError:
try:
from .lib._cli import *
except ImportError:
print("ERROR: could not import OpenGeoSys Python module!")
OGS_BIN_DIR = os.path.join(os.path.join(os.path.dirname(__file__), "bin"))
def _program(name, args):
return subprocess.call([os.path.join(OGS_BIN_DIR, name)] + args)
FUNC_TEMPLATE = """def {0}(): raise SystemExit(_program("{0}", sys.argv[1:]))"""
for f in binaries_list:
exec(FUNC_TEMPLATE.format(f))
......@@ -3,29 +3,13 @@ import os
import pytest
import OpenGeoSys
def test_module():
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()
import ogs
from . import push_argv
def _run(program, args):
func = getattr(OpenGeoSys, program)
func = getattr(ogs, program)
args = ["%s.py" % program] + args
with push_argv(args), pytest.raises(SystemExit) as excinfo:
func()
......@@ -34,6 +18,6 @@ def _run(program, args):
def test_binaries():
ignore_list = ["moveMeshNodes", "mpmetis", "tetgen"] # have no --version cli flag
for f in OpenGeoSys.binaries_list:
for f in ogs.binaries_list:
if f not in ignore_list:
_run(f, ["--version"])
import tempfile
import os
import pytest
import ogs.simulator as sim
def test_simulator():
arguments = [
"",
f"{os.path.abspath(os.path.dirname(__file__))}/../Data/Parabolic/LiquidFlow/Flux/cube_1e3_calculatesurfaceflux.prj",
"-o " + tempfile.mkdtemp(),
]
print("Python OpenGeoSys.init ...")
sim.initialize(arguments)
print("Python OpenGeoSys.executeSimulation ...")
sim.executeSimulation()
print("Python OpenGeoSys.finalize() ...")
sim.finalize()
......@@ -15,13 +15,12 @@ norecursedirs = ["Tests/Data"]
[tool.cibuildwheel]
archs = "auto64"
build = "cp3*"
skip = ["*musllinux*"]
test-extras = "test"
test-command = "pytest {project}/Tests/Python"
# test-command = ""
build-verbosity = "1"
[tool.cibuildwheel.linux]
skip = ["*musllinux*", "cp36-*"]
manylinux-x86_64-image = "manylinux2014"
manylinux-aarch64-image = "manylinux2014"
environment-pass = ["OGS_VERSION"]
......
......@@ -40,8 +40,12 @@ endif()
file(RELATIVE_PATH relDir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
)
list(APPEND CMAKE_INSTALL_RPATH ${BASEPOINT} ${BASEPOINT}/${relDir})
list(APPEND CMAKE_BUILD_RPATH ${BASEPOINT} ${BASEPOINT}/${relDir})
list(APPEND CMAKE_INSTALL_RPATH ${BASEPOINT} ${BASEPOINT}/${relDir}
${BASEPOINT}/${CMAKE_INSTALL_LIBDIR} # Python modules
)
list(APPEND CMAKE_BUILD_RPATH ${BASEPOINT} ${BASEPOINT}/${relDir}
${BASEPOINT}/${CMAKE_INSTALL_LIBDIR} # Python modules
)
# Some external dependencies always use lib instead of lib64, Fix for
# lib64-based systems, e.g. OpenSUSE:
......
......@@ -2,6 +2,7 @@ from skbuild import setup
from setuptools import find_packages
import os
import platform
import re
import subprocess
import sys
......@@ -12,8 +13,11 @@ def get_version():
if "OGS_VERSION" in os.environ:
git_version = os.environ["OGS_VERSION"]
else:
git_describe_cmd = ["git describe --tags"]
if platform.system() == "Windows":
git_describe_cmd = ["git", "describe", "--tags"]
git_version = subprocess.run(
["git", "describe", "--tags"],
git_describe_cmd,
capture_output=True,
text=True,
shell=True,
......@@ -33,28 +37,27 @@ def get_version():
sys.path.append(os.path.join("Applications", "Python"))
from OpenGeoSys import binaries_list
from ogs import binaries_list
console_scripts = []
for b in binaries_list:
console_scripts.append(f"{b}=OpenGeoSys:{b}")
console_scripts.append(f"{b}=ogs:{b}")
import platform
cmake_preset = "wheel"
if platform.system() == "Windows":
cmake_preset += "-win"
setup(
name="OpenGeoSys",
name="ogs",
version=get_version(),
description="OpenGeoSys",
description="OpenGeoSys Python Module",
author="OpenGeoSys Community",
license="BSD-3-Clause",
packages=find_packages(where="Applications/Python"),
package_dir={"": "Applications/Python"},
cmake_install_dir="Applications/Python/OpenGeoSys",
cmake_install_dir="Applications/Python/ogs",
extras_require={"test": ["pytest"]},
cmake_args=[f"--preset {cmake_preset}", "-B ."],
python_requires=">=3.6",
python_requires=">=3.7",
entry_points={"console_scripts": console_scripts},
)
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