1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 buildPythonPackage,
6 python,
7 pythonOlder,
8 astropy,
9 cloudpickle,
10 cython,
11 dask,
12 imageio,
13 lazy-loader,
14 matplotlib,
15 meson-python,
16 networkx,
17 numpy,
18 packaging,
19 pillow,
20 pooch,
21 pyamg,
22 pytestCheckHook,
23 numpydoc,
24 pythran,
25 pywavelets,
26 scikit-learn,
27 scipy,
28 setuptools,
29 simpleitk,
30 six,
31 tifffile,
32 wheel,
33}:
34
35let
36 installedPackageRoot = "${builtins.placeholder "out"}/${python.sitePackages}";
37 self = buildPythonPackage rec {
38 pname = "scikit-image";
39 version = "0.22.0";
40 format = "pyproject";
41
42 disabled = pythonOlder "3.8";
43
44 src = fetchFromGitHub {
45 owner = "scikit-image";
46 repo = "scikit-image";
47 rev = "refs/tags/v${version}";
48 hash = "sha256-M18y5JBPf3DR7SlJcCf82nG2MzwILg2w1AhJMzZXslg=";
49 };
50
51 postPatch = ''
52 patchShebangs skimage/_build_utils/{version,cythoner}.py
53
54 substituteInPlace pyproject.toml \
55 --replace "numpy==" "numpy>="
56 '';
57
58 nativeBuildInputs = [
59 cython
60 meson-python
61 numpy
62 packaging
63 pythran
64 setuptools
65 wheel
66 ];
67
68 propagatedBuildInputs = [
69 imageio
70 lazy-loader
71 matplotlib
72 networkx
73 numpy
74 packaging
75 pillow
76 pywavelets
77 scipy
78 tifffile
79 ];
80
81 passthru.optional-dependencies = {
82 data = [ pooch ];
83 optional = [
84 astropy
85 cloudpickle
86 dask
87 matplotlib
88 pooch
89 pyamg
90 scikit-learn
91 simpleitk
92 ] ++ dask.optional-dependencies.array;
93 };
94
95 # test suite is very cpu intensive, move to passthru.tests
96 doCheck = false;
97 nativeCheckInputs = [
98 pytestCheckHook
99 numpydoc
100 ];
101
102 # (1) The package has cythonized modules, whose .so libs will appear only in the wheel, i.e. in nix store;
103 # (2) To stop Python from importing the wrong directory, i.e. the one in the build dir, not the one in nix store, `skimage` dir should be removed or renamed;
104 # (3) Therefore, tests should be run on the installed package in nix store.
105
106 # See e.g. https://discourse.nixos.org/t/cant-import-cythonized-modules-at-checkphase/14207 on why the following is needed.
107 preCheck = ''
108 rm -r skimage
109 '';
110
111 disabledTestPaths = [
112 # Requires network access (actually some data is loaded via `skimage._shared.testing.fetch` in the global scope, which calls `pytest.skip` when a network is unaccessible, leading to a pytest collection error).
113 "${installedPackageRoot}/skimage/filters/rank/tests/test_rank.py"
114 ];
115 pytestFlagsArray =
116 [
117 "${installedPackageRoot}"
118 "--pyargs"
119 "skimage"
120 ]
121 ++ builtins.map (testid: "--deselect=" + testid) (
122 [
123 # These tests require network access
124 "skimage/data/test_data.py::test_skin"
125 "skimage/data/tests/test_data.py::test_skin"
126 "skimage/io/tests/test_io.py::test_imread_http_url"
127 "skimage/restoration/tests/test_rolling_ball.py::test_ndim"
128 ]
129 ++ lib.optionals stdenv.isDarwin [
130 # Matplotlib tests are broken inside darwin sandbox
131 "skimage/feature/tests/test_util.py::test_plot_matches"
132 "skimage/filters/tests/test_thresholding.py::TestSimpleImage::test_try_all_threshold"
133 "skimage/io/tests/test_mpl_imshow.py::"
134 # See https://github.com/scikit-image/scikit-image/issues/7061 and https://github.com/scikit-image/scikit-image/issues/7104
135 "skimage/measure/tests/test_fit.py"
136 ]
137 ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
138 # https://github.com/scikit-image/scikit-image/issues/7104
139 "skimage/measure/tests/test_moments.py"
140 ]
141 );
142
143 # Check cythonized modules
144 pythonImportsCheck = [
145 "skimage"
146 "skimage._shared"
147 "skimage.draw"
148 "skimage.feature"
149 "skimage.restoration"
150 "skimage.filters"
151 "skimage.graph"
152 "skimage.io"
153 "skimage.measure"
154 "skimage.morphology"
155 "skimage.transform"
156 "skimage.util"
157 "skimage.segmentation"
158 ];
159
160 passthru.tests = {
161 all-tests = self.override { doCheck = true; };
162 };
163
164 meta = {
165 description = "Image processing routines for SciPy";
166 homepage = "https://scikit-image.org";
167 changelog = "https://github.com/scikit-image/scikit-image/releases/tag/${src.rev}";
168 license = lib.licenses.bsd3;
169 maintainers = with lib.maintainers; [ yl3dy ];
170 };
171 };
172in
173self