Skip to content

Commit 826f615

Browse files
committed
Merge branch 'master' into sh_merge_master
2 parents 10283c2 + 7af193e commit 826f615

34 files changed

+668
-71
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,15 @@ jobs:
109109
run: python -m pip install pytest-github-actions-annotate-failures
110110

111111
# First build - C++11 mode and inplace
112-
# More-or-less randomly adding -DPYBIND11_SIMPLE_GIL_MANAGEMENT=ON here.
112+
# More-or-less randomly adding -DPYBIND11_SIMPLE_GIL_MANAGEMENT=ON here
113+
# (same for PYBIND11_NUMPY_1_ONLY, but requires a NumPy 1.x at runtime).
113114
- name: Configure C++11 ${{ matrix.args }}
114115
run: >
115116
cmake -S . -B .
116117
-DPYBIND11_WERROR=ON
118+
-DPYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION=ON
117119
-DPYBIND11_SIMPLE_GIL_MANAGEMENT=ON
120+
-DPYBIND11_NUMPY_1_ONLY=ON
118121
-DDOWNLOAD_CATCH=ON
119122
-DDOWNLOAD_EIGEN=ON
120123
-DCMAKE_CXX_STANDARD=11
@@ -139,11 +142,13 @@ jobs:
139142

140143
# Second build - C++17 mode and in a build directory
141144
# More-or-less randomly adding -DPYBIND11_SIMPLE_GIL_MANAGEMENT=OFF here.
145+
# (same for PYBIND11_NUMPY_1_ONLY, but requires a NumPy 1.x at runtime).
142146
- name: Configure C++17
143147
run: >
144148
cmake -S . -B build2
145149
-DPYBIND11_WERROR=ON
146150
-DPYBIND11_SIMPLE_GIL_MANAGEMENT=OFF
151+
-DPYBIND11_NUMPY_1_ONLY=ON
147152
-DDOWNLOAD_CATCH=ON
148153
-DDOWNLOAD_EIGEN=ON
149154
-DCMAKE_CXX_STANDARD=17
@@ -661,6 +666,11 @@ jobs:
661666
run: |
662667
python3 -m pip install cmake -r tests/requirements.txt
663668
669+
- name: Ensure NumPy 2 is used (required Python >= 3.9)
670+
if: matrix.container == 'almalinux:9'
671+
run: |
672+
python3 -m pip install 'numpy>=2.0.0b1' 'scipy>=1.13.0rc1'
673+
664674
- name: Configure
665675
shell: bash
666676
run: >
@@ -896,8 +906,10 @@ jobs:
896906
python-version: ${{ matrix.python }}
897907

898908
- name: Prepare env
909+
# Ensure use of NumPy 2 (via NumPy nightlies but can be changed soon)
899910
run: |
900911
python3 -m pip install -r tests/requirements.txt
912+
python3 -m pip install 'numpy>=2.0.0b1' 'scipy>=1.13.0rc1'
901913
902914
- name: Update CMake
903915
uses: jwlawson/actions-setup-cmake@v2.0

.github/workflows/labeler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
pull-requests: write
1515
steps:
1616

