From 25a3007a1eea93ada654e0028e370e1a56f950d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Date: Fri, 25 Nov 2016 15:29:36 +0100 Subject: [PATCH] Move C++ source to python/, trivial bindings --- CMakeLists.txt | 1 - README.md | 3 ++- python/sunbeam/CMakeLists.txt | 6 ++++++ python/sunbeam/__init__.py | 2 ++ python/sunbeam/sunbeam.cpp | 20 ++++++++++++++++++++ python/sunbeam/sunbeam.py | 7 +++++++ src/CMakeLists.txt | 5 ----- src/sunbeam.cpp | 0 tests/parse.py | 4 ++++ 9 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 python/sunbeam/sunbeam.cpp delete mode 100644 src/CMakeLists.txt delete mode 100644 src/sunbeam.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c81b212d..2f98511d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,5 @@ find_package( Boost COMPONENTS python REQUIRED ) list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/pycmake/cmake/Modules) -add_subdirectory( src ) add_subdirectory( python ) add_subdirectory( tests ) diff --git a/README.md b/README.md index e7768fe83..4f983ad92 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ # sunbeam ![build status](https://travis-ci.org/Statoil/sunbeam.svg?branch=master "TravisCI Build Status") # Quick start (WIP) +Assumes you have built (and maybe installed) opm-parser ``` git clone --recursive git@github.com:statoil/sunbeam` cd sunbeam mkdir build cd build -cmake .. +cmake .. -DCMAKE_MODULE_PATH=$OPM_COMMON_ROOT/cmake/Modules make ``` diff --git a/python/sunbeam/CMakeLists.txt b/python/sunbeam/CMakeLists.txt index c4a4cd885..9098d4670 100644 --- a/python/sunbeam/CMakeLists.txt +++ b/python/sunbeam/CMakeLists.txt @@ -1,3 +1,9 @@ +include_directories(SYSTEM ${PYTHON_INCLUDE_DIRS} + ${Boost_INCLUDE_DIR} + ${opm-parser_INCLUDE_DIRS}) +add_library( sunbeam SHARED sunbeam.cpp ) +target_link_libraries( sunbeam ${Boost_LIBRARIES} ${opm-parser_LIBRARIES} ) + set(PYTHON_SOURCES __init__.py sunbeam.py) diff --git a/python/sunbeam/__init__.py b/python/sunbeam/__init__.py index b79a82637..7c00eea4e 100644 --- a/python/sunbeam/__init__.py +++ b/python/sunbeam/__init__.py @@ -1,2 +1,4 @@ +from .sunbeam import parse + __version__ = '0.0.1' __license__ = 'GNU General Public License version 3' diff --git a/python/sunbeam/sunbeam.cpp b/python/sunbeam/sunbeam.cpp new file mode 100644 index 000000000..a8c29c21f --- /dev/null +++ b/python/sunbeam/sunbeam.cpp @@ -0,0 +1,20 @@ +#include + +#include +#include + +namespace py = boost::python; +using namespace Opm; + +BOOST_PYTHON_MODULE(libsunbeam) { + +EclipseState (*parse_file)( const std::string&, const ParseContext& ) = &Parser::parse; +py::def( "parse", parse_file ); + +py::class_< EclipseState >( "EclipseState", py::no_init ) + .add_property( "title", &EclipseState::getTitle ) + ; + +py::class_< ParseContext >( "ParseContext" ) + ; +} diff --git a/python/sunbeam/sunbeam.py b/python/sunbeam/sunbeam.py index e69de29bb..c41a4177f 100644 --- a/python/sunbeam/sunbeam.py +++ b/python/sunbeam/sunbeam.py @@ -0,0 +1,7 @@ +import libsunbeam as lib + +class EclipseState(lib.EclipseState): + pass + +def parse(path): + return lib.parse(path, lib.ParseContext()) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index a29da3420..000000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -include_directories(SYSTEM ${PYTHON_INCLUDE_DIRS} - ${Boost_INCLUDE_DIR} - ${opm-parser_INCLUDE_DIRS}) -add_library( sunbeam SHARED sunbeam.cpp ) -target_link_libraries( sunbeam ${Boost_LIBRARIES} ${opm-parser_LIBRARIES} ) diff --git a/src/sunbeam.cpp b/src/sunbeam.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/parse.py b/tests/parse.py index 59a8f818a..fa471f47d 100644 --- a/tests/parse.py +++ b/tests/parse.py @@ -8,3 +8,7 @@ class TestParse(unittest.TestCase): def parse(self): sunbeam.parse(self.spe3) + + def testParse(self): + spe3 = sunbeam.parse(self.spe3) + self.assertEqual('SPE 3 - CASE 1', spe3.title)