11 buildPythonPackage rec {
12 inherit pname version src meta;
14 # Disable imagefont tests, because they don't work well with infinality:
15 # https://github.com/python-pillow/Pillow/issues/1259
17 rm Tests/test_imagefont.py
20 # Disable darwin tests which require executables: `iconutil` and `screencapture`
21 disabledTests = lib.optionals stdenv.isDarwin [
29 ] ++ lib.optionals (lib.versions.major version == "6") [
30 # RuntimeError: Error setting from dictionary
31 "test_custom_metadata"
34 propagatedBuildInputs = [ olefile ];
36 checkInputs = [ pytestCheckHook pyroma numpy ];
38 buildInputs = [ freetype libjpeg openjpeg libimagequant zlib libtiff libwebp tcl lcms2 ]
39 ++ lib.optionals (lib.versionAtLeast version "7.1.0") [ libxcb ]
40 ++ lib.optionals (isPyPy) [ tk libX11 ];
42 # NOTE: we use LCMS_ROOT as WEBP root since there is not other setting for webp.
43 # NOTE: The Pillow install script will, by default, add paths like /usr/lib
44 # and /usr/include to the search paths. This can break things when building
45 # on a non-NixOS system that has some libraries installed that are not
46 # installed in Nix (for example, Arch Linux has jpeg2000 but Nix doesn't
47 # build Pillow with this support). We patch the `disable_platform_guessing`
48 # setting here, instead of passing the `--disable-platform-guessing`
49 # command-line option, since the command-line option doesn't work when we run
52 libinclude' = pkg: ''"${pkg.out}/lib", "${pkg.out}/include"'';
53 libinclude = pkg: ''"${pkg.out}/lib", "${pkg.dev}/include"'';
56 -e 's|^FREETYPE_ROOT =.*$|FREETYPE_ROOT = ${libinclude freetype}|g ;
57 s|^JPEG_ROOT =.*$|JPEG_ROOT = ${libinclude libjpeg}|g ;
58 s|^JPEG2K_ROOT =.*$|JPEG2K_ROOT = ${libinclude openjpeg}|g ;
59 s|^IMAGEQUANT_ROOT =.*$|IMAGEQUANT_ROOT = ${libinclude' libimagequant}|g ;
60 s|^ZLIB_ROOT =.*$|ZLIB_ROOT = ${libinclude zlib}|g ;
61 s|^LCMS_ROOT =.*$|LCMS_ROOT = ${libinclude lcms2}|g ;
62 s|^TIFF_ROOT =.*$|TIFF_ROOT = ${libinclude libtiff}|g ;
63 s|^TCL_ROOT=.*$|TCL_ROOT = ${libinclude' tcl}|g ;
64 s|self\.disable_platform_guessing = None|self.disable_platform_guessing = True|g ;'
65 export LDFLAGS="$LDFLAGS -L${libwebp}/lib"
66 export CFLAGS="$CFLAGS -I${libwebp}/include"
67 '' + lib.optionalString (lib.versionAtLeast version "7.1.0") ''
68 export LDFLAGS="$LDFLAGS -L${libxcb}/lib"
69 export CFLAGS="$CFLAGS -I${libxcb.dev}/include"
70 '' + lib.optionalString stdenv.isDarwin ''
72 substituteInPlace setup.py \
73 --replace '"/Library/Frameworks",' "" \
74 --replace '"/System/Library/Frameworks"' ""