1{ stdenv, buildPythonPackage, fetchPypi, isPyPy
2, olefile
3, freetype, libjpeg, zlib, libtiff, libwebp, tcl, lcms2, tk, libX11
4, openjpeg, libimagequant
5, pytest, pytestrunner, pyroma, numpy
6}:
7
8buildPythonPackage rec {
9 pname = "Pillow";
10 version = "6.2.2";
11
12 src = fetchPypi {
13 inherit pname version;
14 sha256 = "0l5rv8jkdrb5q846v60v03mcq64yrhklidjkgwv6s1pda71g17yv";
15 };
16
17 # Disable imagefont tests, because they don't work well with infinality:
18 # https://github.com/python-pillow/Pillow/issues/1259
19 postPatch = ''
20 rm Tests/test_imagefont.py
21 '';
22
23 checkPhase = ''
24 runHook preCheck
25 python -m pytest -v -x -W always${stdenv.lib.optionalString stdenv.isDarwin " --deselect=Tests/test_file_icns.py::TestFileIcns::test_save --deselect=Tests/test_imagegrab.py::TestImageGrab::test_grab"}
26 runHook postCheck
27 '';
28
29 propagatedBuildInputs = [ olefile ];
30
31 checkInputs = [ pytest pytestrunner 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.github.io/";
72 description = "Fork of The Python Imaging Library (PIL)";
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}