From 977574d9a4b912d7135d82c615f161dab429ce70 Mon Sep 17 00:00:00 2001 From: Eric Cousineau Date: Thu, 12 Oct 2023 19:57:37 -0400 Subject: [PATCH] [workspace] Bump pybind11 fork to latest commit This merges in pybind11 upstream's v2.11.1 Removes need for monostate_pybind.h Changes error types for certain tests --- bindings/pydrake/common/BUILD.bazel | 10 ------- bindings/pydrake/common/monostate_pybind.h | 30 ------------------- .../test/type_safe_index_pybind_test.cc | 5 ++-- bindings/pydrake/geometry/BUILD.bazel | 1 - .../geometry/geometry_py_scene_graph.cc | 1 - bindings/pydrake/multibody/BUILD.bazel | 1 - bindings/pydrake/multibody/meshcat_py.cc | 1 - tools/workspace/pybind11/package.BUILD.bazel | 4 +++ .../pybind11/pybind11-config-version.cmake | 4 +-- .../workspace/pybind11/pybind11-config.cmake | 2 +- tools/workspace/pybind11/repository.bzl | 4 +-- 11 files changed, 12 insertions(+), 51 deletions(-) delete mode 100644 bindings/pydrake/common/monostate_pybind.h diff --git a/bindings/pydrake/common/BUILD.bazel b/bindings/pydrake/common/BUILD.bazel index f5b81152db8a..c003c3a10af9 100644 --- a/bindings/pydrake/common/BUILD.bazel +++ b/bindings/pydrake/common/BUILD.bazel @@ -161,16 +161,6 @@ drake_cc_library( ], ) -drake_cc_library( - name = "monostate_pybind", - hdrs = ["monostate_pybind.h"], - declare_installed_headers = False, - visibility = ["//visibility:public"], - deps = [ - "@pybind11", - ], -) - drake_cc_library( name = "serialize_pybind", hdrs = ["serialize_pybind.h"], diff --git a/bindings/pydrake/common/monostate_pybind.h b/bindings/pydrake/common/monostate_pybind.h deleted file mode 100644 index 262cec0e229e..000000000000 --- a/bindings/pydrake/common/monostate_pybind.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include - -#include "pybind11/pybind11.h" -#include "pybind11/stl.h" - -// TODO(SeanCurtis-TRI) When pybind issue 3019 gets resolved, we won't need to -// define this locally anymore. In fact, it will probably cause link errors. -namespace pybind11 { -namespace detail { - -/* This class teaches pybind11 that C++'s `std::monostate` and Python's `None` -are the same thing. You must include it when binding any API that uses a -`std::variant`. */ -template <> -struct type_caster { - public: - PYBIND11_TYPE_CASTER(std::monostate, _("None")); - - bool load(handle src, bool) { return src.ptr() == Py_None; } - - static handle cast( - std::monostate, return_value_policy /* policy */, handle /* parent */) { - Py_RETURN_NONE; - } -}; - -} // namespace detail -} // namespace pybind11 diff --git a/bindings/pydrake/common/test/type_safe_index_pybind_test.cc b/bindings/pydrake/common/test/type_safe_index_pybind_test.cc index 9629e24efd20..1d7711a9d21c 100644 --- a/bindings/pydrake/common/test/type_safe_index_pybind_test.cc +++ b/bindings/pydrake/common/test/type_safe_index_pybind_test.cc @@ -58,7 +58,7 @@ GTEST_TEST(TypeSafeIndexTest, CheckCasting) { // TypeSafeIndex<> is not implicitly constructible from an int. // TODO(eric.cousineau): Consider relaxing this to *only* accept `int`s, and // puke if another `TypeSafeIndex` is encountered. - ASSERT_THROW(py::eval("pass_thru_index(10)"), std::runtime_error); + ASSERT_THROW(py::eval("pass_thru_index(10)"), py::error_already_set); CheckValue("pass_thru_index(Index(10))", 10); CheckValue("pass_thru_index(Index(10))", Index{10}); @@ -66,7 +66,8 @@ GTEST_TEST(TypeSafeIndexTest, CheckCasting) { using OtherIndex = TypeSafeIndex; BindTypeSafeIndex(m, "OtherIndex"); - ASSERT_THROW(py::eval("pass_thru_index(OtherIndex(10))"), std::runtime_error); + ASSERT_THROW( + py::eval("pass_thru_index(OtherIndex(10))"), py::error_already_set); py::object py_index = py::eval("Index(10)"); ASSERT_THROW(py_index.cast(), std::runtime_error); diff --git a/bindings/pydrake/geometry/BUILD.bazel b/bindings/pydrake/geometry/BUILD.bazel index 2556e3fbd38c..b0a9b19c94a5 100644 --- a/bindings/pydrake/geometry/BUILD.bazel +++ b/bindings/pydrake/geometry/BUILD.bazel @@ -38,7 +38,6 @@ drake_pybind_library( "//bindings/pydrake/common:default_scalars_pybind", "//bindings/pydrake/common:deprecation_pybind", "//bindings/pydrake/common:identifier_pybind", - "//bindings/pydrake/common:monostate_pybind", "//bindings/pydrake/common:serialize_pybind", "//bindings/pydrake/common:sorted_pair_pybind", "//bindings/pydrake/common:type_pack", diff --git a/bindings/pydrake/geometry/geometry_py_scene_graph.cc b/bindings/pydrake/geometry/geometry_py_scene_graph.cc index 059c3048b9e0..f7ea136232b1 100644 --- a/bindings/pydrake/geometry/geometry_py_scene_graph.cc +++ b/bindings/pydrake/geometry/geometry_py_scene_graph.cc @@ -4,7 +4,6 @@ pydrake.geometry module. */ #include "drake/bindings/pydrake/common/default_scalars_pybind.h" -#include "drake/bindings/pydrake/common/monostate_pybind.h" #include "drake/bindings/pydrake/common/type_pack.h" #include "drake/bindings/pydrake/common/value_pybind.h" #include "drake/bindings/pydrake/documentation_pybind.h" diff --git a/bindings/pydrake/multibody/BUILD.bazel b/bindings/pydrake/multibody/BUILD.bazel index d17b7b102e04..063db6a7aa6a 100644 --- a/bindings/pydrake/multibody/BUILD.bazel +++ b/bindings/pydrake/multibody/BUILD.bazel @@ -174,7 +174,6 @@ drake_pybind_library( "//bindings/pydrake:documentation_pybind", "//bindings/pydrake/common:cpp_template_pybind", "//bindings/pydrake/common:default_scalars_pybind", - "//bindings/pydrake/common:monostate_pybind", "//bindings/pydrake/common:serialize_pybind", "//bindings/pydrake/common:type_pack", ], diff --git a/bindings/pydrake/multibody/meshcat_py.cc b/bindings/pydrake/multibody/meshcat_py.cc index 3cc471adcf47..0d3e3a278a67 100644 --- a/bindings/pydrake/multibody/meshcat_py.cc +++ b/bindings/pydrake/multibody/meshcat_py.cc @@ -1,6 +1,5 @@ #include "drake/bindings/pydrake/common/cpp_template_pybind.h" #include "drake/bindings/pydrake/common/default_scalars_pybind.h" -#include "drake/bindings/pydrake/common/monostate_pybind.h" #include "drake/bindings/pydrake/common/serialize_pybind.h" #include "drake/bindings/pydrake/common/type_pack.h" #include "drake/bindings/pydrake/documentation_pybind.h" diff --git a/tools/workspace/pybind11/package.BUILD.bazel b/tools/workspace/pybind11/package.BUILD.bazel index 142ac5aa4202..9791d50f880a 100644 --- a/tools/workspace/pybind11/package.BUILD.bazel +++ b/tools/workspace/pybind11/package.BUILD.bazel @@ -27,6 +27,9 @@ _HDRS = [ "include/pybind11/detail/type_caster_base.h", "include/pybind11/detail/typeid.h", "include/pybind11/eigen.h", + "include/pybind11/eigen/common.h", + "include/pybind11/eigen/matrix.h", + "include/pybind11/eigen/tensor.h", "include/pybind11/embed.h", "include/pybind11/eval.h", "include/pybind11/functional.h", @@ -40,6 +43,7 @@ _HDRS = [ "include/pybind11/stl.h", "include/pybind11/stl/filesystem.h", "include/pybind11/stl_bind.h", + "include/pybind11/type_caster_pyobject_ptr.h", ] check_lists_consistency( diff --git a/tools/workspace/pybind11/pybind11-config-version.cmake b/tools/workspace/pybind11/pybind11-config-version.cmake index 53c916cb241f..8299128b5631 100644 --- a/tools/workspace/pybind11/pybind11-config-version.cmake +++ b/tools/workspace/pybind11/pybind11-config-version.cmake @@ -1,5 +1,5 @@ -set(PACKAGE_VERSION "2.9.0.dev1") -set(PACKAGE_COMPAT_VERSION "2.9.0.dev1") +set(PACKAGE_VERSION "2.11.1") +set(PACKAGE_COMPAT_VERSION "2.11.1") if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) set(PACKAGE_VERSION_COMPATIBLE FALSE) diff --git a/tools/workspace/pybind11/pybind11-config.cmake b/tools/workspace/pybind11/pybind11-config.cmake index 520b8829bec0..7193d9f30402 100644 --- a/tools/workspace/pybind11/pybind11-config.cmake +++ b/tools/workspace/pybind11/pybind11-config.cmake @@ -51,7 +51,7 @@ unset(_targetsDefined) unset(_targetsNotDefined) unset(_expectedTargets) -set(pybind11_VERSION "2.9.0.dev1") +set(pybind11_VERSION "2.11.1") add_library(pybind11::embed INTERFACE IMPORTED) set_target_properties(pybind11::embed PROPERTIES diff --git a/tools/workspace/pybind11/repository.bzl b/tools/workspace/pybind11/repository.bzl index 977cc0b9a25b..ad5a742969ca 100644 --- a/tools/workspace/pybind11/repository.bzl +++ b/tools/workspace/pybind11/repository.bzl @@ -8,9 +8,9 @@ _REPOSITORY = "RobotLocomotion/pybind11" # https://github.com/RobotLocomotion/pybind11/blob/drake/include/pybind11/detail/common.h # and if it has changed, then update the version number in the two # pybind11-*.cmake files in the current directory to match. -_COMMIT = "36695db542e1c34f6db7ca3ebb0415de30762395" +_COMMIT = "c1b0cddf0af5dbca6030fe51fcba25c386bf46a6" -_SHA256 = "36b35032ae6279af6257588856b0284b8106221c816b26509a05801c54d60e30" +_SHA256 = "b98c9ec522a89fabef86b23d6ea530a2291eafd518f6a7a8a18b0f58b7e3515e" def pybind11_repository( name,