Skip to content

Commit abf7493

Browse files
committed
feat: drop PYBIND11_NUMPY_1_ONLY
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 8ef10a0 commit abf7493

File tree

7 files changed

+3
-78
lines changed

7 files changed

+3
-78
lines changed

.github/workflows/ci.yml

-4
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,12 @@ jobs:
149149

150150
# First build - C++11 mode and inplace
151151
# More-or-less randomly adding -DPYBIND11_SIMPLE_GIL_MANAGEMENT=ON here
152-
# (same for PYBIND11_NUMPY_1_ONLY, but requires a NumPy 1.x at runtime).
153152
- name: Configure C++11 ${{ matrix.args }}
154153
run: >
155154
cmake -S . -B .
156155
-DPYBIND11_WERROR=ON
157156
-DPYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION=ON
158157
-DPYBIND11_SIMPLE_GIL_MANAGEMENT=ON
159-
-DPYBIND11_NUMPY_1_ONLY=ON
160158
-DPYBIND11_PYTEST_ARGS=-v
161159
-DDOWNLOAD_CATCH=ON
162160
-DDOWNLOAD_EIGEN=ON
@@ -180,13 +178,11 @@ jobs:
180178

181179
# Second build - C++17 mode and in a build directory
182180
# More-or-less randomly adding -DPYBIND11_SIMPLE_GIL_MANAGEMENT=OFF here.
183-
# (same for PYBIND11_NUMPY_1_ONLY, but requires a NumPy 1.x at runtime).
184181
- name: Configure C++17
185182
run: >
186183
cmake -S . -B build2
187184
-DPYBIND11_WERROR=ON
188185
-DPYBIND11_SIMPLE_GIL_MANAGEMENT=OFF
189-
-DPYBIND11_NUMPY_1_ONLY=ON
190186
-DPYBIND11_PYTEST_ARGS=-v
191187
-DDOWNLOAD_CATCH=ON
192188
-DDOWNLOAD_EIGEN=ON

CMakeLists.txt

-5
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ option(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION
9292
"To enforce that a handle_type_name<> specialization exists" OFF)
9393
option(PYBIND11_SIMPLE_GIL_MANAGEMENT
9494
"Use simpler GIL management logic that does not support disassociation" OFF)
95-
option(PYBIND11_NUMPY_1_ONLY
96-
"Disable NumPy 2 support to avoid changes to previous pybind11 versions." OFF)
9795
set(PYBIND11_INTERNALS_VERSION
9896
""
9997
CACHE STRING "Override the ABI version, may be used to enable the unstable ABI.")
@@ -105,9 +103,6 @@ endif()
105103
if(PYBIND11_SIMPLE_GIL_MANAGEMENT)
106104
add_compile_definitions(PYBIND11_SIMPLE_GIL_MANAGEMENT)
107105
endif()
108-
if(PYBIND11_NUMPY_1_ONLY)
109-
add_compile_definitions(PYBIND11_NUMPY_1_ONLY)
110-
endif()
111106

112107
cmake_dependent_option(
113108
USE_PYTHON_INCLUDE_DIR

include/pybind11/detail/common.h

-4
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,6 @@
251251
# endif
252252
#endif
253253

254-
#if defined(PYBIND11_NUMPY_1_ONLY)
255-
# define PYBIND11_INTERNAL_NUMPY_1_ONLY_DETECTED
256-
#endif
257-
258254
#if (defined(PYPY_VERSION) || defined(GRAALVM_PYTHON)) && !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
259255
# define PYBIND11_SIMPLE_GIL_MANAGEMENT
260256
#endif

include/pybind11/numpy.h

+2-51
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
#include <utility>
3030
#include <vector>
3131

32-
#if defined(PYBIND11_NUMPY_1_ONLY) && !defined(PYBIND11_INTERNAL_NUMPY_1_ONLY_DETECTED)
33-
# error PYBIND11_NUMPY_1_ONLY must be defined before any pybind11 header is included.
34-
#endif
35-
3632
/* This will be true on all flat address space platforms and allows us to reduce the
3733
whole npy_intp / ssize_t / Py_intptr_t business down to just ssize_t for all size
3834
and dimension types (e.g. shape, strides, indexing), instead of inflicting this
@@ -80,7 +76,6 @@ struct PyArrayDescr1_Proxy {
8076
PyObject *names;
8177
};
8278

83-
#ifndef PYBIND11_NUMPY_1_ONLY
8479
struct PyArrayDescr_Proxy {
8580
PyObject_HEAD
8681
PyObject *typeobj;
@@ -91,10 +86,6 @@ struct PyArrayDescr_Proxy {
9186
int type_num;
9287
/* Additional fields are NumPy version specific. */
9388
};
94-
#else
95-
/* NumPy 1.x only, we can expose all fields */
96-
using PyArrayDescr_Proxy = PyArrayDescr1_Proxy;
97-
#endif
9889

