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