Skip to content

Commit 54ea2a5

Browse files
committed
Make pybind11 an optional build dependency
pybind11 is only used for pybind11.setup_helpers.ParallelCompile, which parallelises the compilation of the C extensions; it provides no runtime bindings. Wrap its import and use in try/except ImportError and drop it from build-system.requires, so the wheel builds without pybind11 (compiling serially) while still using it for parallel builds when it is installed. Keep it discoverable via a PEP 735 "build" dependency group, so anyone who wants parallel source builds can install it with e.g. "pip install --group build". This lets distributions that do not want the extra build dependency (e.g. OpenWrt) build Pillow without pulling in pybind11.
1 parent c8c74c8 commit 54ea2a5

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
[build-system]
22
build-backend = "backend"
33
requires = [
4-
"pybind11",
54
"setuptools>=77",
65
]
76
backend-path = [
87
"_custom_build",
98
]
109

10+
[dependency-groups]
11+
# Optional; enables parallel C extension compilation (see setup.py).
12+
build = [
13+
"pybind11",
14+
]
15+
1116
[project]
1217
name = "pillow"
1318
description = "Python Imaging Library (fork)"

setup.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import warnings
1818
from collections.abc import Iterator
1919

20-
from pybind11.setup_helpers import ParallelCompile
2120
from setuptools import Extension, setup
2221
from setuptools.command.build_ext import build_ext
2322

@@ -33,7 +32,14 @@
3332
configuration.setdefault(key, []).append(value)
3433

3534
default = int(configuration.get("parallel", ["0"])[-1])
36-
ParallelCompile("MAX_CONCURRENCY", default).install()
35+
try:
36+
from pybind11.setup_helpers import ParallelCompile
37+
38+
ParallelCompile("MAX_CONCURRENCY", default).install()
39+
except ImportError:
40+
# pybind11 only provides ParallelCompile, a parallel-build helper; without
41+
# it the C extensions are simply compiled serially.
42+
pass
3743

3844

3945
def get_version() -> str:

0 commit comments

Comments
 (0)