Skip to content

Migrate to Pybind11 v3 #30291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ py_mod = import('python')
py3 = py_mod.find_installation(pure: false)
py3_dep = py3.dependency()

pybind11_dep = dependency('pybind11', version: '>=2.13.2')
pybind11_dep = dependency('pybind11', version: '>=3')

subdir('extern')
subdir('src')
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ requires-python = ">=3.11"
# Should be a copy of the build dependencies below.
dev = [
"meson-python>=0.13.1,!=0.17.*",
"pybind11>=2.13.2,!=2.13.3",
"pybind11>=3",
"setuptools_scm>=7",
# Not required by us but setuptools_scm without a version, cso _if_
# installed, then setuptools_scm 8 requires at least this version.
Expand All @@ -73,7 +73,7 @@ requires = [
# meson-python 0.17.x breaks symlinks in sdists. You can remove this pin if
# you really need it and aren't using an sdist.
"meson-python>=0.13.1,!=0.17.*",
"pybind11>=2.13.2,!=2.13.3",
"pybind11>=3",
"setuptools_scm>=7",
]

Expand Down
2 changes: 1 addition & 1 deletion requirements/dev/build-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pybind11>=2.13.2,!=2.13.3
pybind11>=3
meson-python
setuptools-scm
14 changes: 11 additions & 3 deletions src/_backend_agg_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
#include <pybind11/subinterpreter.h>
#endif

#include "mplutils.h"
#include "py_converters.h"
#include "_backend_agg.h"
Expand Down Expand Up @@ -214,9 +218,13 @@ PyRendererAgg_draw_gouraud_triangles(RendererAgg *self,
self->draw_gouraud_triangles(gc, points, colors, trans);
}

PYBIND11_MODULE(_backend_agg, m, py::mod_gil_not_used())
PYBIND11_MODULE(_backend_agg, m, py::mod_gil_not_used()
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
,py::multiple_interpreters::per_interpreter_gil()
#endif
)
{
py::class_<RendererAgg>(m, "RendererAgg", py::buffer_protocol())
py::classh<RendererAgg>(m, "RendererAgg", py::buffer_protocol())
.def(py::init<unsigned int, unsigned int, double>(),
"width"_a, "height"_a, "dpi"_a)

Expand Down Expand Up @@ -266,7 +274,7 @@ PYBIND11_MODULE(_backend_agg, m, py::mod_gil_not_used())
return py::buffer_info(renderer->pixBuffer, shape, strides);
});

py::class_<BufferRegion>(m, "BufferRegion", py::buffer_protocol())
py::classh<BufferRegion>(m, "BufferRegion", py::buffer_protocol())
// BufferRegion is not constructible from Python, thus no py::init is added.
.def("set_x", &PyBufferRegion_set_x)
.def("set_y", &PyBufferRegion_set_y)
Expand Down
95 changes: 0 additions & 95 deletions src/_enums.h

This file was deleted.

15 changes: 12 additions & 3 deletions src/_image_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include <pybind11/pybind11.h>
#include <pybind11/native_enum.h>
#include <pybind11/numpy.h>
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
#include <pybind11/subinterpreter.h>
#endif

#include <algorithm>

Expand Down Expand Up @@ -278,9 +282,13 @@ calculate_rms_and_diff(py::array_t<unsigned char> expected_image,
}


PYBIND11_MODULE(_image, m, py::mod_gil_not_used())
PYBIND11_MODULE(_image, m, py::mod_gil_not_used()
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
,py::multiple_interpreters::per_interpreter_gil()
#endif
)
{
py::enum_<interpolation_e>(m, "_InterpolationType")
py::native_enum<interpolation_e>(m, "_InterpolationType", "enum.Enum")
.value("NEAREST", NEAREST)
.value("BILINEAR", BILINEAR)
.value("BICUBIC", BICUBIC)
Expand All @@ -298,7 +306,8 @@ PYBIND11_MODULE(_image, m, py::mod_gil_not_used())
.value("SINC", SINC)
.value("LANCZOS", LANCZOS)
.value("BLACKMAN", BLACKMAN)
.export_values();
.export_values()
.finalize();

m.def("resample", &image_resample,
"input_array"_a,
Expand Down
9 changes: 8 additions & 1 deletion src/_path_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
#include <pybind11/subinterpreter.h>
#endif

#include <array>
#include <limits>
Expand Down Expand Up @@ -310,7 +313,11 @@ Py_is_sorted_and_has_non_nan(py::object obj)
return result;
}

PYBIND11_MODULE(_path, m, py::mod_gil_not_used())
PYBIND11_MODULE(_path, m, py::mod_gil_not_used()
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
,py::multiple_interpreters::per_interpreter_gil()
#endif
)
{
m.def("point_in_path", &Py_point_in_path,
"x"_a, "y"_a, "radius"_a, "path"_a, "trans"_a);
Expand Down
9 changes: 8 additions & 1 deletion src/_qhull_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
*/
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
#include <pybind11/subinterpreter.h>
#endif

#ifdef _MSC_VER
/* The Qhull header does not declare this as extern "C", but only MSVC seems to
Expand Down Expand Up @@ -276,7 +279,11 @@ delaunay(const CoordArray& x, const CoordArray& y, int verbose)
return delaunay_impl(npoints, x.data(), y.data(), verbose == 0);
}

PYBIND11_MODULE(_qhull, m, py::mod_gil_not_used())
PYBIND11_MODULE(_qhull, m, py::mod_gil_not_used()
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
,py::multiple_interpreters::per_interpreter_gil()
#endif
)
{
m.doc() = "Computing Delaunay triangulations.\n";

Expand Down
6 changes: 2 additions & 4 deletions src/ft2font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
you have disabled hints).
*/

FT_Library _ft2Library;

FT2Image::FT2Image(unsigned long width, unsigned long height)
: m_buffer((unsigned char *)calloc(width * height, 1)), m_width(width), m_height(height)
{
Expand Down Expand Up @@ -207,7 +205,7 @@ FT2Font::get_path(std::vector<double> &vertices, std::vector<unsigned char> &cod
codes.push_back(CLOSEPOLY);
}

FT2Font::FT2Font(FT_Open_Args &open_args,
FT2Font::FT2Font(FT_Library ft2Library, FT_Open_Args &open_args,
long hinting_factor_,
std::vector<FT2Font *> &fallback_list,
FT2Font::WarnFunc warn, bool warn_if_used)
Expand All @@ -217,7 +215,7 @@ FT2Font::FT2Font(FT_Open_Args &open_args,
kerning_factor(0)
{
clear();
FT_CHECK(FT_Open_Face, _ft2Library, &open_args, 0, &face);
FT_CHECK(FT_Open_Face, ft2Library, &open_args, 0, &face);
if (open_args.stream != nullptr) {
face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
}
Expand Down
4 changes: 1 addition & 3 deletions src/ft2font.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,12 @@ class FT2Image
FT2Image &operator=(const FT2Image &);
};

extern FT_Library _ft2Library;

class FT2Font
{
typedef void (*WarnFunc)(FT_ULong charcode, std::set<FT_String*> family_names);

public:
FT2Font(FT_Open_Args &open_args, long hinting_factor,
FT2Font(FT_Library ft2Library, FT_Open_Args &open_args, long hinting_factor,
std::vector<FT2Font *> &fallback_list,
WarnFunc warn, bool warn_if_used);
virtual ~FT2Font();
Expand Down
Loading
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy