Skip to content

Commit a527a89

Browse files
Update PyBind11 to version 2.13.6 (#2331)
This changelist updates the default version of PyBind11 to 2.13.6, removing a CMake workaround in GitHub CI that is no longer needed after this upgrade.
1 parent 47a6332 commit a527a89

26 files changed

Lines changed: 1182 additions & 550 deletions

.github/workflows/main.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,6 @@ jobs:
403403
with:
404404
python-version: 3.${{ matrix.python-minor }}
405405

406-
- name: Install CMake
407-
uses: lukka/get-cmake@28983e0d3955dba2bb0a6810caae0c6cf268ec0c # v4.0.0
408-
with:
409-
cmakeVersion: 3.26
410-
411406
- name: Download Sdist
412407
uses: actions/download-artifact@v4
413408
with:

source/PyMaterialX/External/PyBind11/CMakeLists.txt

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,25 @@
55
# All rights reserved. Use of this source code is governed by a
66
# BSD-style license that can be found in the LICENSE file.
77

8-
cmake_minimum_required(VERSION 3.4)
8+
# Propagate this policy (FindPythonInterp removal) so it can be detected later
9+
if(NOT CMAKE_VERSION VERSION_LESS "3.27")
10+
cmake_policy(GET CMP0148 _pybind11_cmp0148)
11+
endif()
12+
13+
cmake_minimum_required(VERSION 3.5)
914

10-
# The `cmake_minimum_required(VERSION 3.4...3.22)` syntax does not work with
15+
# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
1116
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
1217
# the behavior using the following workaround:
13-
if(${CMAKE_VERSION} VERSION_LESS 3.22)
18+
if(${CMAKE_VERSION} VERSION_LESS 3.29)
1419
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
1520
else()
16-
cmake_policy(VERSION 3.22)
21+
cmake_policy(VERSION 3.29)
22+
endif()
23+
24+
if(_pybind11_cmp0148)
25+
cmake_policy(SET CMP0148 ${_pybind11_cmp0148})
26+
unset(_pybind11_cmp0148)
1727
endif()
1828

1929
# Avoid infinite recursion if tests include this as a subdirectory
@@ -82,42 +92,71 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
8292
set(pybind11_system "")
8393

8494
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
95+
if(CMAKE_VERSION VERSION_LESS "3.18")
96+
set(_pybind11_findpython_default OFF)
97+
else()
98+
set(_pybind11_findpython_default ON)
99+
endif()
85100
else()
86101
set(PYBIND11_MASTER_PROJECT OFF)
87102
set(pybind11_system SYSTEM)
103+
set(_pybind11_findpython_default OFF)
88104
endif()
89105

90106
# Options
91107
option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT})
92108
option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT})
93109
option(PYBIND11_NOPYTHON "Disable search for Python" OFF)
110+
option(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION
111+
"To enforce that a handle_type_name<> specialization exists" OFF)
94112
option(PYBIND11_SIMPLE_GIL_MANAGEMENT
95113
"Use simpler GIL management logic that does not support disassociation" OFF)
114+
option(PYBIND11_NUMPY_1_ONLY
115+
"Disable NumPy 2 support to avoid changes to previous pybind11 versions." OFF)
96116
set(PYBIND11_INTERNALS_VERSION
97117
""
98118
CACHE STRING "Override the ABI version, may be used to enable the unstable ABI.")
119+
option(PYBIND11_USE_CROSSCOMPILING "Respect CMAKE_CROSSCOMPILING" OFF)
99120

121+
if(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION)
122+
add_compile_definitions(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION)
123+
endif()
100124
if(PYBIND11_SIMPLE_GIL_MANAGEMENT)
101125
add_compile_definitions(PYBIND11_SIMPLE_GIL_MANAGEMENT)
102126
endif()
127+
if(PYBIND11_NUMPY_1_ONLY)
128+
add_compile_definitions(PYBIND11_NUMPY_1_ONLY)
129+
endif()
103130

104131
cmake_dependent_option(
105132
USE_PYTHON_INCLUDE_DIR
106133
"Install pybind11 headers in Python include directory instead of default installation prefix"
107134
OFF "PYBIND11_INSTALL" OFF)
108135

109-
cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" OFF
136+
cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" ${_pybind11_findpython_default}
110137
"NOT CMAKE_VERSION VERSION_LESS 3.12" OFF)
111138

