Skip to content

Commit

Permalink
Squashed 'wrap/' changes from aae9b4605..13a2f66c4
Browse files Browse the repository at this point in the history
13a2f66c4 Merge pull request #46 from borglab/feature/new-shared-pointer
3c7d85865 updated docs
6d7897088 use @ for raw pointer, go back to * for shared pointer
1d6194c57 updated matlab wrapper to handle both raw and shared pointers
1448f6924 fix some failing tests
2ab1dae32 Merge branch 'master' into feature/new-shared-pointer
96f8a56bd Merge pull request #47 from borglab/fix/ci
6003203f3 run CI only for pull requests
a8f29ead1 fix the python version yml key
fcae17227 check if directory exists when testing
f592f08c9 explicit pip3 so that we don't use Python2
d49c2f3c2 correct call for pip
dfe360526 fix the CI
149b7c523 docs for templated functions
f2189acc6 support typedefing for templated functions
965458a2b added test for templated functions
eaff6e6ab made is_const common for all types
3d9c70b32 added tests and cleaned up a bit
010b89626 support for simple pointers on basis types
6b98fd80c new syntax for shared_ptr
ff7ad0b78 support for templated functions
a1a443c8d Merge pull request #43 from borglab/fix/cmake-and-matlab
2f3a055e4 remove accidentally committed file
770d055e2 set proper paths for cmake and eschew relative paths
773d01ae1 fix bug in matlab wrapper
721ef740f Merge pull request #41 from borglab/feature/type-hints
67aac9758 minor refactor of CI yml
e6a63ae0c fix all mypy issues
a3aaa3e7c remove a lot of linter issues from matlab_wrapper
a96db522f static typing for interface_parser

git-subtree-dir: wrap
git-subtree-split: 13a2f66c42f08c5e393e2eff0ebdd83c46254fb6
  • Loading branch information
varunagrawal committed Mar 23, 2021
1 parent a30574f commit 4f16cd2
Show file tree
Hide file tree
Showing 18 changed files with 1,278 additions and 834 deletions.
52 changes: 0 additions & 52 deletions .github/workflows/ci.yml

This file was deleted.

37 changes: 37 additions & 0 deletions .github/workflows/linux-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Wrap CI for Linux

on: [pull_request]

jobs:
build:
name: Tests for 🐍 ${{ matrix.python-version }}
runs-on: ubuntu-18.04

strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Dependencies
run: |
sudo apt-get -y update
sudo apt install cmake build-essential pkg-config libpython-dev python-numpy libboost-all-dev
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Python Dependencies
run: |
sudo pip3 install -r requirements.txt
- name: Build and Test
run: |
cd tests
# Use Pytest to run all the tests.
pytest
36 changes: 36 additions & 0 deletions .github/workflows/macos-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Wrap CI for macOS

on: [pull_request]

jobs:
build:
name: Tests for 🐍 ${{ matrix.python-version }}
runs-on: macos-10.15

strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Dependencies
run: |
brew install cmake ninja boost
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Python Dependencies
run: |
pip3 install -r requirements.txt
- name: Build and Test
run: |
cd tests
# Use Pytest to run all the tests.
pytest
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ include(GNUInstallDirs)

# Install the gtwrap python package as a directory so it can be found by CMake
# for wrapping.
install(DIRECTORY gtwrap DESTINATION "${CMAKE_INSTALL_DATADIR}/gtwrap")
install(DIRECTORY gtwrap DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/gtwrap")

# Install wrapping scripts as binaries to `CMAKE_INSTALL_PREFIX/bin` so they can
# be invoked for wrapping. We use DESTINATION (instead of TYPE) so we can
# support older CMake versions.
install(PROGRAMS scripts/pybind_wrap.py scripts/matlab_wrap.py
DESTINATION ${CMAKE_INSTALL_BINDIR})
DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})

