This commit is contained in:
wiredfool 2025-07-09 17:00:19 +10:00 committed by GitHub
commit cc52762b2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 14 deletions

View File

@ -5,6 +5,7 @@ ipython
numpy numpy
packaging packaging
pyarrow-stubs pyarrow-stubs
pybind11
pytest pytest
sphinx sphinx
types-atheris types-atheris

View File

@ -276,10 +276,9 @@ Build options
* Config setting: ``-C parallel=n``. Can also be given * Config setting: ``-C parallel=n``. Can also be given
with environment variable: ``MAX_CONCURRENCY=n``. Pillow can use with environment variable: ``MAX_CONCURRENCY=n``. Pillow can use
multiprocessing to build the extension. Setting ``-C parallel=n`` multiprocessing to build the extensions. Setting ``-C parallel=n``
sets the number of CPUs to use to ``n``, or can disable parallel building by sets the number of CPUs to use to ``n``, or can disable parallel building by
using a setting of 1. By default, it uses 4 CPUs, or if 4 are not using a setting of 1. By default, it uses as many CPUs as are present.
available, as many as are present.
* Config settings: ``-C zlib=disable``, ``-C jpeg=disable``, * Config settings: ``-C zlib=disable``, ``-C jpeg=disable``,
``-C tiff=disable``, ``-C freetype=disable``, ``-C raqm=disable``, ``-C tiff=disable``, ``-C freetype=disable``, ``-C raqm=disable``,

View File

@ -1,6 +1,7 @@
[build-system] [build-system]
build-backend = "backend" build-backend = "backend"
requires = [ requires = [
"pybind11",
"setuptools>=77", "setuptools>=77",
] ]
backend-path = [ backend-path = [

View File

@ -17,9 +17,20 @@ import sys
import warnings import warnings
from collections.abc import Iterator from collections.abc import Iterator
from pybind11.setup_helpers import ParallelCompile
from setuptools import Extension, setup from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext from setuptools.command.build_ext import build_ext
configuration: dict[str, list[str]] = {}
# parse configuration from _custom_build/backend.py
while sys.argv[-1].startswith("--pillow-configuration="):
_, key, value = sys.argv.pop().split("=", 2)
configuration.setdefault(key, []).append(value)
default = int(configuration.get("parallel", ["0"])[-1])
ParallelCompile("MAX_CONCURRENCY", default).install()
def get_version() -> str: def get_version() -> str:
version_file = "src/PIL/_version.py" version_file = "src/PIL/_version.py"
@ -27,9 +38,6 @@ def get_version() -> str:
return f.read().split('"')[1] return f.read().split('"')[1]
configuration: dict[str, list[str]] = {}
PILLOW_VERSION = get_version() PILLOW_VERSION = get_version()
AVIF_ROOT = None AVIF_ROOT = None
FREETYPE_ROOT = None FREETYPE_ROOT = None
@ -386,9 +394,7 @@ class pil_build_ext(build_ext):
cpu_count = os.cpu_count() cpu_count = os.cpu_count()
if cpu_count is not None: if cpu_count is not None:
try: try:
self.parallel = int( self.parallel = int(os.environ.get("MAX_CONCURRENCY", cpu_count))
os.environ.get("MAX_CONCURRENCY", min(4, cpu_count))
)
except TypeError: except TypeError:
pass pass
for x in self.feature: for x in self.feature:
@ -1083,11 +1089,6 @@ ext_modules = [
] ]
# parse configuration from _custom_build/backend.py
while sys.argv[-1].startswith("--pillow-configuration="):
_, key, value = sys.argv.pop().split("=", 2)
configuration.setdefault(key, []).append(value)
try: try:
setup( setup(
cmdclass={"build_ext": pil_build_ext}, cmdclass={"build_ext": pil_build_ext},