1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 isPyPy,
7 fetchpatch,
8
9 # build-system
10 setuptools,
11
12 # native dependencies
13 libGL,
14
15 # dependencies
16 numpy,
17 pillow,
18
19 # optional-dependencies
20 astropy,
21 av,
22 imageio-ffmpeg,
23 pillow-heif,
24 psutil,
25 tifffile,
26
27 # tests
28 fsspec,
29 gitMinimal,
30 pytestCheckHook,
31 writableTmpDirAsHomeHook,
32}:
33
34let
35 test_images = fetchFromGitHub {
36 owner = "imageio";
37 repo = "test_images";
38 rev = "f676c96b1af7e04bb1eed1e4551e058eb2f14acd";
39 leaveDotGit = true;
40 hash = "sha256-Kh8DowuhcCT5C04bE5yJa2C+efilLxP0AM31XjnHRf4=";
41 };
42 libgl = "${libGL.out}/lib/libGL${stdenv.hostPlatform.extensions.sharedLibrary}";
43in
44
45buildPythonPackage rec {
46 pname = "imageio";
47 version = "2.37.0";
48 pyproject = true;
49
50 src = fetchFromGitHub {
51 owner = "imageio";
52 repo = "imageio";
53 tag = "v${version}";
54 hash = "sha256-/nxJxZrTYX7F2grafIWwx9SyfR47ZXyaUwPHMEOdKkI=";
55 };
56
57 patches = [
58 (fetchpatch {
59 # https://github.com/imageio/imageio/issues/1139
60 # https://github.com/imageio/imageio/pull/1144
61 name = "fix-pyav-13-1-compat";
62 url = "https://github.com/imageio/imageio/commit/eadfc5906f5c2c3731f56a582536dbc763c3a7a9.patch";
63 excludes = [
64 "setup.py"
65 ];
66 hash = "sha256-ycsW1YXtiO3ZecIF1crYaX6vg/nRW4bF4So5uWCVzME=";
67 })
68 ];
69
70 postPatch = lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
71 substituteInPlace tests/test_core.py \
72 --replace-fail 'ctypes.util.find_library("GL")' '"${libgl}"'
73 '';
74
75 build-system = [ setuptools ];
76
77 dependencies = [
78 numpy
79 pillow
80 ];
81
82 optional-dependencies = {
83 bsdf = [ ];
84 dicom = [ ];
85 feisem = [ ];
86 ffmpeg = [
87 imageio-ffmpeg
88 psutil
89 ];
90 fits = lib.optionals (!isPyPy) [ astropy ];
91 freeimage = [ ];
92 lytro = [ ];
93 numpy = [ ];
94 pillow = [ ];
95 simpleitk = [ ];
96 spe = [ ];
97 swf = [ ];
98 tifffile = [ tifffile ];
99 pyav = [ av ];
100 heif = [ pillow-heif ];
101 };
102
103 nativeCheckInputs = [
104 fsspec
105 gitMinimal
106 psutil
107 pytestCheckHook
108 writableTmpDirAsHomeHook
109 ]
110 ++ fsspec.optional-dependencies.github
111 ++ lib.flatten (builtins.attrValues optional-dependencies);
112
113 pytestFlags = [ "--test-images=file://${test_images}" ];
114
115 disabledTests = [
116 # These should have had `needs_internet` mark applied but don't so far.
117 # See https://github.com/imageio/imageio/pull/1142
118 "test_read_stream"
119 "test_uri_reading"
120 "test_trim_filter"
121 ];
122
123 disabledTestMarks = [ "needs_internet" ];
124
125 # These tests require the old and vulnerable freeimage binaries; skip.
126 disabledTestPaths = [ "tests/test_freeimage.py" ];
127
128 preCheck = ''
129 export IMAGEIO_USERDIR=$(mktemp -d)
130 '';
131
132 meta = {
133 description = "Library for reading and writing a wide range of image, video, scientific, and volumetric data formats";
134 homepage = "https://imageio.readthedocs.io";
135 changelog = "https://github.com/imageio/imageio/blob/${src.tag}/CHANGELOG.md";
136 license = lib.licenses.bsd2;
137 maintainers = with lib.maintainers; [ Luflosi ];
138 };
139}