Skip to content

Commit

Permalink
Setting up python bindings and updating github actions workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Feb 27, 2021
1 parent 0fcde28 commit eadf500
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 7 deletions.
24 changes: 17 additions & 7 deletions .github/workflows/ContinuousIntegration.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# GitHub workflow to enable continuous integratoin
# GitHub workflow to enable continuous integration
name: Continuous Integration

# This workflow is triggered on pushes and pull requests to the repository.
on:
pull_request:
on:
push:
branches: '**'
pull_request:
branches: 'master'

jobs:
Expand All @@ -18,17 +20,25 @@ jobs:
steps:
- name: which CXX
run: |
which ${{matrix.cxx}}
which ${{matrix.cxx}}
${{matrix.cxx}} --version
- uses: actions/checkout@v2
- name: mkdir bin
run: mkdir bin
run: mkdir bin
- name: cmake
run: cmake -D CMAKE_CXX_COMPILER=`which ${{matrix.cxx}}` -D CMAKE_BUILD_TYPE=${{matrix.build_type}} ..
run: cmake -DPYTHON_EXECUTABLE=$(which python3) -D CMAKE_CXX_COMPILER=`which ${{matrix.cxx}}` -D CMAKE_BUILD_TYPE=${{matrix.build_type}} ..
working-directory: ./bin
- name: make
run: make
run: make -j2
working-directory: ./bin
- name: ctest
run: ctest -j2
working-directory: ./bin
- name: make GNDStk.python
run: make GNDStk.python -j2
working-directory: ./bin
- name: python -m unittest
run: |
cp ../bin/*.so .
python3 -m unittest discover -v -p "Test*"
working-directory: ./python
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ bin*
build
*~
metaconfigure/*.pyc
docs/.build
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ include( cmake/GNDStk_dependencies.cmake )
# Project targets
########################################################################

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# GNDStk : library
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

include_directories( src/ )

add_library( GNDStk INTERFACE )
target_include_directories( GNDStk INTERFACE src/ )
target_link_libraries( GNDStk
Expand All @@ -38,6 +44,21 @@ target_link_libraries( GNDStk
INTERFACE nlohmann_json::nlohmann_json
)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# GNDStk : python bindings
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

include_directories( python/src/ )

pybind11_add_module( GNDStk.python
EXCLUDE_FROM_ALL
python/src/GNDStk.python.cpp
)
target_link_libraries( GNDStk.python PRIVATE GNDStk )
target_compile_options( GNDStk.python PRIVATE "-fPIC" )
target_compile_options( GNDStk.python PRIVATE "-fvisibility=hidden" )
set_target_properties( GNDStk.python PROPERTIES OUTPUT_NAME GNDStk )
set_target_properties( GNDStk.python PROPERTIES COMPILE_DEFINITIONS "PYBIND11" )

#######################################################################
# Top-level Only
Expand Down
6 changes: 6 additions & 0 deletions cmake/GNDStk_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ if(NOT json_POPULATED)
add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

FetchContent_Declare( pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11
GIT_TAG v2.6.1
GIT_SHALLOW TRUE
)


########################################################################
Expand All @@ -52,4 +57,5 @@ FetchContent_MakeAvailable(
Log
pugixml-adapter
json
pybind11
)
29 changes: 29 additions & 0 deletions python/src/GNDStk.python.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// system includes
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

// other includes

// namespace aliases
namespace python = pybind11;

/**
* @brief GNDStk python bindings
*
* The name given here (GNDStk) must be the same as the name
* set on the PROPERTIES OUTPUT_NAME in the CMakeLists.txt file.
*/
PYBIND11_MODULE( GNDStk, module ) {

module.def(

"add",
[] ( int left, int right ) { return left + right; },
python::arg( "left" ), python::arg( "right" ),
"Return the sum of two integers\n\n"
"This function does not throw an exception.\n\n"
"Arguments:\n"
" left the integer on the left\n"
" right the integer on the right"
);
}

0 comments on commit eadf500

Please sign in to comment.