Skip to content

Commit 91adf2e

Browse files
authored
Test agains older pybind11 (#175)
1 parent 2f969a1 commit 91adf2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+990
-39
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@ jobs:
4343
strategy:
4444
fail-fast: false
4545
matrix:
46-
pybind11-branch: [ "master" ]
46+
pybind11-branch:
47+
- "master"
4748
python:
4849
- "3.12"
4950
- "3.11"
5051
- "3.10"
5152
- "3.9"
5253
- "3.8"
5354
- "3.7"
55+
include:
56+
- pybind11-branch: "v2.9"
57+
python: "3.12"
5458
steps:
5559
- uses: actions/checkout@v3
5660

@@ -74,7 +78,7 @@ jobs:
7478

7579
- name: Install demo module
7680
shell: bash
77-
run: ./tests/install-demo-module.sh --pybind11-branch "${{ matrix.pybind11-branch }}"
81+
run: ./tests/install-demo-module.sh --pybind11-branch "${{ matrix.pybind11-branch }}" --eigen-branch "master"
7882

7983
- name: Check stubs generation
8084
shell: bash

pybind11_stubgen/parser/mixins/fix.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ class FixTypingTypeNames(IParser):
355355
map(
356356
Identifier,
357357
[
358+
"buffer",
358359
"Buffer",
359360
],
360361
)

tests/install-demo-module.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
set -e
44

5+
PYTHON_EXECUTABLE=$(python -c 'import sys; print(sys.executable)')
6+
57
function parse_args() {
68

79
CLEAR='\033[0m'
@@ -13,17 +15,20 @@ function parse_args() {
1315
fi
1416
echo "Usage: $0 --pybind11-branch PYBIND11_BRANCH"
1517
echo " --pybind11-branch name of pybind11 branch"
18+
echo " --eigen-branch name of eigen branch"
1619
exit 1
1720
}
1821

1922
# parse params
2023
while [[ "$#" > 0 ]]; do case $1 in
2124
--pybind11-branch) PYBIND11_BRANCH="$2"; shift;shift;;
25+
--eigen-branch) EIGEN_BRANCH="$2"; shift;shift;;
2226
*) usage "Unknown parameter passed: $1"; shift; shift;;
2327
esac; done
2428

2529
# verify params
2630
if [ -z "$PYBIND11_BRANCH" ]; then usage "PYBIND11_BRANCH is not set"; fi;
31+
if [ -z "$EIGEN_BRANCH" ]; then usage "EIGEN_BRANCH is not set"; fi;
2732

