Skip to content

Commit 4d39802

Browse files
committed
added python bindings for Bundle
1 parent b058789 commit 4d39802

6 files changed

Lines changed: 83 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
66

77
rock_init(lib_config 0.1)
88
rock_standard_layout()
9+
include_directories(src)
10+
11+
add_subdirectory(bindings)

bindings/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
find_package(PkgConfig)
2+
pkg_check_modules(PYTHON python)
3+
if(PYTHON_FOUND)
4+
option(WITH_PYTHON "build python bindings" ON)
5+
else()
6+
option(WITH_PYTHON "build python bindings" OFF)
7+
endif()
8+
9+
if(WITH_PYTHON)
10+
add_subdirectory(python)
11+
endif()

bindings/python/CMakeLists.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
find_package(Boost COMPONENTS python REQUIRED)
2+
execute_process ( COMMAND python -c "import sys; version=sys.version_info[:3]; print('{0}.{1}'.format(*version))" OUTPUT_VARIABLE PYTHON_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
3+
set(PYTHON_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/lib/python${PYTHON_VERSION}/site-packages)
4+
message("Installing Python packages to: ${PYTHION_INSTALL_PATH}")
5+
message("Include dirs of boost: " ${Boost_INCLUDE_DIRS} )
6+
message("Libs of boost: " ${Boost_LIBRARIES} )
7+
8+
link_directories(
9+
${PYTHON_LIBRARY_DIRS}
10+
)
11+
include_directories(${PYTHON_INCLUDE_DIRS})
12+
13+
add_library(bundle SHARED bundle.cpp)
14+
set_target_properties(bundle PROPERTIES PREFIX "")
15+
target_link_libraries(bundle
16+
${Boost_LIBRARIES}
17+
lib_config
18+
${PYTHON_LIBRARIES}
19+
)
20+
21+
add_custom_target(rockpy
22+
COMMAND if(NOT EXISTS ${PYTHON_INSTALL_PATH}/rock/__init__.py)
23+
file(WRITE ${PYTHON_INSTALL_PATH}/rock/__init__.py)
24+
endif()
25+
)
26+
27+
install(TARGETS bundle
28+
DESTINATION ${PYTHON_INSTALL_PATH}/rock)
29+
install(FILES __init__.py
30+
DESTINATION ${PYTHON_INSTALL_PATH}/rock)
31+

bindings/python/__init__.py

Whitespace-only changes.

bindings/python/bundle.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <boost/python.hpp>
2+
#include "Bundle.hpp"
3+
#include <vector>
4+
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
5+
using namespace boost;
6+
namespace py = boost::python;
7+
using namespace libConfig;
8+
9+
10+
template<class T>
11+
py::list std_vector_to_py_list(const std::vector<T>& v)
12+
{
13+
py::object get_iter = py::iterator<std::vector<T> >();
14+
py::object iter = get_iter(v);
15+
py::list l(iter);
16+
return l;
17+
}
18+
19+
BOOST_PYTHON_MODULE(bundle)
20+
{
21+
py::class_<std::vector<std::string> >("string_vector")
22+
.def(py::vector_indexing_suite<std::vector<std::string> >())
23+
;
24+
25+
py::class_<SingleBundle>("SingleBundle");
26+
py::class_<Bundle>("Bundle")
27+
.def("initialize", &Bundle::initialize)
28+
.def("getActiveBundleName", &Bundle::getActiveBundleName,
29+
py::return_value_policy<py::reference_existing_object>())
30+
.def("selectedBundle", &Bundle::selectedBundle,
31+
py::return_value_policy<py::reference_existing_object>())
32+
.def("findFileByName", &Bundle::findFileByName)
33+
.def("findFilesByName", &Bundle::findFilesByName)
34+
.def("findFilesByExtension", &Bundle::findFilesByExtension)
35+
.def("getConfigurationPathsForTaskModel",
36+
&Bundle::getConfigurationPathsForTaskModel);
37+
}

manifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
<depend package="base/types" />
1111
<depend package="yaml-cpp" />
1212
<depend package="typelib" />
13+
<depend package="python" optional="1"/>
1314
</package>

0 commit comments

Comments
 (0)