17-
- uses: actions/labeler@main
17+
- uses: actions/labeler@v4
1818
if: >
1919
github.event.pull_request.merged == true &&
2020
!startsWith(github.event.pull_request.title, 'chore(deps):') &&

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,25 @@ endif()
107107
option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT})
108108
option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT})
109109
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)
110112
option(PYBIND11_SIMPLE_GIL_MANAGEMENT
111113
"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)
112116
set(PYBIND11_INTERNALS_VERSION
113117
""
114118
CACHE STRING "Override the ABI version, may be used to enable the unstable ABI.")
115119

120+
if(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION)
121+
add_compile_definitions(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION)
122+
endif()
116123
if(PYBIND11_SIMPLE_GIL_MANAGEMENT)
117124
add_compile_definitions(PYBIND11_SIMPLE_GIL_MANAGEMENT)
118125
endif()
126+
if(PYBIND11_NUMPY_1_ONLY)
127+
add_compile_definitions(PYBIND11_NUMPY_1_ONLY)
128+
endif()
119129

120130
cmake_dependent_option(
121131
USE_PYTHON_INCLUDE_DIR

README.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ with everything stripped away that isn't relevant for binding
4040
generation. Without comments, the core header files only require ~4K
4141
lines of code and depend on Python (3.6+, or PyPy) and the C++
4242
standard library. This compact implementation was possible thanks to
43-
some of the new C++11 language features (specifically: tuples, lambda
44-
functions and variadic templates). Since its creation, this library has
45-
grown beyond Boost.Python in many ways, leading to dramatically simpler
46-
binding code in many common situations.
43+
some C++11 language features (specifically: tuples, lambda functions and
44+
variadic templates). Since its creation, this library has grown beyond
45+
Boost.Python in many ways, leading to dramatically simpler binding code in many
46+
common situations.
4747

4848
Tutorial and reference documentation is provided at
4949
`pybind11.readthedocs.io <https://pybind11.readthedocs.io/en/latest>`_.
@@ -75,6 +75,7 @@ pybind11 can map the following core C++ features to Python:
7575
- Internal references with correct reference counting
7676
- C++ classes with virtual (and pure virtual) methods can be extended
7777
in Python
78+
- Integrated NumPy support (NumPy 2 requires pybind11 2.12+)
7879

7980
Goodies
8081
-------

docs/changelog.rst

Lines changed: 176 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,183 @@ IN DEVELOPMENT
1515

1616
Changes will be summarized here periodically.
1717

18+
Version 2.12.0 (March 27, 2025)
19+
-------------------------------
20+
21+
New Features:
22+
23+
* ``pybind11`` now supports compiling for
24+
`NumPy 2 <https://numpy.org/devdocs/numpy_2_0_migration_guide.html>`_. Most
25+
code shouldn't change (see :ref:`upgrade-guide-2.12` for details). However,
26+
if you experience issues you can define ``PYBIND11_NUMPY_1_ONLY`` to disable
27+
the new support for now, but this will be removed in the future.
28+
`#5050 <https://github.com/pybind/pybind11/pull/5050>`_
29+
30+
* ``pybind11/gil_safe_call_once.h`` was added (it needs to be included
31+
explicitly). The primary use case is GIL-safe initialization of C++
32+
``static`` variables.
33+
`#4877 <https://github.com/pybind/pybind11/pull/4877>`_
34+
35+
* Support move-only iterators in ``py::make_iterator``,
36+
``py::make_key_iterator``, ``py::make_value_iterator``.
37+
`#4834 <https://github.com/pybind/pybind11/pull/4834>`_
38+
39+
* Two simple ``py::set_error()`` functions were added and the documentation was
40+
updated accordingly. In particular, ``py::exception<>::operator()`` was
41+
deprecated (use one of the new functions instead). The documentation for
42+
``py::exception<>`` was further updated to not suggest code that may result
43+
in undefined behavior.
44+
`#4772 <https://github.com/pybind/pybind11/pull/4772>`_
45+
46+
Bug fixes:
47+
48+
* Removes potential for Undefined Behavior during process teardown.
49+
`#4897 <https://github.com/pybind/pybind11/pull/4897>`_
50+
51+
* Improve compatibility with the nvcc compiler (especially CUDA 12.1/12.2).
52+
`#4893 <https://github.com/pybind/pybind11/pull/4893>`_
53+
54+
* ``pybind11/numpy.h`` now imports NumPy's ``multiarray`` and ``_internal``
55+
submodules with paths depending on the installed version of NumPy (for
56+
compatibility with NumPy 2).
57+
`#4857 <https://github.com/pybind/pybind11/pull/4857>`_
58+
59+
* Builtins collections names in docstrings are now consistently rendered in
60+
lowercase (list, set, dict, tuple), in accordance with PEP 585.
61+
`#4833 <https://github.com/pybind/pybind11/pull/4833>`_
62+
63+
* Added ``py::typing::Iterator<T>``, ``py::typing::Iterable<T>``.
64+
`#4832 <https://github.com/pybind/pybind11/pull/4832>`_
65+
66+
* Render ``py::function`` as ``Callable`` in docstring.
67+
`#4829 <https://github.com/pybind/pybind11/pull/4829>`_
68+
69+
* Also bump ``PYBIND11_INTERNALS_VERSION`` for MSVC, which unlocks two new
70+
features without creating additional incompatibilities.
71+
`#4819 <https://github.com/pybind/pybind11/pull/4819>`_
72+
73+
* Guard against crashes/corruptions caused by modules built with different MSVC
74+
versions.
75+
`#4779 <https://github.com/pybind/pybind11/pull/4779>`_
76+
77+
* A long-standing bug in the handling of Python multiple inheritance was fixed.
78+
See PR #4762 for the rather complex details.
79+
`#4762 <https://github.com/pybind/pybind11/pull/4762>`_
80+
81+
* Fix ``bind_map`` with ``using`` declarations.
82+
`#4952 <https://github.com/pybind/pybind11/pull/4952>`_
83+
84+
* Qualify ``py::detail::concat`` usage to avoid ADL selecting one from
85+
somewhere else, such as modernjson's concat.
86+
`#4955 <https://github.com/pybind/pybind11/pull/4955>`_
87+
88+
* Use new PyCode API on Python 3.12+.
89+
`#4916 <https://github.com/pybind/pybind11/pull/4916>`_
90+
91+
* Minor cleanup from warnings reported by Clazy.
92+
`#4988 <https://github.com/pybind/pybind11/pull/4988>`_
93+
94+
* Remove typing and duplicate ``class_`` for ``KeysView``/``ValuesView``/``ItemsView``.
95+
`#4985 <https://github.com/pybind/pybind11/pull/4985>`_
96+
97+
* Use ``PyObject_VisitManagedDict()`` and ``PyObject_ClearManagedDict()`` on Python 3.13 and newer.
98+
`#4973 <https://github.com/pybind/pybind11/pull/4973>`_
99+
100+
* Update ``make_static_property_type()`` to make it compatible with Python 3.13.
101+
`#4971 <https://github.com/pybind/pybind11/pull/4971>`_
102+
103+
.. fix(types)
104+
105+
* Render typed iterators for ``make_iterator``, ``make_key_iterator``,
106+
``make_value_iterator``.
107+
`#4876 <https://github.com/pybind/pybind11/pull/4876>`_
108+
109+
* Add several missing type name specializations.
110+
`#5073 <https://github.com/pybind/pybind11/pull/5073>`_
111+
112+
* Change docstring render for ``py::buffer``, ``py::sequence`` and
113+
``py::handle`` (to ``Buffer``, ``Sequence``, ``Any``).
114+
`#4831 <https://github.com/pybind/pybind11/pull/4831>`_
115+
116+
* Fixed ``base_enum.__str__`` docstring.
117+
`#4827 <https://github.com/pybind/pybind11/pull/4827>`_
118+
119+
* Enforce single line docstring signatures.
120+
`#4735 <https://github.com/pybind/pybind11/pull/4735>`_
121+
122+
* Special 'typed' wrappers now available in ``typing.h`` to annotate tuple, dict,
123+
list, set, and function.
124+
`#4259 <https://github.com/pybind/pybind11/pull/4259>`_
125+
126+
* Create ``handle_type_name`` specialization to type-hint variable length tuples.
127+
`#5051 <https://github.com/pybind/pybind11/pull/5051>`_
128+
129+
.. fix(build)
130+
131+
* Setting ``PYBIND11_FINDPYTHON`` to OFF will force the old FindPythonLibs mechanism to be used.
132+
`#5042 <https://github.com/pybind/pybind11/pull/5042>`_
133+
134+
* Skip empty ``PYBIND11_PYTHON_EXECUTABLE_LAST`` for the first cmake run.
135+
`#4856 <https://github.com/pybind/pybind11/pull/4856>`_
136+
137+
* Fix FindPython mode exports & avoid ``pkg_resources`` if
138+
``importlib.metadata`` available.
139+
`#4941 <https://github.com/pybind/pybind11/pull/4941>`_
140+
141+
* ``Python_ADDITIONAL_VERSIONS`` (classic search) now includes 3.12.
142+
`#4909 <https://github.com/pybind/pybind11/pull/4909>`_
143+
144+
* ``pybind11.pc`` is now relocatable by default as long as install destinations
145+
are not absolute paths.
146+
`#4830 <https://github.com/pybind/pybind11/pull/4830>`_
147+
148+
* Correctly detect CMake FindPython removal when used as a subdirectory.
149+
`#4806 <https://github.com/pybind/pybind11/pull/4806>`_
150+
151+
* Don't require the libs component on CMake 3.18+ when using
152+
PYBIND11_FINDPYTHON (fixes manylinux builds).
153+
`#4805 <https://github.com/pybind/pybind11/pull/4805>`_
154+
155+
* ``pybind11_strip`` is no longer automatically applied when
156+
``CMAKE_BUILD_TYPE`` is unset.
157+
`#4780 <https://github.com/pybind/pybind11/pull/4780>`_
158+
159+
* Support ``DEBUG_POSFIX`` correctly for debug builds.
160+
`#4761 <https://github.com/pybind/pybind11/pull/4761>`_
161+
162+
* Hardcode lto/thin lto for Emscripten cross-compiles.
163+
`#4642 <https://github.com/pybind/pybind11/pull/4642>`_
164+
165+
* Upgrade maximum supported CMake version to 3.27 to fix CMP0148 warnings.
166+
`#4786 <https://github.com/pybind/pybind11/pull/4786>`_
167+
168+
Documentation:
169+
170+
* Small fix to grammar in ``functions.rst``.
171+
`#4791 <https://github.com/pybind/pybind11/pull/4791>`_
172+
173+
* Remove upper bound in example pyproject.toml for setuptools.
174+
`#4774 <https://github.com/pybind/pybind11/pull/4774>`_
175+
176+
CI:
177+
178+
* CI: Update NVHPC to 23.5 and Ubuntu 20.04.
179+
`#4764 <https://github.com/pybind/pybind11/pull/4764>`_
180+
181+
* Test on PyPy 3.10.
182+
`#4714 <https://github.com/pybind/pybind11/pull/4714>`_
183+
184+
Other:
185+
186+
* Use Ruff formatter instead of Black.
187+
`#4912 <https://github.com/pybind/pybind11/pull/4912>`_
188+
189+
* An ``assert()`` was added to help Coverty avoid generating a false positive.
190+
`#4817 <https://github.com/pybind/pybind11/pull/4817>`_
191+
18192

19193
Version 2.11.1 (July 17, 2023)
20-
-----------------------------
194+
------------------------------
21195

22196
Changes:
23197

@@ -32,7 +206,7 @@ Changes:
32206

33207

34208
Version 2.11.0 (July 14, 2023)
35-
-----------------------------
209+
------------------------------
36210

37211
New features:
38212

docs/release.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ If you don't have nox, you should either use ``pipx run nox`` instead, or use
3636

3737
- Run ``nox -s tests_packaging`` to ensure this was done correctly.
3838

39-
- Ensure that all the information in ``setup.cfg`` is up-to-date, like
39+
- Ensure that all the information in ``setup.cfg`` is up-to-date, like
4040
supported Python versions.
4141

42-
- Add release date in ``docs/changelog.rst`` and integrate the output of
43-
``nox -s make_changelog``.
42+
- Add release date in ``docs/changelog.rst`` and integrate the output of
43+
``nox -s make_changelog``.
4444

45-
- Note that the ``make_changelog`` command inspects
46-
`needs changelog <https://github.com/pybind/pybind11/pulls?q=is%3Apr+is%3Aclosed+label%3A%22needs+changelog%22>`_.
45+
- Note that the ``nox -s make_changelog`` command inspects
46+
`needs changelog <https://github.com/pybind/pybind11/pulls?q=is%3Apr+is%3Aclosed+label%3A%22needs+changelog%22>`_.
4747

48-
- Manually clear the ``needs changelog`` labels using the GitHub web
49-
interface (very easy: start by clicking the link above).
48+
- Manually clear the ``needs changelog`` labels using the GitHub web
49+
interface (very easy: start by clicking the link above).
5050

51-
- ``git add`` and ``git commit``, ``git push``. **Ensure CI passes**. (If it
51+
- ``git add`` and ``git commit``, ``git push``. **Ensure CI passes**. (If it
5252
fails due to a known flake issue, either ignore or restart CI.)
5353

5454
- Add a release branch if this is a new MINOR version, or update the existing

docs/upgrade.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,34 @@ to a new version. But it goes into more detail. This includes things like
88
deprecated APIs and their replacements, build system changes, general code
99
modernization and other useful information.
1010

11+
.. _upgrade-guide-2.12:
12+
13+
v2.12
14+
=====
15+
16+
NumPy support has been upgraded to support the 2.x series too. The two relevant
17+
changes are that:
18+
19+
* ``dtype.flags()`` is now a ``uint64`` and ``dtype.alignment()`` an
20+
``ssize_t`` (and NumPy may return an larger than integer value for
21+
``itemsize()`` in NumPy 2.x).
22+
23+
* The long deprecated NumPy function ``PyArray_GetArrayParamsFromObject``
24+
function is not available anymore.
25+
26+
Due to NumPy changes, you may experience difficulties updating to NumPy 2.
27+
Please see the [NumPy 2 migration guide](https://numpy.org/devdocs/numpy_2_0_migration_guide.html) for details.
28+
For example, a more direct change could be that the default integer ``"int_"``
29+
(and ``"uint"``) is now ``ssize_t`` and not ``long`` (affects 64bit windows).
30+
31+
If you want to only support NumPy 1.x for now and are having problems due to
32+
the two internal changes listed above, you can define
33+
``PYBIND11_NUMPY_1_ONLY`` to disable the new support for now. Make sure you
34+
define this on all pybind11 compile units, since it could be a source of ODR
35+
violations if used inconsistently. This option will be removed in the future,
36+
so adapting your code is highly recommended.
37+
38+
1139
.. _upgrade-guide-2.11:
1240

1341
v2.11

0 commit comments

Comments
 (0)