Skip to content

Commit

Permalink
Merge branch 'sh_merge_master' into pybind11k_merge_sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Aug 15, 2024
2 parents 77bb65c + 205da0d commit b4a424e
Show file tree
Hide file tree
Showing 23 changed files with 165 additions and 300 deletions.
10 changes: 5 additions & 5 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ nox -s build
### Full setup

To setup an ideal development environment, run the following commands on a
system with CMake 3.14+:
system with CMake 3.15+:

```bash
python3 -m venv venv
Expand All @@ -96,8 +96,8 @@ Tips:
* You can use `virtualenv` (faster, from PyPI) instead of `venv`.
* You can select any name for your environment folder; if it contains "env" it
will be ignored by git.
* If you don't have CMake 3.14+, just add "cmake" to the pip install command.
* You can use `-DPYBIND11_FINDPYTHON=ON` to use FindPython on CMake 3.12+
* If you don't have CMake 3.15+, just add "cmake" to the pip install command.
* You can use `-DPYBIND11_FINDPYTHON=ON` to use FindPython.
* In classic mode, you may need to set `-DPYTHON_EXECUTABLE=/path/to/python`.
FindPython uses `-DPython_ROOT_DIR=/path/to` or
`-DPython_EXECUTABLE=/path/to/python`.
Expand Down Expand Up @@ -149,8 +149,8 @@ To run the tests, you can "build" the check target:
cmake --build build --target check
```

`--target` can be spelled `-t` in CMake 3.15+. You can also run individual
tests with these targets:
`--target` can be spelled `-t`. You can also run individual tests with these
targets:

* `pytest`: Python tests only, using the
[pytest](https://docs.pytest.org/en/stable/) framework
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ jobs:
include:
- runs-on: ubuntu-20.04
arch: x64
cmake: "3.5"
cmake: "3.15"

- runs-on: ubuntu-20.04
arch: x64
cmake: "3.29"

- runs-on: macos-13
arch: x64
cmake: "3.8"
cmake: "3.15"

- runs-on: windows-2019
arch: x64 # x86 compilers seem to be missing on 2019 image
Expand Down
57 changes: 10 additions & 47 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,15 @@ if(NOT CMAKE_VERSION VERSION_LESS "3.27")
cmake_policy(GET CMP0148 _pybind11_cmp0148)
endif()

cmake_minimum_required(VERSION 3.5)

# The `cmake_minimum_required(VERSION 3.5...3.29)` syntax does not work with
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
# the behavior using the following workaround:
if(${CMAKE_VERSION} VERSION_LESS 3.29)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.29)
endif()
cmake_minimum_required(VERSION 3.15...3.30)

if(_pybind11_cmp0148)
cmake_policy(SET CMP0148 ${_pybind11_cmp0148})
unset(_pybind11_cmp0148)
endif()

# Avoid infinite recursion if tests include this as a subdirectory
if(DEFINED PYBIND11_MASTER_PROJECT)
return()
endif()
include_guard(GLOBAL)

# Extract project version from source
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/pybind11/detail/common.h"
Expand Down Expand Up @@ -74,14 +63,6 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)

set(PYBIND11_MASTER_PROJECT ON)

if(OSX AND CMAKE_VERSION VERSION_LESS 3.7)
# Bug in macOS CMake < 3.7 is unable to download catch
message(WARNING "CMAKE 3.7+ needed on macOS to download catch, and newer HIGHLY recommended")
elseif(WINDOWS AND CMAKE_VERSION VERSION_LESS 3.8)
# Only tested with 3.8+ in CI.
message(WARNING "CMAKE 3.8+ tested on Windows, previous versions untested")
endif()

message(STATUS "CMake ${CMAKE_VERSION}")

if(CMAKE_CXX_STANDARD)
Expand Down Expand Up @@ -133,8 +114,7 @@ cmake_dependent_option(
"Install pybind11 headers in Python include directory instead of default installation prefix"
OFF "PYBIND11_INSTALL" OFF)

cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" ${_pybind11_findpython_default}
"NOT CMAKE_VERSION VERSION_LESS 3.12" OFF)
option(PYBIND11_FINDPYTHON "Force new FindPython" ${_pybind11_findpython_default})

# Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests
# (makes transition easier while we support both modes).
Expand Down Expand Up @@ -193,7 +173,7 @@ set(PYBIND11_HEADERS
include/pybind11/typing.h)

