Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Matlab GHA workflow (with a struct-definition addition to the basic example) #164

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
51 changes: 51 additions & 0 deletions .github/workflows/matlab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: matlab

defaults:
run:
shell: bash

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]



jobs:
matlab:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- uses: actions/setup-python@v1
with:
python-version: 3.8

- run: |
echo "CC=gcc-9" >> $GITHUB_ENV
echo "CXX=g++-9" >> $GITHUB_ENV
VERBOSE=1 pip install --verbose -e .

- run: |
echo "m = py.importlib.import_module('cmake_example')" > test.m
echo "AStruct = m.AStruct" >> test.m
echo "AStruct()" >> test.m
cat test.m

- run: python -c "import cmake_example as m; m.AStruct()"

#- run: |
# echo "pybind11_type=type" > pybind11_builtins.py
# echo "PYTHONPATH=." >> $GITHUB_ENV

- uses: matlab-actions/setup-matlab@v0
with:
release: R2022a

- uses: matlab-actions/run-command@v0
with:
command: test
14 changes: 14 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ int add(int i, int j) {
return i + j;
}

struct AStruct {
AStruct() {
}
};
struct BStruct {
BStruct(AStruct &a) {
}
};

namespace py = pybind11;

PYBIND11_MODULE(cmake_example, m) {
Expand Down Expand Up @@ -35,6 +44,11 @@ PYBIND11_MODULE(cmake_example, m) {
Some other explanation about the subtract function.
)pbdoc");

py::class_<AStruct>(m, "AStruct", py::metaclass((PyObject *) &PyType_Type)).def(py::init<>());
py::class_<BStruct>(m, "BStruct", py::metaclass((PyObject *) &PyType_Type)).def(py::init<AStruct&>());

m.def("fun", [](AStruct &a) { return 44; }, "doc", py::arg("a") );

#ifdef VERSION_INFO
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
#else
Expand Down
5 changes: 5 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ def test_main():
assert m.__version__ == "0.0.1"
assert m.add(1, 2) == 3
assert m.subtract(1, 2) == -1

a = m.AStruct()
assert a is not None
m.fun(a)
b = m.BStruct(a)
Loading