nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6
7 # build-system
8 setuptools,
9 pkg-config,
10 pybind11,
11
12 # native dependencies
13 freetype,
14 lcms2,
15 libavif,
16 libimagequant,
17 libjpeg,
18 libraqm,
19 libtiff,
20 libwebp,
21 libxcb,
22 openjpeg,
23 zlib-ng,
24
25 # optional dependencies
26 defusedxml,
27 olefile,
28
29 # tests
30 numpy,
31 pytest-cov-stub,
32 pytestCheckHook,
33
34 # for passthru.tests
35 imageio,
36 matplotlib,
37 pilkit,
38 pydicom,
39 reportlab,
40 sage,
41}:
42
43buildPythonPackage rec {
44 pname = "pillow";
45 version = "12.1.0";
46 pyproject = true;
47
48 src = fetchFromGitHub {
49 owner = "python-pillow";
50 repo = "pillow";
51 tag = version;
52 hash = "sha256-QGtuxKpkx2FScQHj9lH4mhEAo6jE+NAR2sR5/zvHUuA=";
53 };
54
55 build-system = [
56 setuptools
57 pybind11
58 ];
59
60 nativeBuildInputs = [ pkg-config ];
61
62 # https://pillow.readthedocs.io/en/latest/installation/building-from-source.html#building-from-source
63 buildInputs = [
64 freetype
65 lcms2
66 libavif
67 libimagequant
68 libjpeg
69 libraqm
70 libtiff
71 libwebp
72 libxcb
73 openjpeg
74 zlib-ng
75 ];
76
77 pypaBuildFlags = [
78 # Disable platform guessing, which tries various FHS paths
79 "--config-setting=--disable-platform-guessing"
80 ];
81
82 preConfigure =
83 let
84 getLibAndInclude = pkg: ''"${pkg.out}/lib", "${lib.getDev pkg}/include"'';
85 in
86 ''
87 # The build process fails to find the pkg-config files for these dependencies
88 substituteInPlace setup.py \
89 --replace-fail 'AVIF_ROOT = None' 'AVIF_ROOT = ${getLibAndInclude libavif}' \
90 --replace-fail 'IMAGEQUANT_ROOT = None' 'IMAGEQUANT_ROOT = ${getLibAndInclude libimagequant}' \
91 --replace-fail 'JPEG2K_ROOT = None' 'JPEG2K_ROOT = ${getLibAndInclude openjpeg}'
92
93 # Build with X11 support
94 export LDFLAGS="$LDFLAGS -L${libxcb}/lib"
95 export CFLAGS="$CFLAGS -I${libxcb.dev}/include"
96 '';
97
98 optional-dependencies = {
99 fpx = [ olefile ];
100 mic = [ olefile ];
101 xmp = [ defusedxml ];
102 };
103
104 nativeCheckInputs = [
105 pytest-cov-stub
106 pytestCheckHook
107 numpy
108 ]
109 ++ lib.concatAttrValues optional-dependencies;
110
111 disabledTests = [
112 # Code quality mismathch 9 vs 10
113 "test_pyroma"
114 ]
115 ++ lib.optionals stdenv.hostPlatform.isDarwin [
116 # Disable darwin tests which require executables: `iconutil` and `screencapture`
117 "test_grab"
118 "test_grabclipboard"
119 "test_save"
120 ];
121
122 disabledTestPaths = lib.optionals stdenv.hostPlatform.isDarwin [
123 # Crashes the interpreter
124 "Tests/test_imagetk.py"
125
126 # Checks for very precise color values on what's basically white
127 "Tests/test_file_avif.py::TestFileAvif::test_background_from_gif"
128 ];
129
130 passthru.tests = {
131 inherit
132 imageio
133 matplotlib
134 pilkit
135 pydicom
136 reportlab
137 sage
138 ;
139 };
140
141 meta = {
142 homepage = "https://python-pillow.github.io/";
143 changelog = "https://pillow.readthedocs.io/en/stable/releasenotes/${version}.html";
144 description = "Friendly PIL fork (Python Imaging Library)";
145 longDescription = ''
146 The Python Imaging Library (PIL) adds image processing
147 capabilities to your Python interpreter. This library
148 supports many file formats, and provides powerful image
149 processing and graphics capabilities.
150 '';
151 license = lib.licenses.mit-cmu;
152 maintainers = with lib.maintainers; [ hexa ];
153 };
154
155}