Skip to content
Merged
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
1 change: 1 addition & 0 deletions .ci/requirements-mypy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ipython
numpy
packaging
pyarrow-stubs
pybind11
pytest
sphinx
types-atheris
Expand Down
5 changes: 2 additions & 3 deletions docs/installation/building-from-source.rst
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,9 @@ Build options

* Config setting: ``-C parallel=n``. Can also be given
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
using a setting of 1. By default, it uses 4 CPUs, or if 4 are not
available, as many as are present.
using a setting of 1. By default, it uses as many CPUs as are present.

* Config settings: ``-C zlib=disable``, ``-C jpeg=disable``,
``-C tiff=disable``, ``-C freetype=disable``, ``-C raqm=disable``,
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[build-system]
build-backend = "backend"
requires = [
"pybind11",
"setuptools>=77",
]
backend-path = [
Expand Down
23 changes: 12 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,27 @@
import warnings
from collections.abc import Iterator

from pybind11.setup_helpers import ParallelCompile
from setuptools import Extension, setup
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:
version_file = "src/PIL/_version.py"
with open(version_file, encoding="utf-8") as f:
return f.read().split('"')[1]


configuration: dict[str, list[str]] = {}


PILLOW_VERSION = get_version()
AVIF_ROOT = None
FREETYPE_ROOT = None
Expand Down Expand Up @@ -386,9 +394,7 @@ def finalize_options(self) -> None:
cpu_count = os.cpu_count()
if cpu_count is not None:
try:
self.parallel = int(
os.environ.get("MAX_CONCURRENCY", min(4, cpu_count))
)
self.parallel = int(os.environ.get("MAX_CONCURRENCY", cpu_count))
except TypeError:
pass
for x in self.feature:
Expand Down Expand Up @@ -1044,11 +1050,6 @@ def debug_build() -> bool:
]


# 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:
setup(
cmdclass={"build_ext": pil_build_ext},
Expand Down
Loading