1{ pname
2, version
3, disabled
4, src
5, patches ? []
6, meta
7, passthru ? {}
8, ...
9}@args:
10
11with args;
12
13buildPythonPackage rec {
14 inherit pname version format src meta passthru patches;
15
16 # Disable imagefont tests, because they don't work well with infinality:
17 # https://github.com/python-pillow/Pillow/issues/1259
18 postPatch = ''
19 rm Tests/test_imagefont.py
20 '';
21
22 disabledTests = [
23 # Code quality mismathch 9 vs 10
24 "test_pyroma"
25
26 # pillow-simd
27 "test_roundtrip"
28 "test_basic"
29 "test_custom_metadata"
30 ] ++ lib.optionals stdenv.isDarwin [
31 # Disable darwin tests which require executables: `iconutil` and `screencapture`
32 "test_grab"
33 "test_grabclipboard"
34 "test_save"
35 ];
36
37 propagatedBuildInputs = [ olefile ]
38 ++ lib.optionals (lib.versionAtLeast version "8.2.0") [ defusedxml ];
39
40 nativeCheckInputs = [ pytestCheckHook pyroma numpy ];
41
42 buildInputs = [ freetype libjpeg openjpeg libimagequant zlib libtiff libwebp libxcrypt tcl lcms2 ]
43 ++ lib.optionals (lib.versionAtLeast version "7.1.0") [ libxcb ]
44 ++ lib.optionals (isPyPy) [ tk libX11 ];
45
46 # NOTE: we use LCMS_ROOT as WEBP root since there is not other setting for webp.
47 # NOTE: The Pillow install script will, by default, add paths like /usr/lib
48 # and /usr/include to the search paths. This can break things when building
49 # on a non-NixOS system that has some libraries installed that are not
50 # installed in Nix (for example, Arch Linux has jpeg2000 but Nix doesn't
51 # build Pillow with this support). We patch the `disable_platform_guessing`
52 # setting here, instead of passing the `--disable-platform-guessing`
53 # command-line option, since the command-line option doesn't work when we run
54 # tests.
55 preConfigure = let
56 libinclude' = pkg: ''"${pkg.out}/lib", "${pkg.out}/include"'';
57 libinclude = pkg: ''"${pkg.out}/lib", "${pkg.dev}/include"'';
58 in ''
59 sed -i "setup.py" \
60 -e 's|^FREETYPE_ROOT =.*$|FREETYPE_ROOT = ${libinclude freetype}|g ;
61 s|^JPEG_ROOT =.*$|JPEG_ROOT = ${libinclude libjpeg}|g ;
62 s|^JPEG2K_ROOT =.*$|JPEG2K_ROOT = ${libinclude openjpeg}|g ;
63 s|^IMAGEQUANT_ROOT =.*$|IMAGEQUANT_ROOT = ${libinclude' libimagequant}|g ;
64 s|^ZLIB_ROOT =.*$|ZLIB_ROOT = ${libinclude zlib}|g ;
65 s|^LCMS_ROOT =.*$|LCMS_ROOT = ${libinclude lcms2}|g ;
66 s|^TIFF_ROOT =.*$|TIFF_ROOT = ${libinclude libtiff}|g ;
67 s|^TCL_ROOT=.*$|TCL_ROOT = ${libinclude' tcl}|g ;
68 s|self\.disable_platform_guessing = None|self.disable_platform_guessing = True|g ;'
69 export LDFLAGS="$LDFLAGS -L${libwebp}/lib"
70 export CFLAGS="$CFLAGS -I${libwebp}/include"
71 '' + lib.optionalString (lib.versionAtLeast version "7.1.0") ''
72 export LDFLAGS="$LDFLAGS -L${libxcb}/lib"
73 export CFLAGS="$CFLAGS -I${libxcb.dev}/include"
74 '' + lib.optionalString stdenv.isDarwin ''
75 # Remove impurities
76 substituteInPlace setup.py \
77 --replace '"/Library/Frameworks",' "" \
78 --replace '"/System/Library/Frameworks"' ""
79 '';
80}