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