139+
# Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests
140+
# (makes transition easier while we support both modes).
141+
if(PYBIND11_MASTER_PROJECT
142+
AND PYBIND11_FINDPYTHON
143+
AND DEFINED PYTHON_EXECUTABLE
144+
AND NOT DEFINED Python_EXECUTABLE)
145+
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
146+
endif()
147+
112148
# NB: when adding a header don't forget to also add it to setup.py
113149
set(PYBIND11_HEADERS
114150
include/pybind11/detail/class.h
115151
include/pybind11/detail/common.h
152+
include/pybind11/detail/cpp_conduit.h
116153
include/pybind11/detail/descr.h
117154
include/pybind11/detail/init.h
118155
include/pybind11/detail/internals.h
119156
include/pybind11/detail/type_caster_base.h
120157
include/pybind11/detail/typeid.h
158+
include/pybind11/detail/value_and_holder.h
159+
include/pybind11/detail/exception_translation.h
121160
include/pybind11/attr.h
122161
include/pybind11/buffer_info.h
123162
include/pybind11/cast.h
@@ -126,11 +165,13 @@ set(PYBIND11_HEADERS
126165
include/pybind11/complex.h
127166
include/pybind11/options.h
128167
include/pybind11/eigen.h
168+
include/pybind11/eigen/common.h
129169
include/pybind11/eigen/matrix.h
130170
include/pybind11/eigen/tensor.h
131171
include/pybind11/embed.h
132172
include/pybind11/eval.h
133173
include/pybind11/gil.h
174+
include/pybind11/gil_safe_call_once.h
134175
include/pybind11/iostream.h
135176
include/pybind11/functional.h
136177
include/pybind11/numpy.h
@@ -139,7 +180,9 @@ set(PYBIND11_HEADERS
139180
include/pybind11/pytypes.h
140181
include/pybind11/stl.h
141182
include/pybind11/stl_bind.h
142-
include/pybind11/stl/filesystem.h)
183+
include/pybind11/stl/filesystem.h
184+
include/pybind11/type_caster_pyobject_ptr.h
185+
include/pybind11/typing.h)
143186

144187
# Compare with grep and warn if mismatched
145188
if(PYBIND11_MASTER_PROJECT AND NOT CMAKE_VERSION VERSION_LESS 3.12)
@@ -260,6 +303,7 @@ if(PYBIND11_INSTALL)
260303
tools/pybind11Common.cmake
261304
tools/pybind11Tools.cmake
262305
tools/pybind11NewTools.cmake
306+
tools/pybind11GuessPythonExtSuffix.cmake
263307
DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
264308

265309
if(NOT PYBIND11_EXPORT_NAME)
@@ -275,7 +319,21 @@ if(PYBIND11_INSTALL)
275319

276320
# pkg-config support
277321
if(NOT prefix_for_pc_file)
278-
set(prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}")
322+
if(IS_ABSOLUTE "${CMAKE_INSTALL_DATAROOTDIR}")
323+
set(prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}")
324+
else()
325+
set(pc_datarootdir "${CMAKE_INSTALL_DATAROOTDIR}")
326+
if(CMAKE_VERSION VERSION_LESS 3.20)
327+
set(prefix_for_pc_file "\${pcfiledir}/..")
328+
while(pc_datarootdir)
329+
get_filename_component(pc_datarootdir "${pc_datarootdir}" DIRECTORY)
330+
string(APPEND prefix_for_pc_file "/..")
331+
endwhile()
332+
else()
333+
cmake_path(RELATIVE_PATH CMAKE_INSTALL_PREFIX BASE_DIRECTORY CMAKE_INSTALL_DATAROOTDIR
334+
OUTPUT_VARIABLE prefix_for_pc_file)
335+
endif()
336+
endif()
279337
endif()
280338
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
281339
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11.pc.in"

source/PyMaterialX/External/PyBind11/include/pybind11/buffer_info.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,22 @@ struct buffer_info {
102102
template <typename T>
103103
buffer_info(const T *ptr, ssize_t size, bool readonly = true)
104104
: buffer_info(
105-
const_cast<T *>(ptr), sizeof(T), format_descriptor<T>::format(), size, readonly) {}
105+
const_cast<T *>(ptr), sizeof(T), format_descriptor<T>::format(), size, readonly) {}
106106

107107
explicit buffer_info(Py_buffer *view, bool ownview = true)
108108
: buffer_info(
109-
view->buf,
110-
view->itemsize,
111-
view->format,
112-
view->ndim,
113-
{view->shape, view->shape + view->ndim},
114-
/* Though buffer::request() requests PyBUF_STRIDES, ctypes objects
115-
* ignore this flag and return a view with NULL strides.
116-
* When strides are NULL, build them manually. */
117-
view->strides
118-
? std::vector<ssize_t>(view->strides, view->strides + view->ndim)
119-
: detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize),
120-
(view->readonly != 0)) {
109+
view->buf,
110+
view->itemsize,
111+
view->format,
112+
view->ndim,
113+
{view->shape, view->shape + view->ndim},
114+
/* Though buffer::request() requests PyBUF_STRIDES, ctypes objects
115+
* ignore this flag and return a view with NULL strides.
116+
* When strides are NULL, build them manually. */
117+
view->strides
118+
? std::vector<ssize_t>(view->strides, view->strides + view->ndim)
119+
: detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize),
120+
(view->readonly != 0)) {
121121
// NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
122122
this->m_view = view;
123123
// NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
@@ -176,7 +176,7 @@ struct buffer_info {
176176
detail::any_container<ssize_t> &&strides_in,
177177
bool readonly)
178178
: buffer_info(
179-
ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) {}
179+
ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) {}
180180

