Skip to content

Commit de98f71

Browse files
committed
Bump to pybind11>=2.5 to simplify build.
1 parent 82ed1ef commit de98f71

File tree

4 files changed

+8
-52
lines changed

4 files changed

+8
-52
lines changed

CHANGELOG.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
next
22
====
33

4-
- Dropped support for Py3.5.
4+
- Bumped dependencies to Python≥3.6, pybind11≥2.5.
55
- ``pybind11`` is now a ``setup_requires`` and ``-march=native`` is no longer
66
passed as compilation option by default; drop support for
77
``MPLCAIRO_BUILD_TYPE``.

README.rst

+3-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ mplcairo requires
6363

6464
Additionally, building mplcairo from source requires
6565

66-
- pybind11≥2.2.4 [#]_ (declared as ``setup_requires``),
66+
- pybind11≥2.5.0 [#]_ (declared as ``setup_requires``),
6767
- on Linux and macOS, pycairo≥1.16.0 (declared as ``setup_requires`` on macOS,
6868
but not on Linux).
6969

@@ -83,8 +83,6 @@ OpenType font features. Refer to the instructions on that project's
8383
website for installation on Linux and macOS. You may want to look at
8484
https://github.com/HOST-Oman/libraqm-cmake for Windows build scripts.
8585

86-
.. _pybind11-1362: https://github.com/pybind/pybind11/issues/1362
87-
8886
.. [#] pycairo 1.16.0 added ``get_include()``.
8987
9088
We do not actually rely on pycairo's Python bindings. Rather, specifying a
@@ -114,8 +112,8 @@ https://github.com/HOST-Oman/libraqm-cmake for Windows build scripts.
114112
of cairo, it is suggested to use a commit ≥dfe3aa6, as the latter further
115113
fixes another bug that can cause crashes in mplcairo.
116114
117-
.. [#] The version requirement comes from pybind11 issue `#1362
118-
<pybind11-1362_>`_.
115+
.. [#] pybind11 2.5.0 is the earliest version that supports being added as
116+
``setup_requires`` (and read-only buffers).
119117
120118
On Fedora, the package is available as `python-mplcairo <fedora-package_>`_.
121119

setup.py

+3-40
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"""
1616

1717
from distutils.version import LooseVersion
18-
from enum import Enum
1918
import functools
2019
import json
2120
import os
@@ -78,10 +77,7 @@ def paths_from_link_libpaths():
7877
class build_ext(build_ext):
7978

8079
def build_extensions(self):
81-
try:
82-
import importlib.metadata as importlib_metadata
83-
except ImportError:
84-
import importlib_metadata
80+
import pybind11
8581

8682
ext, = self.distribution.ext_modules
8783

@@ -95,40 +91,8 @@ def build_extensions(self):
9591
else:
9692
ext.sources += [*map(str, Path("src").glob("*.cpp"))]
9793
ext.sources.remove("src/_unity_build.cpp")
98-
ext.language = "c++"
99-
100-
# pybind11.get_include() is brittle (pybind #1425).
101-
pybind11_include_path = next(
102-
path for path in importlib_metadata.files("pybind11")
103-
if path.name == "pybind11.h").locate().parents[1]
104-
if not (pybind11_include_path / "pybind11/pybind11.h").exists():
105-
# egg-install from setup_requires:
106-
# importlib-metadata thinks the headers are at
107-
# .eggs/pybind11-VER-TAG.egg/pybind11-VER.data/headers/pybind11.h
108-
# but they're actually at
109-
# .eggs/pybind11-VER-TAG.egg/pybind11.h
110-
# pybind11_include_path is
111-
# /<...>/.eggs/pybind11-VER-TAG.egg/pybind11-VER.data
112-
# so just create the proper structure there.
113-
try:
114-
is_egg = (pybind11_include_path.relative_to(
115-
Path(__file__).resolve().parent).parts[0] == ".eggs")
116-
except ValueError:
117-
# Arch Linux ships completely wrong metadata, but the headers
118-
# are in the default include paths, so just leave things as is.
119-
is_egg = False
120-
if is_egg:
121-
shutil.rmtree(pybind11_include_path / "pybind11",
122-
ignore_errors=True)
123-
for file in [*pybind11_include_path.parent.glob("**/*")]:
124-
if file.is_dir():
125-
continue
126-
dest = (pybind11_include_path / "pybind11" /
127-
file.relative_to(pybind11_include_path.parent))
128-
dest.parent.mkdir(parents=True, exist_ok=True)
129-
shutil.copy2(file, dest)
13094

131-
ext.include_dirs += [pybind11_include_path]
95+
ext.include_dirs += [pybind11.get_include()]
13296

13397
tmp_include_dir = Path(self.get_finalized_command("build").build_base,
13498
"include")
@@ -272,9 +236,8 @@ def exec_module(module):
272236
ext_modules=[Extension("mplcairo._mplcairo", [])],
273237
python_requires=">=3.6",
274238
setup_requires=[
275-
"importlib_metadata>=0.8; python_version<'3.8'", # Added files().
276239
"setuptools_scm",
277-
"pybind11>=2.2.4",
240+
"pybind11>=2.5.0",
278241
# Actually also a setup_requires on Linux, but in the manylinux build
279242
# we need to shim it.
280243
"pycairo>=1.16.0; sys_platform == 'darwin'",

src/_mplcairo.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,8 @@ cairo_t* GraphicsContextRenderer::cr_from_fileformat_args(
388388
-> cairo_status_t {
389389
auto const& write =
390390
py::reinterpret_borrow<py::object>(static_cast<PyObject*>(closure));
391-
// FIXME[pybind11]: Work around lack of const buffers in pybind11.
392-
auto const& buf_info = py::buffer_info{
393-
const_cast<unsigned char*>(data),
394-
sizeof(char), py::format_descriptor<char>::format(),
395-
1, {length}, {sizeof(char)}};
396391
return
397-
write(py::memoryview{buf_info}).cast<unsigned int>() == length
392+
write(py::memoryview{{data, length}}).cast<unsigned int>() == length
398393
// NOTE: This does not appear to affect the context status.
399394
? CAIRO_STATUS_SUCCESS : CAIRO_STATUS_WRITE_ERROR;
400395
};

0 commit comments

Comments
 (0)