From f264c358e72ff8ee1648cd9224b24ed1c3307cb1 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Fri, 13 Sep 2019 09:22:49 +0200 Subject: [PATCH 1/2] Placed the Python cxx wrapping in namespace python::common --- python/cxx/common.cpp | 34 ++++++++++++++++------------ python/cxx/common.hpp | 6 ++++- python/cxx/connection.cpp | 2 +- python/cxx/deck.cpp | 2 +- python/cxx/deck_keyword.cpp | 2 +- python/cxx/eclipse_3d_properties.cpp | 2 +- python/cxx/eclipse_config.cpp | 2 +- python/cxx/eclipse_grid.cpp | 2 +- python/cxx/eclipse_state.cpp | 2 +- python/cxx/group.cpp | 2 +- python/cxx/group_tree.cpp | 2 +- python/cxx/parsecontext.cpp | 2 +- python/cxx/parser.cpp | 2 +- python/cxx/schedule.cpp | 2 +- python/cxx/table_manager.cpp | 2 +- python/cxx/well.cpp | 2 +- 16 files changed, 38 insertions(+), 30 deletions(-) diff --git a/python/cxx/common.cpp b/python/cxx/common.cpp index 0c1e3ca17..e6ef47ecf 100644 --- a/python/cxx/common.cpp +++ b/python/cxx/common.cpp @@ -2,20 +2,24 @@ #include "common.hpp" -PYBIND11_MODULE(libopmcommon_python, module) { - opmcommon_python::export_ParseContext(module); - opmcommon_python::export_Parser(module); - opmcommon_python::export_Deck(module); - opmcommon_python::export_DeckKeyword(module); - opmcommon_python::export_Schedule(module); - opmcommon_python::export_Well(module); - opmcommon_python::export_Group(module); - opmcommon_python::export_GroupTree(module); - opmcommon_python::export_Connection(module); - opmcommon_python::export_EclipseConfig(module); - opmcommon_python::export_Eclipse3DProperties(module); - opmcommon_python::export_EclipseState(module); - opmcommon_python::export_TableManager(module); - opmcommon_python::export_EclipseGrid(module); + +void python::common::export_all(py::module& module) { + export_ParseContext(module); + export_Parser(module); + export_Deck(module); + export_DeckKeyword(module); + export_Schedule(module); + export_Well(module); + export_Group(module); + export_GroupTree(module); + export_Connection(module); + export_EclipseConfig(module); + export_Eclipse3DProperties(module); + export_EclipseState(module); + export_TableManager(module); + export_EclipseGrid(module); } +PYBIND11_MODULE(libopmcommon_python, module) { + python::common::export_all(module); +} diff --git a/python/cxx/common.hpp b/python/cxx/common.hpp index 62edc7b6d..3223e7994 100644 --- a/python/cxx/common.hpp +++ b/python/cxx/common.hpp @@ -11,8 +11,10 @@ const py::return_value_policy ref_internal = py::return_value_policy::reference_ const py::return_value_policy python_owner = py::return_value_policy::take_ownership; const py::return_value_policy move = py::return_value_policy::move; -namespace opmcommon_python { +namespace python { +namespace common { + void export_all(py::module& module); void export_Connection(py::module& module); void export_Deck(py::module& module); void export_DeckKeyword(py::module& module); @@ -27,6 +29,8 @@ namespace opmcommon_python { void export_Schedule(py::module& module); void export_TableManager(py::module& module); void export_Well(py::module& module); + +} } #endif //SUNBEAM_HPP diff --git a/python/cxx/connection.cpp b/python/cxx/connection.cpp index f84de4335..2d58144fa 100644 --- a/python/cxx/connection.cpp +++ b/python/cxx/connection.cpp @@ -15,7 +15,7 @@ std::string direction( const Connection& c ) { } -void opmcommon_python::export_Connection(py::module& module) { +void python::common::export_Connection(py::module& module) { py::class_< Connection >( module, "Connection") .def_property_readonly("direction", &direction ) diff --git a/python/cxx/deck.cpp b/python/cxx/deck.cpp index 6510cd1ad..2aa049acd 100644 --- a/python/cxx/deck.cpp +++ b/python/cxx/deck.cpp @@ -37,7 +37,7 @@ namespace { } -void opmcommon_python::export_Deck(py::module &module) { +void python::common::export_Deck(py::module &module) { py::class_< Deck >(module, "Deck") .def( "__len__", &size ) diff --git a/python/cxx/deck_keyword.cpp b/python/cxx/deck_keyword.cpp index d5ee85cf6..1931efc4f 100644 --- a/python/cxx/deck_keyword.cpp +++ b/python/cxx/deck_keyword.cpp @@ -56,7 +56,7 @@ struct DeckRecordIterator } -void opmcommon_python::export_DeckKeyword(py::module& module) { +void python::common::export_DeckKeyword(py::module& module) { py::class_< DeckKeyword >( module, "DeckKeyword") .def( "__repr__", &DeckKeyword::name ) .def( "__str__", &str ) diff --git a/python/cxx/eclipse_3d_properties.cpp b/python/cxx/eclipse_3d_properties.cpp index dd9b6ccaa..1bf4158e8 100644 --- a/python/cxx/eclipse_3d_properties.cpp +++ b/python/cxx/eclipse_3d_properties.cpp @@ -35,7 +35,7 @@ namespace { } -void opmcommon_python::export_Eclipse3DProperties(py::module& module) { +void python::common::export_Eclipse3DProperties(py::module& module) { py::class_< Eclipse3DProperties >( module, "Eclipse3DProperties") .def( "getRegions", ®ions ) diff --git a/python/cxx/eclipse_config.cpp b/python/cxx/eclipse_config.cpp index 58b0cbe5a..bdeb764f7 100644 --- a/python/cxx/eclipse_config.cpp +++ b/python/cxx/eclipse_config.cpp @@ -8,7 +8,7 @@ #include "common.hpp" -void opmcommon_python::export_EclipseConfig(py::module& module) +void python::common::export_EclipseConfig(py::module& module) { py::class_< EclipseConfig >( module, "EclipseConfig" ) .def( "init", &EclipseConfig::init, ref_internal) diff --git a/python/cxx/eclipse_grid.cpp b/python/cxx/eclipse_grid.cpp index e310d3eee..5e4aa8c94 100644 --- a/python/cxx/eclipse_grid.cpp +++ b/python/cxx/eclipse_grid.cpp @@ -41,7 +41,7 @@ namespace { } -void opmcommon_python::export_EclipseGrid(py::module& module) { +void python::common::export_EclipseGrid(py::module& module) { py::class_< EclipseGrid >( module, "EclipseGrid") .def( "_getXYZ", &getXYZ ) diff --git a/python/cxx/eclipse_state.cpp b/python/cxx/eclipse_state.cpp index 47105109c..7f87029cc 100644 --- a/python/cxx/eclipse_state.cpp +++ b/python/cxx/eclipse_state.cpp @@ -85,7 +85,7 @@ namespace { } -void opmcommon_python::export_EclipseState(py::module& module) { +void python::common::export_EclipseState(py::module& module) { py::class_< EclipseState >( module, "EclipseState" ) .def_property_readonly( "title", &EclipseState::getTitle ) diff --git a/python/cxx/group.cpp b/python/cxx/group.cpp index 2d9c22146..e52f8f25d 100644 --- a/python/cxx/group.cpp +++ b/python/cxx/group.cpp @@ -14,7 +14,7 @@ namespace { } } -void opmcommon_python::export_Group(py::module& module) { +void python::common::export_Group(py::module& module) { py::class_< Group2 >( module, "Group") .def_property_readonly( "name", &Group2::name) diff --git a/python/cxx/group_tree.cpp b/python/cxx/group_tree.cpp index b9331b298..d58dad488 100644 --- a/python/cxx/group_tree.cpp +++ b/python/cxx/group_tree.cpp @@ -15,7 +15,7 @@ namespace { } } -void opmcommon_python::export_GroupTree(py::module& module) { +void python::common::export_GroupTree(py::module& module) { py::class_(module, "GroupTree") diff --git a/python/cxx/parsecontext.cpp b/python/cxx/parsecontext.cpp index 88a174ad0..78300ab5b 100644 --- a/python/cxx/parsecontext.cpp +++ b/python/cxx/parsecontext.cpp @@ -12,7 +12,7 @@ namespace { } -void opmcommon_python::export_ParseContext(py::module& module) { +void python::common::export_ParseContext(py::module& module) { py::class_< ParseContext >(module, "ParseContext" ) .def(py::init<>()) diff --git a/python/cxx/parser.cpp b/python/cxx/parser.cpp index 98017f685..502a46773 100644 --- a/python/cxx/parser.cpp +++ b/python/cxx/parser.cpp @@ -51,7 +51,7 @@ namespace { } -void opmcommon_python::export_Parser(py::module& module) { +void python::common::export_Parser(py::module& module) { module.def( "parse", parse_file ); module.def( "parse_string", parse_string); diff --git a/python/cxx/schedule.cpp b/python/cxx/schedule.cpp index e3109a45d..55cc785e8 100644 --- a/python/cxx/schedule.cpp +++ b/python/cxx/schedule.cpp @@ -90,7 +90,7 @@ namespace { } -void opmcommon_python::export_Schedule(py::module& module) { +void python::common::export_Schedule(py::module& module) { py::class_< Schedule >( module, "Schedule") .def("_groups", &get_groups ) diff --git a/python/cxx/table_manager.cpp b/python/cxx/table_manager.cpp index e18b1465a..f378ec4f2 100644 --- a/python/cxx/table_manager.cpp +++ b/python/cxx/table_manager.cpp @@ -16,7 +16,7 @@ namespace { } -void opmcommon_python::export_TableManager(py::module& module) { +void python::common::export_TableManager(py::module& module) { py::class_< TableManager >( module, "Tables") .def( "__contains__", &TableManager::hasTables ) diff --git a/python/cxx/well.cpp b/python/cxx/well.cpp index 69ee10443..b6f7750ee 100644 --- a/python/cxx/well.cpp +++ b/python/cxx/well.cpp @@ -33,7 +33,7 @@ namespace { } -void opmcommon_python::export_Well(py::module& module) { +void python::common::export_Well(py::module& module) { py::class_< Well2 >( module, "Well") .def_property_readonly( "name", &Well2::name ) From d2ff536cf3693068b1973efa6dce6268bf0319ab Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Fri, 13 Sep 2019 09:40:13 +0200 Subject: [PATCH 2/2] Renamed python/cxx/common -> python/cxx/export --- CMakeLists.txt | 4 +-- python/cxx/common.hpp | 36 --------------------------- python/cxx/connection.cpp | 2 +- python/cxx/deck.cpp | 2 +- python/cxx/deck_keyword.cpp | 2 +- python/cxx/eclipse_3d_properties.cpp | 2 +- python/cxx/eclipse_config.cpp | 2 +- python/cxx/eclipse_grid.cpp | 2 +- python/cxx/eclipse_state.cpp | 2 +- python/cxx/{common.cpp => export.cpp} | 4 +-- python/cxx/export.hpp | 33 ++++++++++++++++++++++++ python/cxx/group.cpp | 2 +- python/cxx/group_tree.cpp | 2 +- python/cxx/parsecontext.cpp | 2 +- python/cxx/parser.cpp | 2 +- python/cxx/schedule.cpp | 2 +- python/cxx/table_manager.cpp | 2 +- python/cxx/well.cpp | 2 +- python/setup.py | 2 +- 19 files changed, 52 insertions(+), 55 deletions(-) delete mode 100644 python/cxx/common.hpp rename python/cxx/{common.cpp => export.cpp} (96%) create mode 100644 python/cxx/export.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8db98953a..d4aa3d916 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -249,8 +249,8 @@ if (OPM_ENABLE_PYTHON) python/cxx/parsecontext.cpp python/cxx/parser.cpp python/cxx/schedule.cpp - python/cxx/common.cpp - python/cxx/common.hpp + python/cxx/export.cpp + python/cxx/export.hpp python/cxx/common_state.cpp python/cxx/common_state.hpp python/cxx/table_manager.cpp diff --git a/python/cxx/common.hpp b/python/cxx/common.hpp deleted file mode 100644 index 3223e7994..000000000 --- a/python/cxx/common.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef SUNBEAM_HPP -#define SUNBEAM_HPP - -#include - -namespace Opm { } -namespace py = pybind11; - -using namespace Opm; -const py::return_value_policy ref_internal = py::return_value_policy::reference_internal; -const py::return_value_policy python_owner = py::return_value_policy::take_ownership; -const py::return_value_policy move = py::return_value_policy::move; - -namespace python { -namespace common { - - void export_all(py::module& module); - void export_Connection(py::module& module); - void export_Deck(py::module& module); - void export_DeckKeyword(py::module& module); - void export_Eclipse3DProperties(py::module& module); - void export_EclipseConfig(py::module& module); - void export_EclipseGrid(py::module& module); - void export_EclipseState(py::module& module); - void export_Group(py::module& module); - void export_GroupTree(py::module& module); - void export_ParseContext(py::module& module); - void export_Parser(py::module& module); - void export_Schedule(py::module& module); - void export_TableManager(py::module& module); - void export_Well(py::module& module); - -} -} - -#endif //SUNBEAM_HPP diff --git a/python/cxx/connection.cpp b/python/cxx/connection.cpp index 2d58144fa..d187a8ca9 100644 --- a/python/cxx/connection.cpp +++ b/python/cxx/connection.cpp @@ -1,6 +1,6 @@ #include -#include "common.hpp" +#include "export.hpp" namespace { diff --git a/python/cxx/deck.cpp b/python/cxx/deck.cpp index 2aa049acd..27c0dc0ca 100644 --- a/python/cxx/deck.cpp +++ b/python/cxx/deck.cpp @@ -2,7 +2,7 @@ #include #include "converters.hpp" -#include "common.hpp" +#include "export.hpp" namespace { diff --git a/python/cxx/deck_keyword.cpp b/python/cxx/deck_keyword.cpp index 1931efc4f..2761ddc4a 100644 --- a/python/cxx/deck_keyword.cpp +++ b/python/cxx/deck_keyword.cpp @@ -5,7 +5,7 @@ #include #include -#include "common.hpp" +#include "export.hpp" #include "converters.hpp" diff --git a/python/cxx/eclipse_3d_properties.cpp b/python/cxx/eclipse_3d_properties.cpp index 1bf4158e8..9ce1a77ca 100644 --- a/python/cxx/eclipse_3d_properties.cpp +++ b/python/cxx/eclipse_3d_properties.cpp @@ -1,7 +1,7 @@ #include #include -#include "common.hpp" +#include "export.hpp" #include "converters.hpp" namespace { diff --git a/python/cxx/eclipse_config.cpp b/python/cxx/eclipse_config.cpp index bdeb764f7..52f27706b 100644 --- a/python/cxx/eclipse_config.cpp +++ b/python/cxx/eclipse_config.cpp @@ -5,7 +5,7 @@ #include #include -#include "common.hpp" +#include "export.hpp" void python::common::export_EclipseConfig(py::module& module) diff --git a/python/cxx/eclipse_grid.cpp b/python/cxx/eclipse_grid.cpp index 5e4aa8c94..7531b80a2 100644 --- a/python/cxx/eclipse_grid.cpp +++ b/python/cxx/eclipse_grid.cpp @@ -4,7 +4,7 @@ #include #include -#include "common.hpp" +#include "export.hpp" namespace { diff --git a/python/cxx/eclipse_state.cpp b/python/cxx/eclipse_state.cpp index 7f87029cc..0d0315d09 100644 --- a/python/cxx/eclipse_state.cpp +++ b/python/cxx/eclipse_state.cpp @@ -1,7 +1,7 @@ #include #include -#include "common.hpp" +#include "export.hpp" namespace { diff --git a/python/cxx/common.cpp b/python/cxx/export.cpp similarity index 96% rename from python/cxx/common.cpp rename to python/cxx/export.cpp index e6ef47ecf..5e3c8e0e6 100644 --- a/python/cxx/common.cpp +++ b/python/cxx/export.cpp @@ -1,6 +1,5 @@ #include -#include "common.hpp" - +#include "export.hpp" void python::common::export_all(py::module& module) { @@ -20,6 +19,7 @@ void python::common::export_all(py::module& module) { export_EclipseGrid(module); } + PYBIND11_MODULE(libopmcommon_python, module) { python::common::export_all(module); } diff --git a/python/cxx/export.hpp b/python/cxx/export.hpp new file mode 100644 index 000000000..3f1bb99a0 --- /dev/null +++ b/python/cxx/export.hpp @@ -0,0 +1,33 @@ +#ifndef SUNBEAM_HPP +#define SUNBEAM_HPP + +#include + +namespace Opm {} + +namespace py = pybind11; + +using namespace Opm; +const py::return_value_policy ref_internal = py::return_value_policy::reference_internal; +const py::return_value_policy python_owner = py::return_value_policy::take_ownership; +const py::return_value_policy move = py::return_value_policy::move; + +namespace python::common { +void export_all(py::module& module); +void export_Connection(py::module& module); +void export_Deck(py::module& module); +void export_DeckKeyword(py::module& module); +void export_Eclipse3DProperties(py::module& module); +void export_EclipseConfig(py::module& module); +void export_EclipseGrid(py::module& module); +void export_EclipseState(py::module& module); +void export_Group(py::module& module); +void export_GroupTree(py::module& module); +void export_ParseContext(py::module& module); +void export_Parser(py::module& module); +void export_Schedule(py::module& module); +void export_TableManager(py::module& module); +void export_Well(py::module& module); +} + +#endif //SUNBEAM_HPP diff --git a/python/cxx/group.cpp b/python/cxx/group.cpp index e52f8f25d..1ca02f9a6 100644 --- a/python/cxx/group.cpp +++ b/python/cxx/group.cpp @@ -1,6 +1,6 @@ #include #include -#include "common.hpp" +#include "export.hpp" namespace { diff --git a/python/cxx/group_tree.cpp b/python/cxx/group_tree.cpp index d58dad488..d14f06382 100644 --- a/python/cxx/group_tree.cpp +++ b/python/cxx/group_tree.cpp @@ -1,7 +1,7 @@ #include #include -#include "common.hpp" +#include "export.hpp" #include "converters.hpp" namespace { diff --git a/python/cxx/parsecontext.cpp b/python/cxx/parsecontext.cpp index 78300ab5b..1cb14de28 100644 --- a/python/cxx/parsecontext.cpp +++ b/python/cxx/parsecontext.cpp @@ -3,7 +3,7 @@ #include #include "common_state.hpp" -#include "common.hpp" +#include "export.hpp" namespace { diff --git a/python/cxx/parser.cpp b/python/cxx/parser.cpp index 502a46773..c89dac327 100644 --- a/python/cxx/parser.cpp +++ b/python/cxx/parser.cpp @@ -8,7 +8,7 @@ #include #include "common_state.hpp" -#include "common.hpp" +#include "export.hpp" namespace { diff --git a/python/cxx/schedule.cpp b/python/cxx/schedule.cpp index 55cc785e8..6d31fe369 100644 --- a/python/cxx/schedule.cpp +++ b/python/cxx/schedule.cpp @@ -4,7 +4,7 @@ #include #include -#include "common.hpp" +#include "export.hpp" namespace { diff --git a/python/cxx/table_manager.cpp b/python/cxx/table_manager.cpp index f378ec4f2..363c57f34 100644 --- a/python/cxx/table_manager.cpp +++ b/python/cxx/table_manager.cpp @@ -1,6 +1,6 @@ #include -#include "common.hpp" +#include "export.hpp" namespace { diff --git a/python/cxx/well.cpp b/python/cxx/well.cpp index b6f7750ee..a211dfcef 100644 --- a/python/cxx/well.cpp +++ b/python/cxx/well.cpp @@ -1,6 +1,6 @@ #include #include -#include "common.hpp" +#include "export.hpp" namespace { diff --git a/python/setup.py b/python/setup.py index 3d8eb68a1..8b18e2d73 100644 --- a/python/setup.py +++ b/python/setup.py @@ -65,7 +65,7 @@ ext_modules = [ 'cxx/common_state.cpp', 'cxx/table_manager.cpp', 'cxx/well.cpp', - 'cxx/common.cpp' + 'cxx/export.cpp' ], libraries=['opmcommon', 'boost_filesystem', 'boost_regex', 'ecl'], language='c++',