# Install pybind11 directory to `CMAKE_INSTALL_PREFIX/lib/gtwrap/pybind11` This
# will allow the gtwrapConfig.cmake file to load it later.
install(DIRECTORY pybind11 DESTINATION "${CMAKE_INSTALL_LIBDIR}/gtwrap")
install(DIRECTORY pybind11 DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/gtwrap")

# Install the matlab.h file to `CMAKE_INSTALL_PREFIX/lib/gtwrap/matlab.h`.
install(FILES matlab.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/gtwrap")
install(FILES matlab.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/gtwrap")
17 changes: 10 additions & 7 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ The python wrapper supports keyword arguments for functions/methods. Hence, the
- Class variables are read-write so they can be updated directly in Python.

- Pointer types
- To declare a pointer type (including shared pointers), simply add an asterisk (i.e. `*`) to the class name.
- E.g. `gtsam::noiseModel::Base*` to define the wrapping for the `Base` noise model shared pointer.
- To declare a simple/raw pointer, simply add an `@` to the class name, e.g.`Pose3@`.
- To declare a shared pointer (e.g. `gtsam::noiseModel::Base::shared_ptr`), use an asterisk (i.e. `*`). E.g. `gtsam::noiseModel::Base*` to define the wrapping for the `Base` noise model shared pointer.

- Comments can use either C++ or C style, with multiple lines.

Expand All @@ -76,9 +76,13 @@ The python wrapper supports keyword arguments for functions/methods. Hence, the
- Functions specified outside of a class are **global**.
- Can be overloaded with different arguments.
- Can have multiple functions of the same name in different namespaces.
- Functions can be templated and have multiple template arguments, e.g.
```cpp
template<T, >
```

- Using classes defined in other modules
- If you are using a class `OtherClass` not wrapped in an interface file, add `class OtherClass;` as a forward declaration to avoid a dependency error.
- If you are using a class `OtherClass` not wrapped in an interface file, add `class OtherClass;` as a forward declaration to avoid a dependency error. `OtherClass` should be in the same project.

- Virtual inheritance
- Specify fully-qualified base classes, i.e. `virtual class Derived : ns::Base {` where `ns` is the namespace.
Expand Down Expand Up @@ -140,9 +144,9 @@ The python wrapper supports keyword arguments for functions/methods. Hence, the

- Forward declarations and class definitions for **Pybind**:
- Need to specify the base class (both this forward class and base class are declared in an external Pybind header)
This is so that Pybind can generate proper inheritance.
- This is so that Pybind can generate proper inheritance.

Example when wrapping a gtsam-based project:
- Example for when wrapping a gtsam-based project:

```cpp
// forward declarations
Expand All @@ -153,8 +157,7 @@ The python wrapper supports keyword arguments for functions/methods. Hence, the
virtual class MyFactor : gtsam::NoiseModelFactor {...};
```

- **DO NOT** re-define an overriden function already declared in the external (forward-declared) base class
- This will cause an ambiguity problem in Pybind header file.
- **DO NOT** re-define an overriden function already declared in the external (forward-declared) base class. This will cause an ambiguity problem in the Pybind header file.


### TODO
Expand Down
21 changes: 11 additions & 10 deletions cmake/gtwrapConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# This config file modifies CMAKE_MODULE_PATH so that the wrap cmake files may
# be included This file also allows the use of `find_package(gtwrap)` in CMake.

# Standard includes
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(CMakeDependentOption)

set(GTWRAP_DIR "${CMAKE_CURRENT_LIST_DIR}")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")

if(WIN32 AND NOT CYGWIN)
set(GTWRAP_CMAKE_DIR "${GTWRAP_DIR}")
set(GTWRAP_SCRIPT_DIR ${GTWRAP_CMAKE_DIR}/../../../bin)
set(GTWRAP_PYTHON_PACKAGE_DIR ${GTWRAP_CMAKE_DIR}/../../../share/gtwrap)
set(GTWRAP_SCRIPT_DIR ${CMAKE_INSTALL_FULL_BINDIR})
set(GTWRAP_PYTHON_PACKAGE_DIR ${CMAKE_INSTALL_FULL_LIBDIR}/gtwrap)
else()
set(GTWRAP_CMAKE_DIR "${GTWRAP_DIR}")
set(GTWRAP_SCRIPT_DIR ${GTWRAP_CMAKE_DIR}/../../../bin)
set(GTWRAP_PYTHON_PACKAGE_DIR ${GTWRAP_CMAKE_DIR}/../../../share/gtwrap)
set(GTWRAP_SCRIPT_DIR ${CMAKE_INSTALL_FULL_BINDIR})
set(GTWRAP_PYTHON_PACKAGE_DIR ${CMAKE_INSTALL_FULL_LIBDIR}/gtwrap)
endif()

# Standard includes
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(CMakeDependentOption)

# Load all the CMake scripts from the standard location
include(${GTWRAP_CMAKE_DIR}/PybindWrap.cmake)
include(${GTWRAP_CMAKE_DIR}/GtwrapUtils.cmake)
Expand All @@ -28,4 +29,4 @@ set(PYBIND_WRAP_SCRIPT "${GTWRAP_SCRIPT_DIR}/pybind_wrap.py")
set(MATLAB_WRAP_SCRIPT "${GTWRAP_SCRIPT_DIR}/matlab_wrap.py")

# Load the pybind11 code from the library installation path
add_subdirectory(${GTWRAP_CMAKE_DIR}/../../gtwrap/pybind11 pybind11)
add_subdirectory(${CMAKE_INSTALL_FULL_LIBDIR}/gtwrap/pybind11 pybind11)
Loading

0 comments on commit 4f16cd2

Please sign in to comment.