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.0.0";
10 name = "${pname}-${version}";
11
12 src = fetchPypi {
13 inherit pname version;
14 sha256 = "12f29d6c23424f704c66b5b68c02fe0b571504459605cfe36ab8158359b0e1bb";
15 };
16
17 doCheck = !stdenv.isDarwin && !isPyPy;
18
19 # Disable imagefont tests, because they don't work well with infinality:
20 # https://github.com/python-pillow/Pillow/issues/1259
21 postPatch = ''
22 rm Tests/test_imagefont.py
23 '';
24
25 propagatedBuildInputs = [ olefile ];
26
27 checkInputs = [ pytest pytestrunner ];
28
29 buildInputs = [
30 freetype libjpeg zlib libtiff libwebp tcl lcms2 ]
31 ++ stdenv.lib.optionals (isPyPy) [ tk libX11 ];
32
33 # NOTE: we use LCMS_ROOT as WEBP root since there is not other setting for webp.
34 preConfigure = let
35 libinclude' = pkg: ''"${pkg.out}/lib", "${pkg.out}/include"'';
36 libinclude = pkg: ''"${pkg.out}/lib", "${pkg.dev}/include"'';
37 in ''
38 sed -i "setup.py" \
39 -e 's|^FREETYPE_ROOT =.*$|FREETYPE_ROOT = ${libinclude freetype}|g ;
40 s|^JPEG_ROOT =.*$|JPEG_ROOT = ${libinclude libjpeg}|g ;
41 s|^ZLIB_ROOT =.*$|ZLIB_ROOT = ${libinclude zlib}|g ;
42 s|^LCMS_ROOT =.*$|LCMS_ROOT = ${libinclude lcms2}|g ;
43 s|^TIFF_ROOT =.*$|TIFF_ROOT = ${libinclude libtiff}|g ;
44 s|^TCL_ROOT=.*$|TCL_ROOT = ${libinclude' tcl}|g ;'
45 export LDFLAGS="-L${libwebp}/lib"
46 export CFLAGS="-I${libwebp}/include"
47 ''
48 # Remove impurities
49 + stdenv.lib.optionalString stdenv.isDarwin ''
50 substituteInPlace setup.py \
51 --replace '"/Library/Frameworks",' "" \
52 --replace '"/System/Library/Frameworks"' ""
53 '';
54
55 meta = with stdenv.lib; {
56 homepage = https://python-pillow.github.io/;
57 description = "Fork of The Python Imaging Library (PIL)";
58 longDescription = ''
59 The Python Imaging Library (PIL) adds image processing
60 capabilities to your Python interpreter. This library
61 supports many file formats, and provides powerful image
62 processing and graphics capabilities.
63 '';
64 license = "http://www.pythonware.com/products/pil/license.htm";
65 maintainers = with maintainers; [ goibhniu prikhi ];
66 };
67}