Skip to content

Commit c482634

Browse files
authored
Merge pull request #7171 from radarhere/build
Use --config-settings instead of deprecated --global-option
2 parents 0d54cf5 + 38d6386 commit c482634

7 files changed

Lines changed: 77 additions & 21 deletions

File tree

.github/workflows/test-mingw.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
pushd depends && ./install_extra_test_images.sh && popd
8181
8282
- name: Build Pillow
83-
run: SETUPTOOLS_USE_DISTUTILS="stdlib" CFLAGS="-coverage" python3 -m pip install --global-option="build_ext" .
83+
run: SETUPTOOLS_USE_DISTUTILS="stdlib" CFLAGS="-coverage" python3 -m pip install .
8484

8585
- name: Test Pillow
8686
run: |

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ graft src
1515
graft depends
1616
graft winbuild
1717
graft docs
18+
graft _custom_build
1819

1920
# build/src control detritus
2021
exclude .appveyor.yml

Makefile

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,21 @@ help:
4646
@echo " docserve run an HTTP server on the docs directory"
4747
@echo " html make HTML docs"
4848
@echo " htmlview open the index page built by the html target in your browser"
49-
@echo " inplace make inplace extension"
5049
@echo " install make and install"
5150
@echo " install-coverage make and install with C coverage"
5251
@echo " lint run the lint checks"
5352
@echo " lint-fix run Black and isort to (mostly) fix lint issues"
5453
@echo " release-test run code and package tests before release"
5554
@echo " test run tests on installed Pillow"
5655

57-
.PHONY: inplace
58-
inplace: clean
59-
python3 -m pip install -e --global-option="build_ext" --global-option="--inplace" .
60-
6156
.PHONY: install
6257
install:
6358
python3 -m pip -v install .
6459
python3 selftest.py
6560

6661
.PHONY: install-coverage
6762
install-coverage:
68-
CFLAGS="-coverage -Werror=implicit-function-declaration" python3 -m pip -v install --global-option="build_ext" .
63+
CFLAGS="-coverage -Werror=implicit-function-declaration" python3 -m pip -v install .
6964
python3 selftest.py
7065

7166
.PHONY: debug
@@ -74,7 +69,7 @@ debug:
7469
# for our stuff, kills optimization, and redirects to dev null so we
7570
# see any build failures.
7671
make clean > /dev/null
77-
CFLAGS='-g -O0' python3 -m pip -v install --global-option="build_ext" . > /dev/null
72+
CFLAGS='-g -O0' python3 -m pip -v install . > /dev/null
7873

7974
.PHONY: release-test
8075
release-test:

_custom_build/backend.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import sys
2+
3+
from setuptools.build_meta import * # noqa: F401, F403
4+
from setuptools.build_meta import build_wheel
5+
6+
backend_class = build_wheel.__self__.__class__
7+
8+
9+
class _CustomBuildMetaBackend(backend_class):
10+
def run_setup(self, setup_script="setup.py"):
11+
if self.config_settings:
12+
13+
def config_has(key, value):
14+
settings = self.config_settings.get(key)
15+
if settings:
16+
if not isinstance(settings, list):
17+
settings = [settings]
18+
return value in settings
19+
20+
flags = []
21+
for dependency in (
22+
"zlib",
23+
"jpeg",
24+
"tiff",
25+
"freetype",
26+
"raqm",
27+
"lcms",
28+
"webp",
29+
"webpmux",
30+
"jpeg2000",
31+
"imagequant",
32+
"xcb",
33+
):
34+
if config_has(dependency, "enable"):
35+
flags.append("--enable-" + dependency)
36+
elif config_has(dependency, "disable"):
37+
flags.append("--disable-" + dependency)
38+
for dependency in ("raqm", "fribidi"):
39+
if config_has(dependency, "vendor"):
40+
flags.append("--vendor-" + dependency)
41+
if self.config_settings.get("platform-guessing") == "disable":
42+
flags.append("--disable-platform-guessing")
43+
if self.config_settings.get("debug") == "true":
44+
flags.append("--debug")
45+
if flags:
46+
sys.argv = sys.argv[:1] + ["build_ext"] + flags + sys.argv[1:]
47+
return super().run_setup(setup_script)
48+
49+
def build_wheel(
50+
self, wheel_directory, config_settings=None, metadata_directory=None
51+
):
52+
self.config_settings = config_settings
53+
return super().build_wheel(wheel_directory, config_settings, metadata_directory)
54+
55+
56+
build_wheel = _CustomBuildMetaBackend().build_wheel

