Skip to content

Commit 0b1d0c2

Browse files
authored
Merge pull request #7658 from nulano/build-editable
2 parents 0164158 + e6fa5df commit 0b1d0c2

5 files changed

Lines changed: 55 additions & 47 deletions

File tree

.github/workflows/wheels.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
paths:
66
- ".ci/requirements-cibw.txt"
77
- ".github/workflows/wheel*"
8+
- "setup.py"
89
- "wheels/*"
910
- "winbuild/build_prepare.py"
1011
- "winbuild/fribidi.cmake"
@@ -14,6 +15,7 @@ on:
1415
paths:
1516
- ".ci/requirements-cibw.txt"
1617
- ".github/workflows/wheel*"
18+
- "setup.py"
1719
- "wheels/*"
1820
- "winbuild/build_prepare.py"
1921
- "winbuild/fribidi.cmake"

_custom_build/backend.py

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,12 @@
1111
class _CustomBuildMetaBackend(backend_class):
1212
def run_setup(self, setup_script="setup.py"):
1313
if self.config_settings:
14+
for key, values in self.config_settings.items():
15+
if not isinstance(values, list):
16+
values = [values]
17+
for value in values:
18+
sys.argv.append(f"--pillow-configuration={key}={value}")
1419

15-
def config_has(key, value):
16-
settings = self.config_settings.get(key)
17-
if settings:
18-
if not isinstance(settings, list):
19-
settings = [settings]
20-
return value in settings
21-
22-
flags = []
23-
for dependency in (
24-
"zlib",
25-
"jpeg",
26-
"tiff",
27-
"freetype",
28-
"raqm",
29-
"lcms",
30-
"webp",
31-
"webpmux",
32-
"jpeg2000",
33-
"imagequant",
34-
"xcb",
35-
):
36-
if config_has(dependency, "enable"):
37-
flags.append("--enable-" + dependency)
38-
elif config_has(dependency, "disable"):
39-
flags.append("--disable-" + dependency)
40-
for dependency in ("raqm", "fribidi"):
41-
if config_has(dependency, "vendor"):
42-
flags.append("--vendor-" + dependency)
43-
if self.config_settings.get("platform-guessing") == "disable":
44-
flags.append("--disable-platform-guessing")
45-
if self.config_settings.get("debug") == "true":
46-
flags.append("--debug")
47-
if flags:
48-
sys.argv = sys.argv[:1] + ["build_ext"] + flags + sys.argv[1:]
4920
return super().run_setup(setup_script)
5021

