Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac59ca8

Browse files
committed
Remove NumPy from extensions entirely
This should be replaced by pybind11 in all cases now.
1 parent ef9826e commit ac59ca8

File tree

10 files changed

+8
-682
lines changed

10 files changed

+8
-682
lines changed

.github/workflows/tests.yml

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

pyproject.toml

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

9077
[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_wrapper.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
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"
87

@@ -188,14 +187,6 @@ PyRendererAgg_draw_gouraud_triangles(RendererAgg *self,
188187

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

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: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
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"
@@ -266,7 +264,7 @@ Py_cleanup_path(mpl::PathIterator path, agg::trans_affine trans, bool remove_nan
266264
bool do_clip = (clip_rect.x1 < clip_rect.x2 && clip_rect.y1 < clip_rect.y2);
267265

268266
std::vector<double> vertices;
269-
std::vector<npy_uint8> codes;
267+
std::vector<uint8_t> codes;
270268

271269
cleanup_path(path, trans, remove_nans, do_clip, clip_rect, snap_mode, stroke_width,
272270
*simplify, return_curves, sketch, vertices, codes);
@@ -374,14 +372,6 @@ Py_is_sorted_and_has_non_nan(py::object obj)
374372

375373
PYBIND11_MODULE(_path, m)
376374
{
377-
auto ia = [m]() -> const void* {
378-
import_array();
379-
return &m;
380-
};
381-
if (ia() == NULL) {
382-
throw py::error_already_set();
383-
}
384-
385375
m.def("point_in_path", &Py_point_in_path,
386376
"x"_a, "y"_a, "radius"_a, "path"_a, "trans"_a);
387377
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
}

src/meson.build

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,3 @@
1-
# NumPy include directory - needed in all submodules
2-
# The try-except is needed because when things are split across drives on Windows, there
3-
# is no relative path and an exception gets raised. There may be other such cases, so add
4-
# a catch-all and switch to an absolute path. Relative paths are needed when for example
5-
# a virtualenv is placed inside the source tree; Meson rejects absolute paths to places
6-
# inside the source tree.
7-
# For cross-compilation it is often not possible to run the Python interpreter in order
8-
# to retrieve numpy's include directory. It can be specified in the cross file instead:
9-
#
10-
# [properties]
11-
# numpy-include-dir = /abspath/to/host-pythons/site-packages/numpy/core/include
12-
#
13-
# This uses the path as is, and avoids running the interpreter.
14-
incdir_numpy = meson.get_external_property('numpy-include-dir', 'not-given')
15-
if incdir_numpy == 'not-given'
16-
incdir_numpy = run_command(py3,
17-
[
18-
'-c',
19-
'''import os
20-
import numpy as np
21-
try:
22-
incdir = os.path.relpath(np.get_include())
23-
except Exception:
24-
incdir = np.get_include()
25-
print(incdir)'''
26-
],
27-
check: true
28-
).stdout().strip()
29-
endif
30-
numpy_dep = declare_dependency(
31-
compile_args: [
32-
'-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION',
33-
# Allow NumPy's printf format specifiers in C++.
34-
'-D__STDC_FORMAT_MACROS=1',
35-
],
36-
include_directories: include_directories(incdir_numpy),
37-
dependencies: py3_dep,
38-
)
39-
401
# For cross-compilation it is often not possible to run the Python interpreter in order
412
# to retrieve the platform-specific /dev/null. It can be specified in the cross file
423
# instead:
@@ -76,7 +37,7 @@ extension_data = {
7637
'_backend_agg.cpp',
7738
'_backend_agg_wrapper.cpp',
7839
),
79-
'dependencies': [agg_dep, numpy_dep, freetype_dep, pybind11_dep],
40+
'dependencies': [agg_dep, freetype_dep, pybind11_dep],
8041
},
8142
'_c_internal_utils': {
8243
'subdir': 'matplotlib',
@@ -92,7 +53,7 @@ extension_data = {
9253
'ft2font_wrapper.cpp',
9354
),
9455
'dependencies': [
95-
freetype_dep, pybind11_dep, numpy_dep, agg_dep.partial_dependency(includes: true),
56+
freetype_dep, pybind11_dep, agg_dep.partial_dependency(includes: true),
9657
],
9758
'cpp_args': [
9859
'-DFREETYPE_BUILD_TYPE="@0@"'.format(
@@ -117,7 +78,7 @@ extension_data = {
11778
'sources': files(
11879
'_path_wrapper.cpp',
11980
),
120-
'dependencies': [numpy_dep, agg_dep, pybind11_dep],
81+
'dependencies': [agg_dep, pybind11_dep],
12182
},
12283
'_qhull': {
12384
'subdir': 'matplotlib',
@@ -157,16 +118,7 @@ extension_data = {
157118
}
158119

159120
foreach ext, kwargs : extension_data
160-
# Ensure that PY_ARRAY_UNIQUE_SYMBOL is uniquely defined for each extension.
161-
unique_array_api = '-DPY_ARRAY_UNIQUE_SYMBOL=MPL_@0@_ARRAY_API'.format(ext.replace('.', '_'))
162-
additions = {
163-
'c_args': [unique_array_api] + kwargs.get('c_args', []),
164-
'cpp_args': [unique_array_api] + kwargs.get('cpp_args', []),
165-
}
166-
py3.extension_module(
167-
ext,
168-
install: true,
169-
kwargs: kwargs + additions)
121+
py3.extension_module(ext, install: true, kwargs: kwargs)
170122
endforeach
171123

172124
if get_option('macosx') and host_machine.system() == 'darwin'

0 commit comments

Comments
 (0)