Skip to content

Commit 592c123

Browse files
authored
Merge pull request matplotlib#28857 from QuLogic/pybind11-cleanup
Pybind11 cleanup
2 parents f5e74e1 + 6ad4e7d commit 592c123

19 files changed

+186
-1586
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ jobs:
260260
# Preinstall build requirements to enable no-build-isolation builds.
261261
python -m pip install --upgrade $PRE \
262262
'contourpy>=1.0.1' cycler fonttools kiwisolver importlib_resources \
263-
numpy packaging pillow 'pyparsing!=3.1.0' python-dateutil setuptools-scm \
263+
packaging pillow 'pyparsing!=3.1.0' python-dateutil setuptools-scm \
264264
'meson-python>=0.13.1' 'pybind11>=2.6' \
265265
-r requirements/testing/all.txt \
266266
${{ matrix.extra-requirements }}

pyproject.toml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ requires-python = ">=3.10"
4747
# Should be a copy of the build dependencies below.
4848
dev = [
4949
"meson-python>=0.13.1",
50-
"numpy>=1.25",
5150
"pybind11>=2.6,!=2.13.3",
5251
"setuptools_scm>=7",
5352
# Not required by us but setuptools_scm without a version, cso _if_
@@ -74,18 +73,6 @@ requires = [
7473
"meson-python>=0.13.1",
7574
"pybind11>=2.6,!=2.13.3",
7675
"setuptools_scm>=7",
77-
78-
# Comments on numpy build requirement range:
79-
#
80-
# 1. >=2.0.x is the numpy requirement for wheel builds for distribution
81-
# on PyPI - building against 2.x yields wheels that are also
82-
# ABI-compatible with numpy 1.x at runtime.
83-
# 2. Note that building against numpy 1.x works fine too - users and
84-
# redistributors can do this by installing the numpy version they like
85-
# and disabling build isolation.
86-
# 3. The <2.3 upper bound is for matching the numpy deprecation policy,
87-
# it should not be loosened.
88-
"numpy>=2.0.0rc1,<2.3",
8976
]
9077

9178
[tool.meson-python.args]
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
pybind11!=2.13.3
22
meson-python
3-
numpy<2.1.0
43
setuptools-scm

requirements/testing/mypy.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ contourpy>=1.0.1
1818
cycler>=0.10
1919
fonttools>=4.22.0
2020
kiwisolver>=1.3.1
21-
numpy>=1.19
2221
packaging>=20.0
2322
pillow>=8
2423
pyparsing>=2.3.1

src/_backend_agg.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,11 +1234,11 @@ inline void RendererAgg::draw_gouraud_triangles(GCAgg &gc,
12341234
ColorArray &colors,
12351235
agg::trans_affine &trans)
12361236
{
1237-
if (points.shape(0) && !check_trailing_shape(points, "points", 3, 2)) {
1238-
throw py::error_already_set();
1237+
if (points.shape(0)) {
1238+
check_trailing_shape(points, "points", 3, 2);
12391239
}
1240-
if (colors.shape(0) && !check_trailing_shape(colors, "colors", 3, 4)) {
1241-
throw py::error_already_set();
1240+
if (colors.shape(0)) {
1241+
check_trailing_shape(colors, "colors", 3, 4);
12421242
}
12431243
if (points.shape(0) != colors.shape(0)) {
12441244
throw py::value_error(

src/_backend_agg_wrapper.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
#include <pybind11/numpy.h>
33
#include <pybind11/stl.h>
44
#include "mplutils.h"
5-
#include "numpy_cpp.h"
65
#include "py_converters.h"
76
#include "_backend_agg.h"
8-
#include "py_converters_11.h"
97

108
namespace py = pybind11;
119
using namespace pybind11::literals;
@@ -189,14 +187,6 @@ PyRendererAgg_draw_gouraud_triangles(RendererAgg *self,
189187

190188
PYBIND11_MODULE(_backend_agg, m)
191189
{
192-
auto ia = [m]() -> const void* {
193-
import_array();
194-
return &m;
195-
};
196-
if (ia() == NULL) {
197-
throw py::error_already_set();
198-
}
199-
200190
py::class_<RendererAgg>(m, "RendererAgg", py::buffer_protocol())
201191
.def(py::init<unsigned int, unsigned int, double>(),
202192
"width"_a, "height"_a, "dpi"_a)

src/_image_wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <pybind11/numpy.h>
33

44
#include "_image_resample.h"
5-
#include "py_converters_11.h"
5+
#include "py_converters.h"
66

77
namespace py = pybind11;
88
using namespace pybind11::literals;

src/_path.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#include "path_converters.h"
2020
#include "_backend_agg_basic_types.h"
21-
#include "numpy_cpp.h"
2221

2322
const size_t NUM_VERTICES[] = { 1, 1, 1, 2, 3 };
2423

@@ -1004,15 +1003,15 @@ void convert_path_to_polygons(PathIterator &path,
10041003

10051004
template <class VertexSource>
10061005
void
1007-
__cleanup_path(VertexSource &source, std::vector<double> &vertices, std::vector<npy_uint8> &codes)
1006+
__cleanup_path(VertexSource &source, std::vector<double> &vertices, std::vector<uint8_t> &codes)
10081007
{
10091008
unsigned code;
10101009
double x, y;
10111010
do {
10121011
code = source.vertex(&x, &y);
10131012
vertices.push_back(x);
10141013
vertices.push_back(y);
1015-
codes.push_back((npy_uint8)code);
1014+
codes.push_back(static_cast<uint8_t>(code));
10161015
} while (code != agg::path_cmd_stop);
10171016
}
10181017

src/_path_wrapper.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@
77
#include <string>
88
#include <vector>
99

10-
#include "numpy_cpp.h"
11-
1210
#include "_path.h"
1311

1412
#include "_backend_agg_basic_types.h"
1513
#include "py_adaptors.h"
1614
#include "py_converters.h"
17-
#include "py_converters_11.h"
1815

1916
namespace py = pybind11;
2017
using namespace pybind11::literals;
@@ -184,9 +181,7 @@ Py_affine_transform(py::array_t<double, py::array::c_style | py::array::forcecas
184181
if (vertices_arr.ndim() == 2) {
185182
auto vertices = vertices_arr.unchecked<2>();
186183

187-
if(!check_trailing_shape(vertices, "vertices", 2)) {
188-
throw py::error_already_set();
189-
}
184+
check_trailing_shape(vertices, "vertices", 2);
190185

191186
py::ssize_t dims[] = { vertices.shape(0), 2 };
192187
py::array_t<double> result(dims);
@@ -267,7 +262,7 @@ Py_cleanup_path(mpl::PathIterator path, agg::trans_affine trans, bool remove_nan
267262
bool do_clip = (clip_rect.x1 < clip_rect.x2 && clip_rect.y1 < clip_rect.y2);
268263

269264
std::vector<double> vertices;
270-
std::vector<npy_uint8> codes;
265+
std::vector<uint8_t> codes;
271266

272267
cleanup_path(path, trans, remove_nans, do_clip, clip_rect, snap_mode, stroke_width,
273268
*simplify, return_curves, sketch, vertices, codes);
@@ -375,14 +370,6 @@ Py_is_sorted_and_has_non_nan(py::object obj)
375370

376371
PYBIND11_MODULE(_path, m)
377372
{
378-
auto ia = [m]() -> const void* {
379-
import_array();
380-
return &m;
381-
};
382-
if (ia() == NULL) {
383-
throw py::error_already_set();
384-
}
385-
386373
m.def("point_in_path", &Py_point_in_path,
387374
"x"_a, "y"_a, "radius"_a, "path"_a, "trans"_a);
388375
m.def("points_in_path", &Py_points_in_path,

src/ft2font_wrapper.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <pybind11/stl.h>
55

66
#include "ft2font.h"
7-
#include "numpy/arrayobject.h"
87

98
#include <set>
109
#include <sstream>
@@ -955,14 +954,6 @@ PyFT2Font_fname(PyFT2Font *self)
955954

956955
PYBIND11_MODULE(ft2font, m)
957956
{
958-
auto ia = [m]() -> const void* {
959-
import_array();
960-
return &m;
961-
};
962-
if (ia() == NULL) {
963-
throw py::error_already_set();
964-
}
965-
966957
if (FT_Init_FreeType(&_ft2Library)) { // initialize library
967958
throw std::runtime_error("Could not initialize the freetype2 library");
968959
}

0 commit comments

Comments
 (0)