# Compare with grep and warn if mismatched
if(PYBIND11_MASTER_PROJECT AND NOT CMAKE_VERSION VERSION_LESS 3.12)
if(PYBIND11_MASTER_PROJECT)
file(
GLOB_RECURSE _pybind11_header_check
LIST_DIRECTORIES false
Expand All @@ -211,10 +191,7 @@ if(PYBIND11_MASTER_PROJECT AND NOT CMAKE_VERSION VERSION_LESS 3.12)
endif()
endif()

# CMake 3.12 added list(TRANSFORM <list> PREPEND
# But we can't use it yet
string(REPLACE "include/" "${CMAKE_CURRENT_SOURCE_DIR}/include/" PYBIND11_HEADERS
"${PYBIND11_HEADERS}")
list(TRANSFORM PYBIND11_HEADERS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/")

# Cache variable so this can be used in parent projects
set(pybind11_INCLUDE_DIR
Expand Down Expand Up @@ -284,25 +261,11 @@ if(PYBIND11_INSTALL)
tools/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})

if(CMAKE_VERSION VERSION_LESS 3.14)
# Remove CMAKE_SIZEOF_VOID_P from ConfigVersion.cmake since the library does
# not depend on architecture specific settings or libraries.
set(_PYBIND11_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
unset(CMAKE_SIZEOF_VOID_P)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)

set(CMAKE_SIZEOF_VOID_P ${_PYBIND11_CMAKE_SIZEOF_VOID_P})
else()
# CMake 3.14+ natively supports header-only libraries
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT)
endif()
# CMake natively supports header-only libraries
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced/embedding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ information, see :doc:`/compiling`.

.. code-block:: cmake
cmake_minimum_required(VERSION 3.5...3.29)
cmake_minimum_required(VERSION 3.15...3.30)
project(example)
find_package(pybind11 REQUIRED) # or `add_subdirectory(pybind11)`
Expand Down
23 changes: 22 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,28 @@ New Features:
* Support for Python 3.7 was removed. (Official end-of-life: 2023-06-27).
`#5191 <https://github.com/pybind/pybind11/pull/5191>`_

Support for CMake older than 3.15 and some older compilers will also be removed.
* stl.h ``list|set|map_caster`` were made more user friendly: it is no longer
necessary to explicitly convert Python iterables to ``tuple()``, ``set()``,
or ``map()`` in many common situations.
`#4686 <https://github.com/pybind/pybind11/pull/4686>`_

* Support for CMake older than 3.15 removed. CMake 3.15-3.30 supported.
`#5304 <https://github.com/pybind/pybind11/pull/5304>`_

Version 2.13.4 (August 14, 2024)
--------------------------------

Bug fixes:

* Fix paths with spaces, including on Windows.
(Replaces regression from `#5302 <https://github.com/pybind/pybind11/pull/5302>`_)
`#4874 <https://github.com/pybind/pybind11/pull/4874>`_

Documentation:

* Remove repetitive words.
`#5308 <https://github.com/pybind/pybind11/pull/5308>`_


Version 2.13.3 (August 13, 2024)
--------------------------------
Expand Down
32 changes: 17 additions & 15 deletions docs/compiling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A Python extension module can be created with just a few lines of code:

.. code-block:: cmake
cmake_minimum_required(VERSION 3.15...3.29)
cmake_minimum_required(VERSION 3.15...3.30)
project(example LANGUAGES CXX)
set(PYBIND11_FINDPYTHON ON)
Expand Down Expand Up @@ -319,11 +319,11 @@ Building with CMake

For C++ codebases that have an existing CMake-based build system, a Python
extension module can be created with just a few lines of code, as seen above in
the module section. Pybind11 currently supports a lower minimum if you don't
use the modern FindPython, though be aware that CMake 3.27 removed the old
mechanism, so pybind11 will automatically switch if the old mechanism is not
available. Please opt into the new mechanism if at all possible. Our default
may change in future versions. This is the minimum required:
the module section. Pybind11 currently defaults to the old mechanism, though be
aware that CMake 3.27 removed the old mechanism, so pybind11 will automatically
switch if the old mechanism is not available. Please opt into the new mechanism
if at all possible. Our default may change in future versions. This is the
minimum required:



Expand All @@ -333,6 +333,9 @@ may change in future versions. This is the minimum required:
.. versionchanged:: 2.11
CMake 3.5+ is required.

.. versionchanged:: 2.14
CMake 3.15+ is required.


Further information can be found at :doc:`cmake/index`.

Expand Down Expand Up @@ -444,7 +447,7 @@ See the `Config file`_ docstring for details of relevant CMake variables.

.. code-block:: cmake
cmake_minimum_required(VERSION 3.4...3.18)
cmake_minimum_required(VERSION 3.15...3.30)
project(example LANGUAGES CXX)
find_package(pybind11 REQUIRED)
Expand Down Expand Up @@ -483,14 +486,13 @@ can refer to the same [cmake_example]_ repository for a full sample project
FindPython mode
---------------

CMake 3.12+ (3.15+ recommended, 3.18.2+ ideal) added a new module called
FindPython that had a highly improved search algorithm and modern targets
and tools. If you use FindPython, pybind11 will detect this and use the
existing targets instead:
Modern CMake (3.18.2+ ideal) added a new module called FindPython that had a
highly improved search algorithm and modern targets and tools. If you use
FindPython, pybind11 will detect this and use the existing targets instead:

.. code-block:: cmake
cmake_minimum_required(VERSION 3.15...3.22)
cmake_minimum_required(VERSION 3.15...3.30)
project(example LANGUAGES CXX)
find_package(Python 3.8 COMPONENTS Interpreter Development REQUIRED)
Expand Down Expand Up @@ -541,7 +543,7 @@ available in all modes. The targets provided are:
Just the "linking" part of pybind11:module