2833
TESTS_ROOT="$(readlink -m "$(dirname "$0")")"
2934
PROJECT_ROOT="${TESTS_ROOT}/.."
@@ -39,7 +44,7 @@ clone_eigen() {
3944
if [ ! -d "${EXTERNAL_DIR}/eigen" ]; then
4045
git clone \
4146
--depth 1 \
42-
--branch master \
47+
--branch "${EIGEN_BRANCH}" \
4348
--single-branch \
4449
https://gitlab.com/libeigen/eigen.git \
4550
"${EXTERNAL_DIR}/eigen"
@@ -65,7 +70,10 @@ install_eigen() {
6570
}
6671

6772
install_pybind11() {
68-
cmake -S "${EXTERNAL_DIR}/pybind11" -B "${BUILD_ROOT}/pybind11"
73+
cmake \
74+
-S "${EXTERNAL_DIR}/pybind11" \
75+
-B "${BUILD_ROOT}/pybind11"\
76+
-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
6977
cmake --install "${BUILD_ROOT}/pybind11" \
7078
--prefix "${INSTALL_PREFIX}"
7179
}
@@ -80,8 +88,8 @@ install_demo() {
8088
install_pydemo() {
8189
(
8290
export CMAKE_PREFIX_PATH="$(readlink -m "${INSTALL_PREFIX}")";
83-
export CMAKE_ARGS="CMAKE_CXX_STANDARD=17";
84-
pip install "${TESTS_ROOT}/py-demo"
91+
export CMAKE_ARGS="-DCMAKE_CXX_STANDARD=17";
92+
pip install --force-reinstall "${TESTS_ROOT}/py-demo"
8593
)
8694
}
8795

tests/py-demo/bindings/src/modules.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
#include <pybind11/pybind11.h>
33
#include "opaque_types.h"
44

5+
#define PYBIND11_VERSION_AT_LEAST(x,y) (PYBIND11_VERSION_MAJOR>x || ( PYBIND11_VERSION_MAJOR>=x && PYBIND11_VERSION_MINOR>=y ))
6+
57
namespace py = pybind11;
68

7-
void bind_aliases_module(py::module_&& m);
8-
void bind_classes_module(py::module_&& m);
9-
void bind_eigen_module(py::module_&& m);
10-
void bind_enum_module(py::module_&& m);
11-
void bind_flawed_bindings_module(py::module_&& m);
12-
void bind_functions_module(py::module_&& m);
13-
void bind_issues_module(py::module_&& m);
14-
void bind_methods_module(py::module_&& m);
15-
void bind_numpy_module(py::module_&& m);
16-
void bind_properties_module(py::module_&& m);
17-
void bind_stl_module(py::module_&& m);
18-
void bind_stl_bind_module(py::module_&& m);
19-
void bind_typing_module(py::module_&& m);
20-
void bind_values_module(py::module_&& m);
9+
void bind_aliases_module(py::module&& m);
10+
void bind_classes_module(py::module&& m);
11+
void bind_eigen_module(py::module&& m);
12+
void bind_enum_module(py::module&& m);
13+
void bind_flawed_bindings_module(py::module&& m);
14+
void bind_functions_module(py::module&& m);
15+
void bind_issues_module(py::module&& m);
16+
void bind_methods_module(py::module&& m);
17+
void bind_numpy_module(py::module&& m);
18+
void bind_properties_module(py::module&& m);
19+
void bind_stl_module(py::module&& m);
20+
void bind_stl_bind_module(py::module&& m);
21+
void bind_typing_module(py::module&& m);
22+
void bind_values_module(py::module&& m);

tests/py-demo/bindings/src/modules/aliases.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace {
1818
};
1919
} // namespace
2020

21-
void bind_aliases_module(py::module_ &&m) {
21+
void bind_aliases_module(py::module &&m) {
2222
{
2323
// python module as value
2424
auto &&pyDummy = py::class_<Dummy>(m, "Dummy");

tests/py-demo/bindings/src/modules/classes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <demo/Inheritance.h>
55
#include <demo/NestedClasses.h>
66

7-
void bind_classes_module(py::module_&&m) {
7+
void bind_classes_module(py::module&&m) {
88

99
{
1010
auto pyOuter = py::class_<demo::Outer>(m, "Outer");

tests/py-demo/bindings/src/modules/eigen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <Eigen/Core>
44
#include <pybind11/eigen.h>
55

6-
void bind_eigen_module(py::module_ &&m) {
6+
void bind_eigen_module(py::module &&m) {
77

88
using DenseMatrixR = Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
99
using DenseMatrixC = Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic>;

tests/py-demo/bindings/src/modules/enum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <demo/sublibA/ConsoleColors.h>
44

5-
void bind_enum_module(py::module_&&m) {
5+
void bind_enum_module(py::module&&m) {
66

77
py::enum_<demo::sublibA::ConsoleForegroundColor>(m, "ConsoleForegroundColor")
88
.value("Green", demo::sublibA::ConsoleForegroundColor::Green)

tests/py-demo/bindings/src/modules/flawed_bindings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ enum Enum { ONE = 1, TWO = 2 };
88

99
} // namespace
1010

11-
void bind_flawed_bindings_module(py::module_&& m) {
11+
void bind_flawed_bindings_module(py::module&& m) {
1212
// This submodule will have C++ signatures in python docstrings to emulate
1313
// common mistakes in using pybind11
1414
m.def("get_unbound_type", [] { return Unbound{}; });

tests/py-demo/bindings/src/modules/functions.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
#include "modules.h"
2+
3+
#if PYBIND11_VERSION_MAJOR == 2 && PYBIND11_VERSION_MINOR >= 11
14
#include <pybind11/typing.h>
2-
#include <pybind11/stl.h>
5+
#endif
36

4-
#include "modules.h"
7+
#include <pybind11/stl.h>
58

69
#include <demo/sublibA/add.h>
710

@@ -15,7 +18,7 @@ namespace {
1518
};
1619
}; // namespace
1720

18-
void bind_functions_module(py::module_ &&m) {
21+
void bind_functions_module(py::module &&m) {
1922
m.def("add", demo::sublibA::add);
2023
{
2124

@@ -35,6 +38,7 @@ void bind_functions_module(py::module_ &&m) {
3538

3639
m.def("func_w_anon_args", [](int x, int y, int z) {});
3740

41+
#if PYBIND11_VERSION_AT_LEAST(2, 6)
3842
m.def(
3943
"func_w_named_pos_args",
4044
[](int x, int y, int z) {},
@@ -61,15 +65,19 @@ void bind_functions_module(py::module_ &&m) {
6165
py::arg("j"),
6266
py::kw_only(),
6367
py::arg("k"));
64-
68+
#endif
6569
m.def("accept_callable", [](py::function &callable) { return callable(); });
6670
m.def("accept_py_object", [](py::object &object) { return py::str(object); });
6771
m.def("accept_py_handle", [](py::handle &handle) { return py::str(handle); });
6872

73+
#if PYBIND11_VERSION_AT_LEAST(2, 12)
6974
m.def("accept_annotated_callable",
7075
[](py::typing::Callable<int(int, int)> &callable) { return callable(13, 42); });
76+
#endif
7177

78+
#if PYBIND11_VERSION_AT_LEAST(2, 10)
7279
m.def("accept_frozenset", [](const py::frozenset &) {});
80+
#endif
7381
m.def("accept_set", [](const py::set &) {});
7482

7583
m.def("default_int_arg", [](int n) {}, py::arg("n") = 5);

0 commit comments

Comments
 (0)