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