docs/installation.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -385,40 +385,40 @@ Build Options
385385
using a setting of 1. By default, it uses 4 CPUs, or if 4 are not
386386
available, as many as are present.
387387

388-
* Build flags: ``--disable-zlib``, ``--disable-jpeg``,
389-
``--disable-tiff``, ``--disable-freetype``, ``--disable-raqm``,
390-
``--disable-lcms``, ``--disable-webp``, ``--disable-webpmux``,
391-
``--disable-jpeg2000``, ``--disable-imagequant``, ``--disable-xcb``.
388+
* Config settings: ``-C zlib=disable``, ``-C jpeg=disable``,
389+
``-C tiff=disable``, ``-C freetype=disable``, ``-C raqm=disable``,
390+
``-C lcms=disable``, ``-C webp=disable``, ``-C webpmux=disable``,
391+
``-C jpeg2000=disable``, ``-C imagequant=disable``, ``-C xcb=disable``.
392392
Disable building the corresponding feature even if the development
393393
libraries are present on the building machine.
394394

395-
* Build flags: ``--enable-zlib``, ``--enable-jpeg``,
396-
``--enable-tiff``, ``--enable-freetype``, ``--enable-raqm``,
397-
``--enable-lcms``, ``--enable-webp``, ``--enable-webpmux``,
398-
``--enable-jpeg2000``, ``--enable-imagequant``, ``--enable-xcb``.
395+
* Config settings: ``-C zlib=enable``, ``-C jpeg=enable``,
396+
``-C tiff=enable``, ``-C freetype=enable``, ``-C raqm=enable``,
397+
``-C lcms=enable``, ``-C webp=enable``, ``-C webpmux=enable``,
398+
``-C jpeg2000=enable``, ``-C imagequant=enable``, ``-C xcb=enable``.
399399
Require that the corresponding feature is built. The build will raise
400400
an exception if the libraries are not found. Webpmux (WebP metadata)
401401
relies on WebP support. Tcl and Tk also must be used together.
402402

403-
* Build flags: ``--vendor-raqm``, ``--vendor-fribidi``.
403+
* Config settings: ``-C raqm=vendor``, ``-C fribidi=vendor``.
404404
These flags are used to compile a modified version of libraqm and
405405
a shim that dynamically loads libfribidi at runtime. These are
406406
used to compile the standard Pillow wheels. Compiling libraqm requires
407407
a C99-compliant compiler.
408408

409-
* Build flag: ``--disable-platform-guessing``. Skips all of the
409+
* Build flag: ``-C platform-guessing=disable``. Skips all of the
410410
platform dependent guessing of include and library directories for
411411
automated build systems that configure the proper paths in the
412412
environment variables (e.g. Buildroot).
413413

414-
* Build flag: ``--debug``. Adds a debugging flag to the include and
414+
* Build flag: ``-C debug=true``. Adds a debugging flag to the include and
415415
library search process to dump all paths searched for and found to
416416
stdout.
417417

418418

419419
Sample usage::
420420

421-
python3 -m pip install --upgrade Pillow --global-option="build_ext" --global-option="--enable-[feature]"
421+
python3 -m pip install --upgrade Pillow -C [feature]=enable
422422

423423
Platform Support
424424
----------------

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[build-system]
2+
requires = ["setuptools >= 40.8.0", "wheel"]
3+
build-backend = "backend"
4+
backend-path = ["_custom_build"]

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extras =
1313
tests
1414
commands =
1515
make clean
16-
{envpython} -m pip install --global-option="build_ext" --global-option="--inplace" .
16+
{envpython} -m pip install .
1717
{envpython} selftest.py
1818
{envpython} -m pytest -W always {posargs}
1919
allowlist_externals =

0 commit comments

Comments
 (0)