181181
Py_buffer *m_view = nullptr;
182182
bool ownview = false;

source/PyMaterialX/External/PyBind11/include/pybind11/cast.h

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,13 @@ class type_caster<std::pair<T1, T2>> : public tuple_caster<std::pair, T1, T2> {}
740740
template <typename... Ts>
741741
class type_caster<std::tuple<Ts...>> : public tuple_caster<std::tuple, Ts...> {};
742742

743+
template <>
744+
class type_caster<std::tuple<>> : public tuple_caster<std::tuple> {
745+
public:
746+
// PEP 484 specifies this syntax for an empty tuple
747+
static constexpr auto name = const_name("tuple[()]");
748+
};
749+
743750
/// Helper class which abstracts away certain actions. Users can provide specializations for
744751
/// custom holders, but it's only necessary if the type has a non-standard interface.
745752
template <typename T>
@@ -787,11 +794,11 @@ struct copyable_holder_caster : public type_caster_base<type> {
787794
}
788795
}
789796

790-
bool load_value(value_and_holder &&v_h) {
797+
void load_value(value_and_holder &&v_h) {
791798
if (v_h.holder_constructed()) {
792799
value = v_h.value_ptr();
793800
holder = v_h.template holder<holder_type>();
794-
return true;
801+
return;
795802
}
796803
throw cast_error("Unable to cast from non-held to held instance (T& to Holder<T>) "
797804
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
@@ -1339,13 +1346,24 @@ enable_if_t<!cast_is_temporary_value_reference<T>::value, T> cast_ref(object &&,
13391346
// static_assert, even though if it's in dead code, so we provide a "trampoline" to pybind11::cast
13401347
// that only does anything in cases where pybind11::cast is valid.
13411348
template <typename T>
1342-
enable_if_t<cast_is_temporary_value_reference<T>::value, T> cast_safe(object &&) {
1349+
enable_if_t<cast_is_temporary_value_reference<T>::value
1350+
&& !detail::is_same_ignoring_cvref<T, PyObject *>::value,
1351+
T>
1352+
cast_safe(object &&) {
13431353
pybind11_fail("Internal error: cast_safe fallback invoked");
13441354
}
13451355
template <typename T>
13461356
enable_if_t<std::is_void<T>::value, void> cast_safe(object &&) {}
13471357
template <typename T>
1348-
enable_if_t<detail::none_of<cast_is_temporary_value_reference<T>, std::is_void<T>>::value, T>
1358+
enable_if_t<detail::is_same_ignoring_cvref<T, PyObject *>::value, PyObject *>
1359+
cast_safe(object &&o) {
1360+
return o.release().ptr();
1361+
}
1362+
template <typename T>
1363+
enable_if_t<detail::none_of<cast_is_temporary_value_reference<T>,
1364+
detail::is_same_ignoring_cvref<T, PyObject *>,
1365+
std::is_void<T>>::value,
1366+
T>
13491367
cast_safe(object &&o) {
13501368
return pybind11::cast<T>(std::move(o));
13511369
}

0 commit comments

Comments
 (0)