``pybind11::module``
Everything for extension modules - ``pybind11::pybind11`` + ``Python::Module`` (FindPython CMake 3.15+) or ``pybind11::python_link_helper``
Everything for extension modules - ``pybind11::pybind11`` + ``Python::Module`` (FindPython) or ``pybind11::python_link_helper``

``pybind11::embed``
Everything for embedding the Python interpreter - ``pybind11::pybind11`` + ``Python::Python`` (FindPython) or Python libs
Expand All @@ -568,7 +570,7 @@ You can use these targets to build complex applications. For example, the

.. code-block:: cmake
cmake_minimum_required(VERSION 3.5...3.29)
cmake_minimum_required(VERSION 3.15...3.30)
project(example LANGUAGES CXX)
find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11)
Expand Down Expand Up @@ -626,7 +628,7 @@ information about usage in C++, see :doc:`/advanced/embedding`.

.. code-block:: cmake
cmake_minimum_required(VERSION 3.5...3.29)
cmake_minimum_required(VERSION 3.15...3.30)
project(example LANGUAGES CXX)
find_package(pybind11 REQUIRED) # or add_subdirectory(pybind11)
Expand Down
16 changes: 8 additions & 8 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ CMake configure line. (Replace ``$(which python)`` with a path to python if
your prefer.)

You can alternatively try ``-DPYBIND11_FINDPYTHON=ON``, which will activate the
new CMake FindPython support instead of pybind11's custom search. Requires
CMake 3.12+, and 3.15+ or 3.18.2+ are even better. You can set this in your
``CMakeLists.txt`` before adding or finding pybind11, as well.
new CMake FindPython support instead of pybind11's custom search. Newer CMake,
like, 3.18.2+, is recommended. You can set this in your ``CMakeLists.txt``
before adding or finding pybind11, as well.

Inconsistent detection of Python version in CMake and pybind11
==============================================================
Expand All @@ -281,11 +281,11 @@ There are three possible solutions:
from CMake and rely on pybind11 in detecting Python version. If this is not
possible, the CMake machinery should be called *before* including pybind11.
2. Set ``PYBIND11_FINDPYTHON`` to ``True`` or use ``find_package(Python
COMPONENTS Interpreter Development)`` on modern CMake (3.12+, 3.15+ better,
3.18.2+ best). Pybind11 in these cases uses the new CMake FindPython instead
of the old, deprecated search tools, and these modules are much better at
finding the correct Python. If FindPythonLibs/Interp are not available
(CMake 3.27+), then this will be ignored and FindPython will be used.
COMPONENTS Interpreter Development)`` on modern CMake ( 3.18.2+ best).
Pybind11 in these cases uses the new CMake FindPython instead of the old,
deprecated search tools, and these modules are much better at finding the
correct Python. If FindPythonLibs/Interp are not available (CMake 3.27+),
then this will be ignored and FindPython will be used.
3. Set ``PYBIND11_NOPYTHON`` to ``TRUE``. Pybind11 will not search for Python.
However, you will have to use the target-based system, and do more setup
yourself, because it does not know about or include things that depend on
Expand Down
8 changes: 4 additions & 4 deletions include/pybind11/stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ struct set_caster {
void reserve_maybe(const anyset &, void *) {}

bool convert_iterable(const iterable &itbl, bool convert) {
for (auto it : itbl) {
for (const auto &it : itbl) {
key_conv conv;
if (!conv.load(it, convert)) {
return false;
Expand Down Expand Up @@ -223,7 +223,7 @@ struct map_caster {
bool convert_elements(const dict &d, bool convert) {
value.clear();
reserve_maybe(d, &value);
for (auto it : d) {
for (const auto &it : d) {
key_conv kconv;
value_conv vconv;
if (!kconv.load(it.first.ptr(), convert) || !vconv.load(it.second.ptr(), convert)) {
Expand Down Expand Up @@ -377,7 +377,7 @@ struct array_caster {
bool convert_elements(handle seq, bool convert) {
auto l = reinterpret_borrow<sequence>(seq);
value.reset(new ArrayType{});
// Using `resize` to preserve the behavior exactly as it was before google/pybind11k#30034
// Using `resize` to preserve the behavior exactly as it was before PR #5305
// For the `resize` to work, `Value` must be default constructible.
// For `std::valarray`, this is a requirement:
// https://en.cppreference.com/w/cpp/named_req/NumericType
Expand Down Expand Up @@ -453,7 +453,7 @@ struct array_caster {
}

// Code copied from PYBIND11_TYPE_CASTER macro.
// Intentionally preserving the behavior exactly as it was before google/pybind11k#30034
// Intentionally preserving the behavior exactly as it was before PR #5305
template <typename T_, enable_if_t<std::is_same<ArrayType, remove_cv_t<T_>>::value, int> = 0>
static handle cast(T_ *src, const return_value_policy_pack &policy, handle parent) {
if (!src) {
Expand Down
Loading

0 comments on commit b4a424e

Please sign in to comment.