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