9990
/* NumPy 2 proxy, including legacy fields */
10091
struct PyArrayDescr2_Proxy {
@@ -179,14 +170,6 @@ PYBIND11_NOINLINE module_ import_numpy_core_submodule(const char *submodule_name
179170
object numpy_version = numpy_lib.attr("NumpyVersion")(version_string);
180171
int major_version = numpy_version.attr("major").cast<int>();
181172

182-
#ifdef PYBIND11_NUMPY_1_ONLY
183-
if (major_version >= 2) {
184-
throw std::runtime_error(
185-
"This extension was built with PYBIND11_NUMPY_1_ONLY defined, "
186-
"but NumPy 2 is used in this process. For NumPy2 compatibility, "
187-
"this extension needs to be rebuilt without the PYBIND11_NUMPY_1_ONLY define.");
188-
}
189-
#endif
190173
/* `numpy.core` was renamed to `numpy._core` in NumPy 2.0 as it officially
191174
became a private module. */
192175
std::string numpy_core_path = major_version >= 2 ? "numpy._core" : "numpy.core";
@@ -300,16 +283,6 @@ struct npy_api {
300283
PyObject *(*PyArray_FromAny_)(PyObject *, PyObject *, int, int, int, PyObject *);
301284
int (*PyArray_DescrConverter_)(PyObject *, PyObject **);
302285
bool (*PyArray_EquivTypes_)(PyObject *, PyObject *);
303-
#ifdef PYBIND11_NUMPY_1_ONLY
304-
int (*PyArray_GetArrayParamsFromObject_)(PyObject *,
305-
PyObject *,
306-
unsigned char,
307-
PyObject **,
308-
int *,
309-
Py_intptr_t *,
310-
PyObject **,
311-
PyObject *);
312-
#endif
313286
PyObject *(*PyArray_Squeeze_)(PyObject *);
314287
// Unused. Not removed because that affects ABI of the class.
315288
int (*PyArray_SetBaseObject_)(PyObject *, PyObject *);
@@ -337,9 +310,6 @@ struct npy_api {
337310
API_PyArray_View = 137,
338311
API_PyArray_DescrConverter = 174,
339312
API_PyArray_EquivTypes = 182,
340-
#ifdef PYBIND11_NUMPY_1_ONLY
341-
API_PyArray_GetArrayParamsFromObject = 278,
342-
#endif
343313
API_PyArray_SetBaseObject = 282
344314
};
345315

@@ -374,9 +344,6 @@ struct npy_api {
374344
DECL_NPY_API(PyArray_View);
375345
DECL_NPY_API(PyArray_DescrConverter);
376346
DECL_NPY_API(PyArray_EquivTypes);
377-
#ifdef PYBIND11_NUMPY_1_ONLY
378-
DECL_NPY_API(PyArray_GetArrayParamsFromObject);
379-
#endif
380347
DECL_NPY_API(PyArray_SetBaseObject);
381348

382349
#undef DECL_NPY_API
@@ -760,21 +727,14 @@ class dtype : public object {
760727
}
761728

762729
/// Size of the data type in bytes.
763-
#ifdef PYBIND11_NUMPY_1_ONLY
764-
ssize_t itemsize() const { return detail::array_descriptor_proxy(m_ptr)->elsize; }
765-
#else
766730
ssize_t itemsize() const {
767731
if (detail::npy_api::get().PyArray_RUNTIME_VERSION_ < 0x12) {
768732
return detail::array_descriptor1_proxy(m_ptr)->elsize;
769733
}
770734
return detail::array_descriptor2_proxy(m_ptr)->elsize;
771735
}
772-
#endif
773736

774737
/// Returns true for structured data types.
775-
#ifdef PYBIND11_NUMPY_1_ONLY
776-
bool has_fields() const { return detail::array_descriptor_proxy(m_ptr)->names != nullptr; }
777-
#else
778738
bool has_fields() const {
779739
if (detail::npy_api::get().PyArray_RUNTIME_VERSION_ < 0x12) {
780740
return detail::array_descriptor1_proxy(m_ptr)->names != nullptr;
@@ -785,7 +745,6 @@ class dtype : public object {
785745
}
786746
return proxy->names != nullptr;
787747
}
788-
#endif
789748

790749
/// Single-character code for dtype's kind.
791750
/// For example, floating point types are 'f' and integral types are 'i'.
@@ -824,29 +783,21 @@ class dtype : public object {
824783
/// Single character for byteorder
825784
char byteorder() const { return detail::array_descriptor_proxy(m_ptr)->byteorder; }
826785

827-
/// Alignment of the data type
828-
#ifdef PYBIND11_NUMPY_1_ONLY
829-
int alignment() const { return detail::array_descriptor_proxy(m_ptr)->alignment; }
830-
#else
786+
/// Alignment of the data type
831787
ssize_t alignment() const {
832788
if (detail::npy_api::get().PyArray_RUNTIME_VERSION_ < 0x12) {
833789
return detail::array_descriptor1_proxy(m_ptr)->alignment;
834790
}
835791
return detail::array_descriptor2_proxy(m_ptr)->alignment;
836792
}
837-
#endif
838793

839-
/// Flags for the array descriptor
840-
#ifdef PYBIND11_NUMPY_1_ONLY
841-
char flags() const { return detail::array_descriptor_proxy(m_ptr)->flags; }
842-
#else
794+
/// Flags for the array descriptor
843795
std::uint64_t flags() const {
844796
if (detail::npy_api::get().PyArray_RUNTIME_VERSION_ < 0x12) {
845797
return (unsigned char) detail::array_descriptor1_proxy(m_ptr)->flags;
846798
}
847799
return detail::array_descriptor2_proxy(m_ptr)->flags;
848800
}
849-
#endif
850801

851802
private:
852803
static object &_dtype_from_pep3118() {

tests/conftest.py

-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ def pytest_report_header():
229229
f"{pybind11_tests.cpp_std}",
230230
f"{pybind11_tests.PYBIND11_INTERNALS_ID}",
231231
f"PYBIND11_SIMPLE_GIL_MANAGEMENT={pybind11_tests.PYBIND11_SIMPLE_GIL_MANAGEMENT}",
232-
f"PYBIND11_NUMPY_1_ONLY={pybind11_tests.PYBIND11_NUMPY_1_ONLY}",
233232
]
234233
if "__graalpython__" in sys.modules:
235234
cpp_info.append(

tests/pybind11_tests.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ PYBIND11_MODULE(pybind11_tests, m, py::mod_gil_not_used()) {
9797
#else
9898
false;
9999
#endif
100-
m.attr("PYBIND11_NUMPY_1_ONLY") =
101-
#if defined(PYBIND11_NUMPY_1_ONLY)
102-
true;
103-
#else
104-
false;
105-
#endif
106100

107101
bind_ConstructorStats(m);
108102

tests/test_numpy_dtypes.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pytest
66

77
import env # noqa: F401
8-
from pybind11_tests import PYBIND11_NUMPY_1_ONLY
98
from pybind11_tests import numpy_dtypes as m
109

1110
np = pytest.importorskip("numpy")
@@ -181,12 +180,7 @@ def test_dtype(simple_dtype):
181180
assert m.test_dtype_num() == [np.dtype(ch).num for ch in expected_chars]
182181
assert m.test_dtype_byteorder() == [np.dtype(ch).byteorder for ch in expected_chars]
183182
assert m.test_dtype_alignment() == [np.dtype(ch).alignment for ch in expected_chars]
184-
if not PYBIND11_NUMPY_1_ONLY:
185-
assert m.test_dtype_flags() == [np.dtype(ch).flags for ch in expected_chars]
186-
else:
187-
assert m.test_dtype_flags() == [
188-
chr(np.dtype(ch).flags) for ch in expected_chars
189-
]
183+
assert m.test_dtype_flags() == [np.dtype(ch).flags for ch in expected_chars]
190184

191185
for a, b in m.test_dtype_num_of():
192186
assert a == b

0 commit comments

Comments
 (0)