5122
def build_wheel(
@@ -54,5 +25,15 @@ def build_wheel(
5425
self.config_settings = config_settings
5526
return super().build_wheel(wheel_directory, config_settings, metadata_directory)
5627

28+
def build_editable(
29+
self, wheel_directory, config_settings=None, metadata_directory=None
30+
):
31+
self.config_settings = config_settings
32+
return super().build_editable(
33+
wheel_directory, config_settings, metadata_directory
34+
)
35+
5736

58-
build_wheel = _CustomBuildMetaBackend().build_wheel
37+
_backend = _CustomBuildMetaBackend()
38+
build_wheel = _backend.build_wheel
39+
build_editable = _backend.build_editable

docs/installation/building-from-source.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,10 @@ After navigating to the Pillow directory, run::
266266
Build Options
267267
^^^^^^^^^^^^^
268268

269-
* Environment variable: ``MAX_CONCURRENCY=n``. Pillow can use
270-
multiprocessing to build the extension. Setting ``MAX_CONCURRENCY``
271-
sets the number of CPUs to use, or can disable parallel building by
269+
* Config setting: ``-C parallel=n``. Can also be given
270+
with environment variable: ``MAX_CONCURRENCY=n``. Pillow can use
271+
multiprocessing to build the extension. Setting ``-C parallel=n``
272+
sets the number of CPUs to use to ``n``, or can disable parallel building by
272273
using a setting of 1. By default, it uses 4 CPUs, or if 4 are not
273274
available, as many as are present.
274275

@@ -293,14 +294,13 @@ Build Options
293294
used to compile the standard Pillow wheels. Compiling libraqm requires
294295
a C99-compliant compiler.
295296

296-
* Build flag: ``-C platform-guessing=disable``. Skips all of the
297+
* Config setting: ``-C platform-guessing=disable``. Skips all of the
297298
platform dependent guessing of include and library directories for
298299
automated build systems that configure the proper paths in the
299300
environment variables (e.g. Buildroot).
300301

301-
* Build flag: ``-C debug=true``. Adds a debugging flag to the include and
302-
library search process to dump all paths searched for and found to
303-
stdout.
302+
* Config setting: ``-C debug=true``. Adds a debugging flag to the include and
303+
library search process to dump all paths searched for and found to stdout.
304304

305305

306306
Sample usage::

setup.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def get_version():
2727
return locals()["__version__"]
2828

2929

30+
configuration = {}
31+
32+
3033
PILLOW_VERSION = get_version()
3134
FREETYPE_ROOT = None
3235
HARFBUZZ_ROOT = None
@@ -333,15 +336,24 @@ def __iter__(self):
333336
+ [("add-imaging-libs=", None, "Add libs to _imaging build")]
334337
)
335338

339+
@staticmethod
340+
def check_configuration(option, value):
341+
return True if value in configuration.get(option, []) else None
342+
336343
def initialize_options(self):
337-
self.disable_platform_guessing = None
344+
self.disable_platform_guessing = self.check_configuration(
345+
"platform-guessing", "disable"
346+
)
338347
self.add_imaging_libs = ""
339348
build_ext.initialize_options(self)
340349
for x in self.feature:
341-
setattr(self, f"disable_{x}", None)
342-
setattr(self, f"enable_{x}", None)
350+
setattr(self, f"disable_{x}", self.check_configuration(x, "disable"))
351+
setattr(self, f"enable_{x}", self.check_configuration(x, "enable"))
343352
for x in ("raqm", "fribidi"):
344-
setattr(self, f"vendor_{x}", None)
353+
setattr(self, f"vendor_{x}", self.check_configuration(x, "vendor"))
354+
if self.check_configuration("debug", "true"):
355+
self.debug = True
356+
self.parallel = configuration.get("parallel", [None])[-1]
345357

346358
def finalize_options(self):
347359
build_ext.finalize_options(self)
@@ -987,6 +999,12 @@ def debug_build():
987999
Extension("PIL._imagingmorph", ["src/_imagingmorph.c"]),
9881000
]
9891001

1002+
1003+
# parse configuration from _custom_build/backend.py
1004+
while sys.argv[-1].startswith("--pillow-configuration="):
1005+
_, key, value = sys.argv.pop().split("=", 2)
1006+
configuration.setdefault(key, []).append(value)
1007+
9901008
try:
9911009
setup(
9921010
cmdclass={"build_ext": pil_build_ext},

winbuild/build.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,18 @@ are set by running ``winbuild\build\build_env.cmd`` and install Pillow with pip:
8787
winbuild\build\build_env.cmd
8888
python.exe -m pip install -v -C raqm=vendor -C fribidi=vendor .
8989

90-
To build a wheel instead, run::
90+
You can also install Pillow in `editable mode`_::
91+
92+
winbuild\build\build_env.cmd
93+
python.exe -m pip install -v -C raqm=vendor -C fribidi=vendor -e .
94+
95+
To build a binary wheel instead, run::
9196

9297
winbuild\build\build_env.cmd
9398
python.exe -m pip wheel -v -C raqm=vendor -C fribidi=vendor .
9499

100+
.. _editable mode: https://setuptools.pypa.io/en/stable/userguide/development_mode.html
101+
95102
Testing Pillow
96103
--------------
97104

0 commit comments

Comments
 (0)