From c59bca287118393ca96b10823116cedd28da3ac3 Mon Sep 17 00:00:00 2001 From: Aaron Miller Date: Sun, 23 Feb 2025 23:42:45 -0800 Subject: [PATCH] Bump pybind Fixes #425 Our previous version of pybind didn't support py3.11. pybind 2.13.6 supports all versions of python that we support. There isn't much downside to downloading an additional copy of pybind if you have an older one installed that supports your version of python. If we wanted to we could write some table of minimum required versions based on SYMFORCE_PYTHON's version Topic: sf-pybind --- symforce/pybind/CMakeLists.txt | 6 ++-- symforce/test_util/stubs_util.py | 35 ++++++++++++++++++++++ test/symforce_cc_sym_stubs_codegen_test.py | 2 ++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/symforce/pybind/CMakeLists.txt b/symforce/pybind/CMakeLists.txt index 04eb7d28..2fb3c29d 100644 --- a/symforce/pybind/CMakeLists.txt +++ b/symforce/pybind/CMakeLists.txt @@ -9,7 +9,7 @@ include(FetchContent) -find_package(pybind11 2.9.2 QUIET) +find_package(pybind11 2.13.6 QUIET) if (NOT pybind11_FOUND) message(STATUS "pybind11 not found, adding with FetchContent") # NOTE(brad): Set PYTHON_EXECUTABLE to ensure pybind11 uses the same @@ -17,8 +17,8 @@ if (NOT pybind11_FOUND) set(PYTHON_EXECUTABLE ${SYMFORCE_PYTHON}) FetchContent_Declare( pybind11 - URL https://github.com/pybind/pybind11/archive/v2.9.2.zip - URL_HASH SHA256=d1646e6f70d8a3acb2ddd85ce1ed543b5dd579c68b8fb8e9638282af20edead8 + URL https://github.com/pybind/pybind11/archive/v2.13.6.zip + URL_HASH SHA256=d0a116e91f64a4a2d8fb7590c34242df92258a61ec644b79127951e821b47be6 ) FetchContent_MakeAvailable(pybind11) else() diff --git a/symforce/test_util/stubs_util.py b/symforce/test_util/stubs_util.py index 13dc49a3..c0ec8944 100644 --- a/symforce/test_util/stubs_util.py +++ b/symforce/test_util/stubs_util.py @@ -80,3 +80,38 @@ def handle_field( return result pybind11_stubgen.parser.mixins.fix.FixMissingNoneHashFieldAnnotation.handle_field = handle_field # type: ignore[method-assign] + + +def patch_filter_pybind_internals() -> None: + """ + See https://github.com/sizmailov/pybind11-stubgen/pull/243 + """ + + def handle_class_member( + self: pybind11_stubgen.parser.mixins.filter.FilterPybindInternals, + path: pybind11_stubgen.structs.QualifiedName, + class_: type, + member: T.Any, + ) -> T.Union[ + pybind11_stubgen.structs.Docstring, + pybind11_stubgen.structs.Alias, + pybind11_stubgen.structs.Class, + T.List[pybind11_stubgen.structs.Method], + pybind11_stubgen.structs.Field, + pybind11_stubgen.structs.Property, + None, + ]: + name = path[-1] + if name in self.__class_blacklist: + return None + if name.startswith("__pybind11_module"): + return None + if name.startswith("_pybind11_conduit_v1_"): + return None + return super( # type: ignore[safe-super] + pybind11_stubgen.parser.mixins.filter.FilterPybindInternals, self + ).handle_class_member(path, class_, member) + + pybind11_stubgen.parser.mixins.filter.FilterPybindInternals.handle_class_member = ( # type: ignore[method-assign] + handle_class_member + ) diff --git a/test/symforce_cc_sym_stubs_codegen_test.py b/test/symforce_cc_sym_stubs_codegen_test.py index c32bae55..0ecb4d60 100644 --- a/test/symforce_cc_sym_stubs_codegen_test.py +++ b/test/symforce_cc_sym_stubs_codegen_test.py @@ -15,6 +15,7 @@ from symforce import path_util from symforce.codegen import format_util from symforce.test_util import TestCase +from symforce.test_util.stubs_util import patch_filter_pybind_internals from symforce.test_util.stubs_util import patch_handle_docstring from symforce.test_util.stubs_util import patch_lcmtype_imports from symforce.test_util.stubs_util import patch_remove_parameters @@ -22,6 +23,7 @@ patch_lcmtype_imports() patch_handle_docstring() patch_remove_parameters() +patch_filter_pybind_internals() class SymforceCCSymStubsCodegenTest(TestCase):